fix(main): pass own username to Tasks object

This commit is contained in:
xeruf 2024-08-21 12:30:13 +03:00
parent f7f4bdc4f3
commit 999068bdd9
2 changed files with 12 additions and 8 deletions

View File

@ -238,18 +238,20 @@ async fn main() -> Result<()> {
], None).await; ], None).await;
info!("Subscribed to updates with {:?}", sub2); info!("Subscribed to updates with {:?}", sub2);
let metadata = var("USER").ok().map(
|user| Metadata::new().name(user));
let myMeta = metadata.clone();
let (tx, mut rx) = mpsc::channel::<MostrMessage>(64); let (tx, mut rx) = mpsc::channel::<MostrMessage>(64);
let tasks_for_url = |url: Option<Url>| Tasks::from(url, &tx, &keys); let tasks_for_url = |url: Option<Url>| Tasks::from(url, &tx, &keys, metadata.clone());
let mut relays: HashMap<Option<Url>, Tasks> = let mut relays: HashMap<Option<Url>, Tasks> =
client.relays().await.into_keys().map(|url| (Some(url.clone()), tasks_for_url(Some(url)))).collect(); client.relays().await.into_keys().map(|url| (Some(url.clone()), tasks_for_url(Some(url)))).collect();
let sender = tokio::spawn(async move { let sender = tokio::spawn(async move {
let mut queue: Option<(Url, Vec<Event>)> = None; let mut queue: Option<(Url, Vec<Event>)> = None;
if let Ok(user) = var("USER") { if let Some(meta) = myMeta.as_ref() {
let metadata = Metadata::new() or_warn!(client.set_metadata(meta).await, "Unable to set metadata");
.name(user);
or_warn!(client.set_metadata(&metadata).await);
} }
loop { loop {

View File

@ -103,13 +103,15 @@ impl Display for StateFilter {
} }
impl Tasks { impl Tasks {
pub(crate) fn from(url: Option<Url>, tx: &tokio::sync::mpsc::Sender<MostrMessage>, keys: &Keys) -> Self { pub(crate) fn from(url: Option<Url>, tx: &tokio::sync::mpsc::Sender<MostrMessage>, keys: &Keys, metadata: Option<Metadata>) -> Self {
Self::with_sender(EventSender { let mut new = Self::with_sender(EventSender {
url, url,
tx: tx.clone(), tx: tx.clone(),
keys: keys.clone(), keys: keys.clone(),
queue: Default::default(), queue: Default::default(),
}) });
metadata.map(|m| new.users.insert(keys.public_key(), m));
new
} }
pub(crate) fn with_sender(sender: EventSender) -> Self { pub(crate) fn with_sender(sender: EventSender) -> Self {