mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
fix: Don't remember old channel members in the database (#7716)
This PR fixes a bug that old channel members were remembered in the database even after they left the channel. Concretely, they remained in the `past_members` table that's only meant for groups. Though it was not a bad bug; we're anyways not cleaning up old contacts.
This commit is contained in:
@@ -4087,7 +4087,7 @@ pub async fn remove_contact_from_chat(
|
|||||||
} else {
|
} else {
|
||||||
let mut sync = Nosync;
|
let mut sync = Nosync;
|
||||||
|
|
||||||
if chat.is_promoted() {
|
if chat.is_promoted() && chat.typ != Chattype::OutBroadcast {
|
||||||
remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
|
remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
|
||||||
} else {
|
} else {
|
||||||
remove_from_chat_contacts_table_without_trace(context, chat_id, contact_id).await?;
|
remove_from_chat_contacts_table_without_trace(context, chat_id, contact_id).await?;
|
||||||
|
|||||||
@@ -3344,6 +3344,11 @@ async fn test_remove_member_from_broadcast() -> Result<()> {
|
|||||||
let alice_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
|
let alice_bob_contact_id = alice.add_or_lookup_contact_id(bob).await;
|
||||||
remove_contact_from_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
|
remove_contact_from_chat(alice, alice_chat_id, alice_bob_contact_id).await?;
|
||||||
|
|
||||||
|
// Alice must not remember old members,
|
||||||
|
// because we would like to remember the minimum information possible
|
||||||
|
let past_contacts = get_past_chat_contacts(alice, alice_chat_id).await?;
|
||||||
|
assert_eq!(past_contacts.len(), 0);
|
||||||
|
|
||||||
let remove_msg = alice.pop_sent_msg().await;
|
let remove_msg = alice.pop_sent_msg().await;
|
||||||
let rcvd = bob.recv_msg(&remove_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, "Member Me removed by alice@example.org.");
|
||||||
|
|||||||
@@ -247,6 +247,37 @@ impl MimeFactory {
|
|||||||
|
|
||||||
// Do not encrypt messages to mailing lists.
|
// Do not encrypt messages to mailing lists.
|
||||||
encryption_pubkeys = None;
|
encryption_pubkeys = None;
|
||||||
|
} else if let Some(fp) = must_have_only_one_recipient(&msg, &chat) {
|
||||||
|
let fp = fp?;
|
||||||
|
// In a broadcast channel, only send member-added/removed messages
|
||||||
|
// to the affected member
|
||||||
|
let (authname, addr) = context
|
||||||
|
.sql
|
||||||
|
.query_row(
|
||||||
|
"SELECT authname, addr FROM contacts WHERE fingerprint=?",
|
||||||
|
(fp,),
|
||||||
|
|row| {
|
||||||
|
let authname: String = row.get(0)?;
|
||||||
|
let addr: String = row.get(1)?;
|
||||||
|
Ok((authname, addr))
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let public_key_bytes: Vec<_> = context
|
||||||
|
.sql
|
||||||
|
.query_get_value(
|
||||||
|
"SELECT public_key FROM public_keys WHERE fingerprint=?",
|
||||||
|
(fp,),
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.context("Can't send member addition/removal: missing key")?;
|
||||||
|
|
||||||
|
recipients.push(addr.clone());
|
||||||
|
to.push((authname, addr.clone()));
|
||||||
|
|
||||||
|
let public_key = SignedPublicKey::from_slice(&public_key_bytes)?;
|
||||||
|
encryption_pubkeys = Some(vec![(addr, public_key)]);
|
||||||
} else {
|
} else {
|
||||||
let email_to_remove = if msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup {
|
let email_to_remove = if msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup {
|
||||||
msg.param.get(Param::Arg)
|
msg.param.get(Param::Arg)
|
||||||
@@ -306,13 +337,6 @@ impl MimeFactory {
|
|||||||
for row in rows {
|
for row in rows {
|
||||||
let (authname, addr, fingerprint, id, add_timestamp, remove_timestamp, public_key_bytes_opt) = row?;
|
let (authname, addr, fingerprint, id, add_timestamp, remove_timestamp, public_key_bytes_opt) = row?;
|
||||||
|
|
||||||
// In a broadcast channel, only send member-added/removed messages
|
|
||||||
// to the affected member:
|
|
||||||
if let Some(fp) = must_have_only_one_recipient(&msg, &chat)
|
|
||||||
&& fp? != fingerprint {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let public_key_opt = if let Some(public_key_bytes) = &public_key_bytes_opt {
|
let public_key_opt = if let Some(public_key_bytes) = &public_key_bytes_opt {
|
||||||
Some(SignedPublicKey::from_slice(public_key_bytes)?)
|
Some(SignedPublicKey::from_slice(public_key_bytes)?)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user