Browse Source

app: trigger rescan after adding new private contact

jkds 2 weeks ago
parent
commit
b4dbe8123b
2 changed files with 9 additions and 6 deletions
  1. 9 4
      bin/app/src/app/schema/menu/contact.rs
  2. 0 2
      bin/app/src/plugin/darkirc2.rs

+ 9 - 4
bin/app/src/app/schema/menu/contact.rs

@@ -1380,10 +1380,6 @@ pub async fn make(
             menu_prop2.push_str(atom, Role::App, &contact_name).unwrap();
             i!("Successfully saved contact: {}", contact_name);
 
-            if let Some(darkirc) = sg_root2.lookup_node("/plugin/darkirc") {
-                let _ = darkirc.call_method("reload_contacts", vec![]).await;
-            }
-
             let atom = &mut renderer2.make_guard(gfxtag!("clear_contact_fields"));
             name_prop.set_str(atom, Role::App, 0, "").unwrap();
             public_prop.set_str(atom, Role::App, 0, "").unwrap();
@@ -1448,6 +1444,15 @@ pub async fn make(
                 Pimpl::Window(win) => win.draw(atom).await,
                 _ => panic!("wrong pimpl"),
             }
+
+            // Trigger rescan to fetch this contact's DM history from the DAG.
+            // The rescan reloads contacts first, so a freshly added contact's
+            // crypto box is available, then replays DMs as "@name".
+            if let Some(darkirc) = sg_root.lookup_node("/plugin/darkirc") {
+                let mut data = vec![];
+                contact.encode(&mut data).unwrap();
+                darkirc.call_method("rescan", data).await.unwrap();
+            }
         }
     });
     app.tasks.lock().unwrap().push(listen_select);

+ 0 - 2
bin/app/src/plugin/darkirc2.rs

@@ -684,7 +684,6 @@ impl DarkIrc2 {
         };
 
         let mut found_count = 0;
-
         for event in dag_events.iter() {
             // Deserialize Privmsg
             let mut privmsg = match deserialize_async::<Privmsg>(event.content()).await {
@@ -702,7 +701,6 @@ impl DarkIrc2 {
             if privmsg.channel != channel {
                 continue;
             }
-
             found_count += 1;
 
             // Calculate message ID