Skip to content

Telegram: a message deleted in a private chat can stay until the chat is reopened - #823

Closed
itz4blitz wants to merge 1 commit into
mainfrom
issue/515-telegram-delete-placed
Closed

itz4blitz wants to merge 1 commit into
mainfrom
issue/515-telegram-delete-placed

Conversation

@itz4blitz

Copy link
Copy Markdown
Collaborator

What changed and why

A message deleted in a private Telegram chat is removed even after the app has reconnected. The chat a message belongs to is kept with the message, so a delete that names only the message id can still find it. A cleared place is not reused for a later message.

Type

  • feature
  • fix
  • perf
  • refactor
  • chore
  • docs

Platforms

  • windows
  • macos
  • linux
  • android
  • ios

Proof

Scenario: e2e/scenarios/telegram-delete-placed

Lab run:

Compatibility

No protocol change. An older client still drops a private delete that arrives after a reconnect until that chat is opened again.

Risk and rollback

A wrong remembered chat would remove a message from the wrong conversation. Revert this change.

Release note

A Telegram message deleted in a private chat is removed even if the app reconnected first.

Tested with cargo test -p chatd --no-default-features --test telegram a_private_delete_after_reconnect and cargo clippy -p chatd --no-default-features --all-targets. No live Telegram account. The lab was not run.

Closes #515

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Tiny Code Review

⚠️ Code review unavailable · run

the AI provider rate-limited the request

This is advice, not a gate. Re-run with the agent:review label or a /review comment.

@unRekable unRekable left a comment

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.

Code Review

🟡 1 finding (0 blocking).

The fix persists where each placed Telegram message lives, using the existing per-account note store, and clears that note (and the in-memory entry) when a delete is applied, so a delete still names its chat after a reconnect or restart. The design holds: note keys cannot collide across the two id spaces (channel ids carry a c-prefix), clearing writes an empty value that remembered() filters, and the new integration test drives a real process restart so it fails on main without the change. The one real defect is growth: place() now writes one note row for every message seen, nothing sweeps that family, and the store's retention prunes the messages these notes shadow but never the notes themselves.

Residual risk

  • delete() resolves the peer from the conversation, so deleting a discussion-group comment (conversation cX_Y, message peer gY) clears the note tg-msg:cX:{id} while place keyed it tg-msg:{id}; the residue is harmless only because Telegram ids are never reused and the delete echo's forget_placed(None, id) clears the right key.
  • forget_placed always writes set_note(key, ""), so deletes in plain channels and private chats create empty rows even where no note existed; INSERT OR REPLACE keeps them and remembered() filters the empty value on read, so this is stray rows only.
  • Notes exist only for messages seen after this build first runs; messages seen before the upgrade still go only when their conversation is reopened, so the old behavior lingers for existing stores.

return;
}
let channel = matches!(who, Who::Channel(_)).then(|| who.text());
self.ctx.set_note(&message_note(channel.as_deref(), message), conversation);

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.

⚠️ Major: Every message that reaches the store now writes a tg-msg: row into the name table, and the family has no cap and no sweep: forget_placed clears a row only when a delete for that exact id is observed while connected, and prune() removes messages, conversations and threads but never name rows, so notes for pruned, never-deleted messages accumulate for the life of the account. Before this change the name table held only bounded per-entity rows (guilds, people, emoji); this is the first family any contact who can message you can grow without bound, which defeats the bound retention exists to keep. Smallest fix: give the family a bound, e.g. sweep stale tg-msg: rows in Store::prune alongside the messages they shadow, or delete the oldest tg-msg: row past the existing PLACED count when place writes.

@itz4blitz

Copy link
Copy Markdown
Collaborator Author

Superseded by and merged in #903 (d387971 — Release 2026-11-20 combined PR).

@itz4blitz itz4blitz closed this Nov 21, 2026
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.

Telegram: a message deleted in a private chat can stay until the chat is reopened

2 participants