refactor: Merge msg_group_left_local into msg_del_member_local (#8575)

Follow-up to #8562

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Estera Ślązak
2026-08-13 14:08:27 +02:00
committed by GitHub
parent 56a99c227a
commit 1edbfa1024
4 changed files with 18 additions and 26 deletions

View File

@@ -4275,12 +4275,8 @@ async fn send_member_removal_msg(
) -> Result<MsgId> {
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;
}

View File

@@ -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(())

View File

@@ -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.")
}

View File

@@ -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)