From 1edbfa10249ebeb5502b809e0ece5337fd16e2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jagoda=20Estera=20=C5=9Al=C4=85zak?= <128227338+j-g00da@users.noreply.github.com> Date: Thu, 13 Aug 2026 14:08:27 +0200 Subject: [PATCH] refactor: Merge msg_group_left_local into msg_del_member_local (#8575) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #8562 Signed-off-by: Jagoda Ślązak --- src/chat.rs | 8 ++------ src/chat/chat_tests.rs | 2 +- src/receive_imf.rs | 8 ++------ src/stock_str.rs | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 7f51518a2..e1b843022 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4275,12 +4275,8 @@ async fn send_member_removal_msg( ) -> Result { let mut msg = Message::new(Viewtype::Text); - if contact_id == ContactId::SELF { - if chat.typ == Chattype::InBroadcast { - msg.text = stock_str::msg_you_left_broadcast(context); - } else { - msg.text = stock_str::msg_group_left_local(context, ContactId::SELF).await; - } + if contact_id == ContactId::SELF && chat.typ == Chattype::InBroadcast { + msg.text = stock_str::msg_you_left_broadcast(context); } else { msg.text = stock_str::msg_del_member_local(context, contact_id, ContactId::SELF).await; } diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 9ec0f5d40..e2b7f0161 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -387,7 +387,7 @@ async fn test_member_add_remove() -> Result<()> { let sent = alice.pop_sent_msg().await; assert_eq!( sent.load_from_db().await.get_text(), - stock_str::msg_group_left_local(&alice, ContactId::SELF).await + stock_str::msg_del_member_local(&alice, ContactId::SELF, ContactId::SELF).await ); Ok(()) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index bc931751b..4aff9b6c0 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -3038,12 +3038,8 @@ async fn apply_group_changes( lookup_key_contact_by_address(context, removed_addr, Some(chat.id)).await?; } if let Some(id) = removed_id { - better_msg = if id == from_id { - silent = true; - Some(stock_str::msg_group_left_local(context, from_id).await) - } else { - Some(stock_str::msg_del_member_local(context, id, from_id).await) - }; + silent = id == from_id; + better_msg = Some(stock_str::msg_del_member_local(context, id, from_id).await); } else { warn!(context, "Removed {removed_addr:?} has no contact id.") } diff --git a/src/stock_str.rs b/src/stock_str.rs index be1eb1e48..b6ffdc60d 100644 --- a/src/stock_str.rs +++ b/src/stock_str.rs @@ -672,7 +672,9 @@ pub(crate) async fn msg_add_member_local( /// - `You removed member %1$s.`, /// - `Member %1$s removed by %2$s.`, /// - `You were removed by %1$s.`, -/// - `You were removed.`. +/// - `You were removed.`, +/// - `You left the group.`, +/// - `Group left by %1$s.`. /// /// The `removed_member` and `by_contact` contacts /// are looked up in the database to get the display names. @@ -682,32 +684,30 @@ pub(crate) async fn msg_del_member_local( by_contact: ContactId, ) -> String { let whom = removed_member.get_stock_name(context).await; - // note: this does not properly handle (SELF, SELF) case, - // as "you left"/"left by" messages are handled by `msg_group_left_local`. match (removed_member, by_contact) { + // You left the group. + (ContactId::SELF, ContactId::SELF) => translated(context, StockMessage::MsgYouLeftGroup), + // You were removed. (ContactId::SELF, ContactId::UNDEFINED) => translated(context, StockMessage::MsgRemoved), + // You were removed by ... (ContactId::SELF, _) => translated(context, StockMessage::MsgRemovedBy) .replace1(&by_contact.get_stock_name(context).await), + // Member ... removed. (_, ContactId::UNDEFINED) => { translated(context, StockMessage::MsgDelMember).replace1(&whom) } + // You removed member ... (_, ContactId::SELF) => translated(context, StockMessage::MsgYouDelMember).replace1(&whom), + // Group left by ... + (a, b) if a == b => translated(context, StockMessage::MsgGroupLeftBy) + .replace1(&by_contact.get_stock_name(context).await), + // Member ... removed by ... _ => translated(context, StockMessage::MsgDelMemberBy) .replace1(&whom) .replace2(&by_contact.get_stock_name(context).await), } } -/// Stock string: `You left the group.` or `Group left by %1$s.`. -pub(crate) async fn msg_group_left_local(context: &Context, by_contact: ContactId) -> String { - if by_contact == ContactId::SELF { - translated(context, StockMessage::MsgYouLeftGroup) - } else { - translated(context, StockMessage::MsgGroupLeftBy) - .replace1(&by_contact.get_stock_name(context).await) - } -} - /// Stock string: `You left the channel.` pub(crate) fn msg_you_left_broadcast(context: &Context) -> String { translated(context, StockMessage::MsgYouLeftBroadcast)