Skip to content

feat: Resend the last 10 messages to new broadcast member#8151

Merged
Hocuri merged 11 commits into
mainfrom
hoc/resend-last-broadcast-msgs
Apr 21, 2026
Merged

feat: Resend the last 10 messages to new broadcast member#8151
Hocuri merged 11 commits into
mainfrom
hoc/resend-last-broadcast-msgs

Conversation

@Hocuri
Copy link
Copy Markdown
Collaborator

@Hocuri Hocuri commented Apr 21, 2026

Based on #7854, with the following changes:

  • Refactor and simplify code, don't reuse the existing get_chat_msgs() function
  • Document that Param::Arg4 is also used for resent messages cc818d9
  • It's unclear how exactly to resend webxdc status updates. After discussing with @r10s, don't resend webxdc's at all for now. 38d57eb
  • Don't set fake msg_id in resent messages e7d0687
    Setting the msg_id to u32::MAX is hacky, and may just as well break
    things as it may fix things, because some code may use the msg.id to
    load information from the database, like get_iroh_topic_for_msg().
    From reading the code, I couldn't find any problem with leaving the
    correct msg_id, and if there is one, then we should add a function
    parameter is_resending that is checked in the corresponding places.

Easiest to review file-by-file rather than individual commits, probably. I'll squash-merge this.

iequidoo and others added 4 commits April 17, 2026 13:58
Messages are sent and encrypted only to the new member. This way we at least postpone spreading the
information that the new member joined: even if the server operator is a broadcast member, they
can't know that immediately.
@Hocuri Hocuri marked this pull request as draft April 21, 2026 13:41
Hocuri added 5 commits April 21, 2026 15:55
Setting the msg_id to `u32::MAX` is hacky, and may just as well break
things as it may fix things, because some code may use the msg.id to
load information from the database, like `get_iroh_topic_for_msg()`.

From reading the code, I couldn't find any problem with leaving the
correct `msg_id`, and if there is one, then we should add a function
parameter `is_resending` that is checked in the corresponding places.
Comment thread src/chat.rs
info_only,
add_daymarker,
} = options;
// TODO: Remove `info_only` parameter; it's not used by anything
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this in a follow-up PR

@Hocuri Hocuri marked this pull request as ready for review April 21, 2026 14:40
Comment thread src/chat.rs
Comment on lines +4779 to +4780
// The event only matters if the message is last in the chat.
// But it's probably too expensive check, and UIs anyways need to debounce.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in practise, resent messages always belong to the same chat, in a channel, but also when resend manually by selecting in the UI

we can also move the event out of the loop, and document that all messages shall belong to the same chat

but i am also fine to leave things as is

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be fixed in this way:

diff --git a/src/chat.rs b/src/chat.rs
index 966a041ca..1b6440720 100644
--- a/src/chat.rs
+++ b/src/chat.rs
@@ -4747,6 +4747,9 @@ pub(crate) async fn resend_msgs_ex(
         msgs.push(msg)
     }
 
+    let mut chat_ids: Vec<ChatId> = msgs.iter().map(|m| m.chat_id).collect();
+    chat_ids.dedup();
+
     for mut msg in msgs {
         match msg.get_state() {
             // `get_state()` may return an outdated `OutPending`, so update anyway.
@@ -4776,9 +4779,6 @@ pub(crate) async fn resend_msgs_ex(
             chat_id: msg.chat_id,
             msg_id: msg.id,
         });
-        // The event only matters if the message is last in the chat.
-        // But it's probably too expensive check, and UIs anyways need to debounce.
-        chatlist_events::emit_chatlist_item_changed(context, msg.chat_id);
 
         if msg.viewtype == Viewtype::Webxdc {
             let conn_fn = |conn: &mut rusqlite::Connection| {
@@ -4811,6 +4811,11 @@ pub(crate) async fn resend_msgs_ex(
         }
         context.scheduler.interrupt_smtp().await;
     }
+    for chat_id in chat_ids {
+        // The event only matters if the message is last in the chat.
+        // But it's probably too expensive check, and UIs anyways need to debounce.
+        chatlist_events::emit_chatlist_item_changed(context, chat_id);
+    }
     Ok(())
 }

but is unrelated to the PR here

@Hocuri Hocuri merged commit 970222f into main Apr 21, 2026
56 of 57 checks passed
@Hocuri Hocuri deleted the hoc/resend-last-broadcast-msgs branch April 21, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants