Skip to content

fix: Don't remember old channel members in the database#7716

Merged
Hocuri merged 2 commits intomainfrom
hoc/dont-remember-old-channel-members
Jan 19, 2026
Merged

fix: Don't remember old channel members in the database#7716
Hocuri merged 2 commits intomainfrom
hoc/dont-remember-old-channel-members

Conversation

@Hocuri
Copy link
Copy Markdown
Collaborator

@Hocuri Hocuri commented Jan 14, 2026

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.

@Hocuri Hocuri requested a review from link2xt January 14, 2026 11:17
Comment on lines +250 to +274
} else if let Some(fp) = must_have_only_one_recipient(&msg, &chat) {
// In a broadcast channel, only send member-added/removed messages
// to the affected member
let (authname, addr, public_key_bytes) = context
.sql
.query_row(
"SELECT c.authname, c.addr, k.public_key
FROM contacts c, public_keys k
WHERE c.fingerprint=?1 AND k.fingerprint=?1",
(fp?,),
|row| {
let authname: String = row.get(0)?;
let addr: String = row.get(1)?;
let public_key_bytes: Vec<u8> = row.get(2)?;

Ok((authname, addr, public_key_bytes))
},
)
.await?;

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)]);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary because previously, the removed contact was loaded from the past_members table.

let (authname, addr, public_key_bytes) = context
.sql
.query_row(
"SELECT c.authname, c.addr, k.public_key
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selecting from a cross-product looks inefficent, not sure if SQLite can optimize it.

I'd rewrite this with JOIN or even use a transaction and just do two separate SELECT queries:

SELECT c.authname, c.addr, k.public_key
FROM contacts c
JOIN public_keys k ON c.fingerprint = k.fingerprint
WHERE c.fingerprint = ?

@Hocuri Hocuri merged commit 29c57ad into main Jan 19, 2026
30 checks passed
@Hocuri Hocuri deleted the hoc/dont-remember-old-channel-members branch January 19, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants