mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 07:16:31 +03:00
Notify a removed member that they were removed
This commit is contained in:
@@ -15,8 +15,7 @@ use num_traits::FromPrimitive;
|
||||
use regex::Regex;
|
||||
|
||||
use crate::chat::{
|
||||
self, Chat, ChatId, ChatIdBlocked, ProtectionStatus, remove_from_chat_contacts_table,
|
||||
save_broadcast_shared_secret,
|
||||
self, Chat, ChatId, ChatIdBlocked, ProtectionStatus, save_broadcast_shared_secret,
|
||||
};
|
||||
use crate::config::Config;
|
||||
use crate::constants::{self, Blocked, Chattype, DC_CHAT_ID_TRASH, EDITED_PREFIX, ShowEmails};
|
||||
@@ -28,8 +27,8 @@ use crate::ephemeral::{Timer as EphemeralTimer, stock_ephemeral_timer_changed};
|
||||
use crate::events::EventType;
|
||||
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||
use crate::imap::{GENERATED_PREFIX, markseen_on_imap_table};
|
||||
use crate::key::self_fingerprint_opt;
|
||||
use crate::key::{DcKey, Fingerprint, SignedPublicKey};
|
||||
use crate::key::{self_fingerprint, self_fingerprint_opt};
|
||||
use crate::log::LogExt;
|
||||
use crate::log::{info, warn};
|
||||
use crate::logged_debug_assert;
|
||||
@@ -2895,15 +2894,13 @@ async fn apply_group_changes(
|
||||
}
|
||||
|
||||
if let Some(removed_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) {
|
||||
// TODO: if address "alice@example.org" is a member of the group twice,
|
||||
// with old and new key,
|
||||
// and someone (maybe Alice's new contact) just removed Alice's old contact,
|
||||
// we may lookup the wrong contact because we only look up by the address.
|
||||
// The result is that info message may contain the new Alice's display name
|
||||
// rather than old display name.
|
||||
// This could be fixed by looking up the contact with the highest
|
||||
// `remove_timestamp` after applying Chat-Group-Member-Timestamps.
|
||||
removed_id = lookup_key_contact_by_address(context, removed_addr, Some(chat.id)).await?;
|
||||
if let Some(removed_fpr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemovedFpr) {
|
||||
removed_id = lookup_key_contact_by_fingerprint(context, removed_fpr).await?;
|
||||
} else {
|
||||
// Removal message sent by a legacy Delta Chat client.
|
||||
removed_id =
|
||||
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;
|
||||
@@ -2920,6 +2917,8 @@ async fn apply_group_changes(
|
||||
// we may lookup the wrong contact.
|
||||
// This could be fixed by looking up the contact with
|
||||
// highest `add_timestamp` to disambiguate.
|
||||
// Alternatively, this can be fixed by a header ChatGroupMemberAddedFpr,
|
||||
// just like we have ChatGroupMemberRemovedFpr.
|
||||
// The result of the error is that info message
|
||||
// may contain display name of the wrong contact.
|
||||
let fingerprint = key.dc_fingerprint().hex();
|
||||
@@ -3489,23 +3488,30 @@ async fn apply_out_broadcast_changes(
|
||||
)
|
||||
.await?;
|
||||
|
||||
if let Some(_removed_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) {
|
||||
// The sender of the message left the broadcast channel
|
||||
remove_from_chat_contacts_table(context, chat.id, from_id).await?;
|
||||
if let Some(removed_fpr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemovedFpr) {
|
||||
let removed_id = lookup_key_contact_by_fingerprint(context, removed_fpr).await?;
|
||||
if removed_id == Some(from_id) {
|
||||
// The sender of the message left the broadcast channel
|
||||
chat::remove_from_chat_contacts_table(context, chat.id, from_id).await?;
|
||||
|
||||
return Ok(GroupChangesInfo {
|
||||
better_msg: Some("".to_string()),
|
||||
added_removed_id: None,
|
||||
silent: true,
|
||||
extra_msgs: vec![],
|
||||
});
|
||||
return Ok(GroupChangesInfo {
|
||||
better_msg: Some("".to_string()),
|
||||
added_removed_id: None,
|
||||
silent: true,
|
||||
extra_msgs: vec![],
|
||||
});
|
||||
} else if from_id == ContactId::SELF {
|
||||
if let Some(removed_id) = removed_id {
|
||||
chat::remove_from_chat_contacts_table(context, chat.id, removed_id).await?;
|
||||
|
||||
better_msg.get_or_insert(
|
||||
stock_str::msg_del_member_local(context, removed_id, ContactId::SELF).await,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) {
|
||||
// TODO this may lookup the wrong contact if multiple contacts have the same email addr.
|
||||
// We can send sync messages instead,
|
||||
// lookup the fingerprint by gossip header (like it's done for groups right now),
|
||||
// add a header ChatGroupMemberAddedFpr,
|
||||
// or only handle addition on receival of Bob's request message and solve the problem in a different way for member-removed.
|
||||
// --> link2xt said to probably handle addition on receival of Bob's request message, and to add a header ChatGroupMemberRemovedFpr.
|
||||
// TODO this block can be removed,
|
||||
// now that all of Alice's devices get to know about Bob joining via Bob's QR message.
|
||||
let contact = lookup_key_contact_by_address(context, added_addr, None).await?;
|
||||
if let Some(contact) = contact {
|
||||
better_msg.get_or_insert(
|
||||
@@ -3565,13 +3571,20 @@ async fn apply_in_broadcast_changes(
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(_removed_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) {
|
||||
if let Some(removed_fpr) = mime_parser.get_header(HeaderDef::ChatGroupMemberRemovedFpr) {
|
||||
// We are not supposed to receive a notification when someone else than self is removed:
|
||||
ensure!(removed_fpr == self_fingerprint(context).await?);
|
||||
|
||||
if from_id == ContactId::SELF {
|
||||
// The only member added/removed message that is ever sent is "I left.",
|
||||
// so, this is the only case we need to handle here
|
||||
better_msg
|
||||
.get_or_insert(stock_str::msg_group_left_local(context, ContactId::SELF).await);
|
||||
} // TODO handle removed case
|
||||
} else {
|
||||
better_msg.get_or_insert(
|
||||
stock_str::msg_del_member_local(context, ContactId::SELF, from_id).await,
|
||||
);
|
||||
}
|
||||
|
||||
chat::remove_from_chat_contacts_table(context, chat.id, ContactId::SELF).await?;
|
||||
} else if !chat.is_self_in_chat(context).await? {
|
||||
// Apparently, self is in the chat now, because we're receiving messages
|
||||
chat::add_to_chat_contacts_table(
|
||||
|
||||
Reference in New Issue
Block a user