feat: Add stock strings for being added/removed from group (#8562)

Adds following stock strings:
- You were removed by %1$s.
- You were added by %1$s.

and implicit equivalents:
- You were removed.
- You were added.

Closes: #8419

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Estera Ślązak
2026-08-11 20:47:30 +02:00
committed by GitHub
parent 5ec1d65294
commit 4623d89528
12 changed files with 84 additions and 30 deletions

View File

@@ -449,7 +449,7 @@ async fn test_parallel_member_remove() -> Result<()> {
// Test that remove message is rewritten.
assert_eq!(
bob_received_remove_msg.get_text(),
"Member Me removed by alice@example.org."
"You were removed by alice@example.org."
);
Ok(())
@@ -4002,7 +4002,7 @@ async fn test_remove_member_from_broadcast() -> Result<()> {
let remove_msg = alice.pop_sent_msg().await;
let rcvd = bob.recv_msg(&remove_msg).await;
assert_eq!(rcvd.text, "Member Me removed by alice@example.org.");
assert_eq!(rcvd.text, "You were removed by alice@example.org.");
let bob_chat = Chat::load_from_db(bob, bob_chat_id).await?;
assert_eq!(bob_chat.is_self_in_chat(bob).await?, false);

View File

@@ -1651,7 +1651,7 @@ async fn test_deduplicate_member_added() -> Result<()> {
let bob_rcvd = bob.recv_msg(&sent1).await;
assert_eq!(bob_rcvd.chat_id, bob_chat_id);
assert_eq!(bob_rcvd.text, "Member Me added by alice@example.org.");
assert_eq!(bob_rcvd.text, "You were added by alice@example.org.");
// Second message is a no-op, so it is trashed.
bob.recv_msg_trash(&sent2).await;

View File

@@ -344,6 +344,18 @@ pub enum StockMessage {
#[strum(props(fallback = "Member %1$s removed."))]
MsgDelMember = 178,
#[strum(props(fallback = "You were removed by %1$s."))]
MsgRemovedBy = 179,
#[strum(props(fallback = "You were added by %1$s."))]
MsgAddedBy = 180,
#[strum(props(fallback = "You were removed."))]
MsgRemoved = 181,
#[strum(props(fallback = "You were added."))]
MsgAdded = 182,
#[strum(props(fallback = "Establishing connection, please wait…"))]
SecurejoinWait = 190,
@@ -626,7 +638,12 @@ pub(crate) async fn msg_pinned(context: &Context, by_contact: ContactId) -> Stri
}
}
/// Stock string: `Member %1$s added.`, `You added member %1$s.` or `Member %1$s added by %2$s.`.
/// Stock string, one of:
/// - `Member %1$s added.`,
/// - `You added member %1$s.`,
/// - `Member %1$s added by %2$s.`,
/// - `You were added by %1$s.`,
/// - `You were added.`.
///
/// The `added_member` and `by_contact` contacts
/// are looked up in the database to get the display names.
@@ -636,18 +653,26 @@ pub(crate) async fn msg_add_member_local(
by_contact: ContactId,
) -> String {
let whom = added_member.get_stock_name(context).await;
if by_contact == ContactId::UNDEFINED {
translated(context, StockMessage::MsgAddMember).replace1(&whom)
} else if by_contact == ContactId::SELF {
translated(context, StockMessage::MsgYouAddMember).replace1(&whom)
} else {
translated(context, StockMessage::MsgAddMemberBy)
match (added_member, by_contact) {
(ContactId::SELF, ContactId::UNDEFINED) => translated(context, StockMessage::MsgAdded),
(ContactId::SELF, _) => translated(context, StockMessage::MsgAddedBy)
.replace1(&by_contact.get_stock_name(context).await),
(_, ContactId::UNDEFINED) => {
translated(context, StockMessage::MsgAddMember).replace1(&whom)
}
(_, ContactId::SELF) => translated(context, StockMessage::MsgYouAddMember).replace1(&whom),
_ => translated(context, StockMessage::MsgAddMemberBy)
.replace1(&whom)
.replace2(&by_contact.get_stock_name(context).await)
.replace2(&by_contact.get_stock_name(context).await),
}
}
/// Stock string: `Member %1$s removed.` or `You removed member %1$s.` or `Member %1$s removed by %2$s.`
/// Stock string, one of:
/// - `Member %1$s removed.`,
/// - `You removed member %1$s.`,
/// - `Member %1$s removed by %2$s.`,
/// - `You were removed by %1$s.`,
/// - `You were removed.`.
///
/// The `removed_member` and `by_contact` contacts
/// are looked up in the database to get the display names.
@@ -657,14 +682,19 @@ pub(crate) async fn msg_del_member_local(
by_contact: ContactId,
) -> String {
let whom = removed_member.get_stock_name(context).await;
if by_contact == ContactId::UNDEFINED {
translated(context, StockMessage::MsgDelMember).replace1(&whom)
} else if by_contact == ContactId::SELF {
translated(context, StockMessage::MsgYouDelMember).replace1(&whom)
} else {
translated(context, StockMessage::MsgDelMemberBy)
// 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) {
(ContactId::SELF, ContactId::UNDEFINED) => translated(context, StockMessage::MsgRemoved),
(ContactId::SELF, _) => translated(context, StockMessage::MsgRemovedBy)
.replace1(&by_contact.get_stock_name(context).await),
(_, ContactId::UNDEFINED) => {
translated(context, StockMessage::MsgDelMember).replace1(&whom)
}
(_, ContactId::SELF) => translated(context, StockMessage::MsgYouDelMember).replace1(&whom),
_ => translated(context, StockMessage::MsgDelMemberBy)
.replace1(&whom)
.replace2(&by_contact.get_stock_name(context).await)
.replace2(&by_contact.get_stock_name(context).await),
}
}

View File

@@ -810,7 +810,7 @@ mod tests {
let fiona = &tcm.fiona().await;
tcm.exec_securejoin_qr(fiona, alice2, &qr).await;
let msg = fiona.get_last_msg().await;
assert_eq!(msg.text, "Member Me added by alice@example.org.");
assert_eq!(msg.text, "You were added by alice@example.org.");
Ok(())
}