fix(identity): keep live group membership in sync with join and leave

A join now counts the member as in the group right away. A leave drops
them from the live roster without forgetting who they are. Other
sightings still do not mean the person is in the group.
This commit is contained in:
DrSmoothl committed 2026-08-29 23:34:43 +08:00
1 parent 9e27910885
commit 9cdbcb0299
4 files changed
+132 -2

No files matched your search

+37 -2
View File
@@ -682,12 +682,47 @@ export class IdentityService {
})));
}
/** Live 花名册: the joiner is in this group now. Does not invent card/role/isRobot.
* No-op when the UIN is missing, the group is unknown, or the member is already present. */
rememberGroupMemberJoined(
groupId: number,
identity: { uid?: string; uin?: number },
): void {
this.beginObservation('group member joined');
const uin = normalizeUin(identity.uin);
if (uin === null) return;
const g = this.groups_.get(groupId);
if (!g || g.members.has(uin)) return;
const uid = normalizeUid(identity.uid) ?? '';
this.rememberUidUin(uid, uin);
g.members.set(uin, {
uin,
uid,
nickname: '',
card: '',
role: 'member',
level: 0,
title: '',
joinTime: 0,
lastSentTime: 0,
shutUpTime: 0,
});
}
markGroupMemberInactive(groupId: number, identity: { uid?: string; uin?: number }): void {
this.beginObservation('group member inactive');
const observed = { ...identity };
const uid = normalizeUid(observed.uid);
const uin = normalizeUin(observed.uin);
const g = this.groups_.get(groupId);
if (g) {
if (uin !== null) g.members.delete(uin);
else if (uid) {
const member = this.findGroupMemberByUid(groupId, uid);
if (member) g.members.delete(member.uin);
}
}
this.runWrite('group member inactive', () => {
const uid = normalizeUid(observed.uid);
const uin = normalizeUin(observed.uin);
if (!uid && uin === null) return;
const rows = this.findMemberRows(groupId, uid, uin);
const updatedAt = nowSeconds();
+4
View File
@@ -678,6 +678,10 @@ export class IncomingPacketPipeline {
uid: event.operatorUid,
uin: event.operatorUin,
});
this.deps.identity.rememberGroupMemberJoined(event.groupId, {
uid: event.userUid,
uin: event.userUin,
});
break;
case 'group_member_leave':
this.deps.identity.markGroupMemberInactive(event.groupId, {