Skip to content

fix: keep my avatar from earlier messages on a Discord message being sent - #53

Open
itz4blitz wants to merge 2 commits into
mainfrom
fix/pending-message-avatar
Open

itz4blitz wants to merge 2 commits into
mainfrom
fix/pending-message-avatar

Conversation

@itz4blitz

Copy link
Copy Markdown
Owner

Cause

chatd's new_message builds the pending row with Message::plain(..., "You", ..., true), so it has no sender id or avatar. In gui/conversation/draw.rs::avatar, an outgoing message with no avatar went straight to own_picture, which is the account snapshot's avatar. That avatar can be missing, and it is never the server-specific one. So the row showed a generic plate (or the global picture) until Discord's echo arrived with the sender avatar from adapters/discord/content.rs.

Fix

This is GUI only. The GUI is the only client that draws avatars, and it already has the conversation's messages in memory, so no database or network lookup is needed per send.

  • The history search that who used is pulled out into a pure said_by(root, messages, id). It still finds my newest message with a picture first and otherwise my newest message, so a tombstone doesn't drop the picture.
  • New own_face: for my own message, use its own avatar. If it has none, use the avatar on my newest earlier message in this conversation (matched on open.me), which is the server-specific picture when Discord sent one. Only then fall back to the account avatar.
  • The pending row now gets the same MediaFile the echo will carry, so the avatar stays put when the message is confirmed.

Validation

  • cargo test -p tinyclient --features gui (the CI command): 351 passed, 0 failed, 1 ignored. This includes 3 new tests in gui::conversation::draw::tests:
    • a pending message, with no avatar of its own and no account avatar, keeps the avatar from my earlier confirmed messages; a server-specific avatar wins over the global account one; a newer message of mine with no picture doesn't lose it
    • with none of my messages in view, the account avatar is used (or nothing), and an empty me matches nothing
    • the picture is the same before and after the confirmed message replaces the pending one
  • cargo test -p tinyclient (no features): 12 passed
  • cargo test -p chatd: 288 passed, 0 failed (no changes there)
  • cargo clippy -p tinyclient --features gui --all-targets: nothing new in draw.rs
  • Not checked in the running app.

Fixes #46

🤖 Generated with Claude Code

…sent

A pending message names no sender picture, and the row fell back to the
account's, which may be missing and is never a server's own picture of me.
It now borrows the picture my newest message in the conversation shows,
the same one the echo brings, before the account's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…il the recovery test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@itz4blitz

Copy link
Copy Markdown
Owner Author

@vbmithr this one fixes the avatar flicker from #46.

What changed (crates/tinyclient/src/gui/conversation/draw.rs, GUI only, no request per send):

  • Shared history lookup. The search that who already did is now a small function, said_by, which who reuses with unchanged behaviour.

  • New own_face for your own messages. It picks, in order:

    1. the message's own avatar;
    2. otherwise the avatar on your newest earlier message in this conversation, matched on your account id;
    3. otherwise the account avatar.

    Step 2 is the server-specific picture when Discord sent one. So the pending row now shows the same picture the confirmed echo carries, and nothing changes when it lands.

Tests (gui::conversation::draw::tests):

  • A pending message with no avatar, plus an account snapshot with no avatar, plus earlier own messages with an avatar, keeps that avatar. A server-specific avatar wins over the global one, and a newer own message with no picture doesn't lose it.
  • With no own messages in view, it falls back to the account avatar, or to none.
  • The picture is the same before and after the confirmed message replaces the pending one.

Not covered:

  • If none of your messages are in the loaded part of the conversation, it still uses the account avatar.
  • I didn't look into image-cache readiness, the second cause you raised.

This branch also carries the fix for a flaky macOS pacing test (#54), which was failing CI here.

To try it:

git fetch origin pull/53/head:pr-53 && git checkout pr-53
cargo test -p tinyclient --features gui gui::conversation::draw
cargo run -p tinyclient --features gui                     # starts chatd beside it

In a Discord channel where your earlier messages show your avatar (ideally a server where you have a per-server avatar), send a message. The sending row should show the same avatar from start to finish, with no generic icon.

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.

Discord avatar briefly becomes generic while an outgoing message is pending

1 participant