refactor: Extract function resend_last_msgs()

This commit is contained in:
Hocuri
2026-04-21 16:08:39 +02:00
parent d75c3231b9
commit 524db830f1

View File

@@ -4019,25 +4019,22 @@ pub(crate) async fn add_contact_to_chat_ex(
if sync.into() { if sync.into() {
chat.sync_contacts(context).await.log_err(context).ok(); chat.sync_contacts(context).await.log_err(context).ok();
} }
let resend_last_msgs = || async {
let msgs =
get_msgs_for_resending(context, chat.id, constants::N_MSGS_TO_NEW_BROADCAST_MEMBER)
.await?;
resend_msgs_ex(context, &msgs, contact.fingerprint()).await
};
if chat.typ == Chattype::OutBroadcast { if chat.typ == Chattype::OutBroadcast {
resend_last_msgs().await.log_err(context).ok(); resend_last_msgs(context, &chat, &contact)
.await
.log_err(context)
.ok();
} }
Ok(true) Ok(true)
} }
/// TODO async fn resend_last_msgs(
async fn get_msgs_for_resending(
context: &Context, context: &Context,
chat_id: ChatId, chat: &Chat,
n_msgs: usize, to_contact: &Contact,
) -> Result<Vec<MsgId>> { ) -> std::result::Result<(), anyhow::Error> {
let items = context let chat_id = chat.id;
let msgs: Vec<MsgId> = context
.sql .sql
.query_map_vec( .query_map_vec(
&format!( &format!(
@@ -4059,7 +4056,7 @@ ORDER BY timestamp DESC, id DESC LIMIT ?"
ContactId::INFO, ContactId::INFO,
ContactId::INFO, ContactId::INFO,
Viewtype::Webxdc, Viewtype::Webxdc,
n_msgs, constants::N_MSGS_TO_NEW_BROADCAST_MEMBER,
), ),
|row: &rusqlite::Row| Ok(row.get::<_, MsgId>(0)?), |row: &rusqlite::Row| Ok(row.get::<_, MsgId>(0)?),
) )
@@ -4067,8 +4064,7 @@ ORDER BY timestamp DESC, id DESC LIMIT ?"
.into_iter() .into_iter()
.rev() .rev()
.collect(); .collect();
resend_msgs_ex(context, &msgs, to_contact.fingerprint()).await
Ok(items)
} }
/// Returns true if an avatar should be attached in the given chat. /// Returns true if an avatar should be attached in the given chat.
@@ -4750,7 +4746,7 @@ pub async fn resend_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
/// NB: Actually `to_fingerprint` is only passed for `OutBroadcast` chats when a new member is /// NB: Actually `to_fingerprint` is only passed for `OutBroadcast` chats when a new member is
/// added. Regarding webxdc's: It is not trivial to resend only the own status updates, /// added. Regarding webxdc's: It is not trivial to resend only the own status updates,
/// and it is not trivial to resend them only to the newly-joined member, /// and it is not trivial to resend them only to the newly-joined member,
/// so that for now, webxdc's are not resent at all. /// so that for now, [`resend_last_msgs`] does not automatically resend webxdc's at all.
pub(crate) async fn resend_msgs_ex( pub(crate) async fn resend_msgs_ex(
context: &Context, context: &Context,
msg_ids: &[MsgId], msg_ids: &[MsgId],