forked from janek/mostr
fix(main): pass own username to Tasks object
This commit is contained in:
parent
f7f4bdc4f3
commit
999068bdd9
12
src/main.rs
12
src/main.rs
|
@ -238,18 +238,20 @@ async fn main() -> Result<()> {
|
|||
], None).await;
|
||||
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 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> =
|
||||
client.relays().await.into_keys().map(|url| (Some(url.clone()), tasks_for_url(Some(url)))).collect();
|
||||
|
||||
let sender = tokio::spawn(async move {
|
||||
let mut queue: Option<(Url, Vec<Event>)> = None;
|
||||
|
||||
if let Ok(user) = var("USER") {
|
||||
let metadata = Metadata::new()
|
||||
.name(user);
|
||||
or_warn!(client.set_metadata(&metadata).await);
|
||||
if let Some(meta) = myMeta.as_ref() {
|
||||
or_warn!(client.set_metadata(meta).await, "Unable to set metadata");
|
||||
}
|
||||
|
||||
loop {
|
||||
|
|
|
@ -103,13 +103,15 @@ impl Display for StateFilter {
|
|||
}
|
||||
|
||||
impl Tasks {
|
||||
pub(crate) fn from(url: Option<Url>, tx: &tokio::sync::mpsc::Sender<MostrMessage>, keys: &Keys) -> Self {
|
||||
Self::with_sender(EventSender {
|
||||
pub(crate) fn from(url: Option<Url>, tx: &tokio::sync::mpsc::Sender<MostrMessage>, keys: &Keys, metadata: Option<Metadata>) -> Self {
|
||||
let mut new = Self::with_sender(EventSender {
|
||||
url,
|
||||
tx: tx.clone(),
|
||||
keys: keys.clone(),
|
||||
queue: Default::default(),
|
||||
})
|
||||
});
|
||||
metadata.map(|m| new.users.insert(keys.public_key(), m));
|
||||
new
|
||||
}
|
||||
|
||||
pub(crate) fn with_sender(sender: EventSender) -> Self {
|
||||
|
|
Loading…
Reference in New Issue