feat: populate contacts from message senders automatically#9
Open
Edouard-m-333 wants to merge 1 commit into
Open
feat: populate contacts from message senders automatically#9Edouard-m-333 wants to merge 1 commit into
Edouard-m-333 wants to merge 1 commit into
Conversation
Previously `contacts` was only filled from the address book (dialog peers and `contacts.*` lookups). The sender of a message from someone not in the address book — common in groups/supergroups — had no stored name, so output and analytics fell back to `user:<id>`. The name cannot be recovered later from a bare numeric id, because resolving a user requires its access_hash. Every fetched message and every real-time update already carries its sender as a `Peer`, but only the bare id was kept. This upserts the sender into `contacts` wherever a message is processed, at no extra API cost: - daemon: each incoming message upserts its sender (real-time). - sync: the three message-sync paths upsert senders of fetched messages. - chats members: persists every listed participant (incl. silent members). All reuse the existing idempotent Store::upsert_contact (COALESCE merge), so a good value is never overwritten with an empty one. No new dependencies and no schema change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
contactsis only populated from the address book (dialog peers andcontacts.*lookups). The sender of a message from someone not in your address book — common in groups/supergroups — has no stored name, so message output and SQL analytics fall back touser:<id>. The name can't be recovered later from a bare numeric id, because resolving a user requires itsaccess_hash.Change
Every fetched message and every real-time update already carries its sender as a
Peer, but only the bare id was retained. This upserts the sender intocontactsat each point a message is processed — no extra API calls, no schema change, no new dependencies:src/cmd/daemon.rs): each incomingNewMessageupserts its sender → contacts stay current in real time.src/app/sync.rs): the three message paths (sync,sync_msgs, deepfetch) upsert the senders of messages they pull. Adds aSenderContactfield onFetchedMessageand a smallsender_contact_from_peerhelper.chats members(src/cmd/chats.rs): persists every participant it lists (also covers members who haven't posted).All four reuse the existing idempotent
Store::upsert_contact, whoseON CONFLICT … DO UPDATEusesCOALESCE/non-empty guards, so a good value is never overwritten with an empty one. Failures are best-effort (logged in the daemon, ignored elsewhere) so contact population never breaks message storage.Testing
cargo build --release— clean.sync/sync msgs, andchats membersagainst a live account: group senders that previously showed asuser:<id>now resolve to names incontacts; re-runs are idempotent and don't clobber existing names.