fix(group): self-heal member group card from message field 4

A member's cached group card could stay stale for the lifetime of a long-running
bot: nothing refreshes it on a card change (no push), and the member-list refetch
only fires on join/leave/admin events (+60s TTL), never periodically — so a quiet
group freezes at warmup. get_group_msg_history / live events then showed an empty
or outdated sender.card even though the current card was in the message.

Every group message carries the sender's current display name in grp.memberCard
(field 4 = group card if set, else base nickname). The group decoder now prefers
it over the possibly-stale cache when it differs from the base nickname (a real
group card); and packet-pipeline self-heals it back into the in-memory member
cache, gated so it writes only on an actual change. This keeps active members'
cards fresh for all cache consumers off message traffic alone — no extra fetch,
no rate-limit exposure. Verified on-target: a member's card change now reflects
in the next message without a member-list refetch.

Known, accepted edge: a member changing only their base nickname (no card) is
mislabeled as a card until the next member-list refetch corrects it — field 4
alone can't distinguish the two, and the mislabeled value is still the member's
own current name.
This commit is contained in:
DrSmoothl committed 2026-07-05 14:20:36 +08:00
1 parent 8dde7ef8e2
commit 007dfaf6e2
4 files changed
+104

No files matched your search

@@ -32,6 +32,14 @@ export const decodeGroupMessage: MsgPushDecoder = (ctx) => {
if (!ev.senderNick) ev.senderNick = member.nickname;
ev.senderCard = member.card;
ev.senderRole = member.role;
// [#1] field 4 (memberCard) is the sender's CURRENT display name (group card
// if set, else base nickname). When it differs from the base nickname it's an
// up-to-date group card — fresher than the cache, which nothing refreshes on
// a card change (no push; a quiet group can freeze at warmup for months).
// Prefer it. (Self-healed back into the cache in packet-pipeline side effects.)
if (grp?.memberCard && grp.memberCard !== ev.senderNick) {
ev.senderCard = grp.memberCard;
}
} else if (!ev.senderNick && grp?.memberCard) {
ev.senderNick = grp.memberCard;
}