fix(identity): keep group roster accurate across restarts
Inbox groups and operator sightings are no longer treated as current membership after a restart. Members who actually joined stay on the roster until they leave.
This commit is contained in:
@@ -834,6 +834,28 @@ describe('IdentityService', () => {
|
||||
identity.close();
|
||||
});
|
||||
|
||||
it('does not hydrate identity-only sightings as live members after reopen', () => {
|
||||
const dbPath = tempDbPath('identity-only-not-roster');
|
||||
const member = makeMember(33333, 'u_member', 'card');
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
identity.rememberGroups([makeGroup()]);
|
||||
identity.rememberGroupMembers(GROUP_ID, [member]);
|
||||
identity.rememberGroupMemberIdentity(GROUP_ID, { uid: 'u_operator', uin: 88888 });
|
||||
expect(identity.findGroupMember(GROUP_ID, 88888)).toBeNull();
|
||||
identity.close();
|
||||
}
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
expect(identity.findGroupMember(GROUP_ID, member.uin)?.card).toBe('card');
|
||||
expect(identity.findGroupMember(GROUP_ID, 88888)).toBeNull();
|
||||
expect(identity.findUinByUid('u_operator')).toBe(88888);
|
||||
identity.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('records a thin live member on join without inventing roster details', () => {
|
||||
const identity = IdentityService.memory(SELF_UIN);
|
||||
identity.rememberGroups([makeGroup()]);
|
||||
@@ -857,6 +879,34 @@ describe('IdentityService', () => {
|
||||
identity.close();
|
||||
});
|
||||
|
||||
it('persists a thin live member on join across reopen', () => {
|
||||
const dbPath = tempDbPath('join-live-roster');
|
||||
const existing = makeMember(33333, 'u_existing', 'card');
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
identity.rememberGroups([makeGroup()]);
|
||||
identity.rememberGroupMembers(GROUP_ID, [existing]);
|
||||
identity.rememberGroupMemberJoined(GROUP_ID, { uid: 'u_join', uin: 44444 });
|
||||
identity.close();
|
||||
}
|
||||
|
||||
{
|
||||
const identity = new IdentityService(SELF_UIN, dbPath);
|
||||
const joined = identity.findGroupMember(GROUP_ID, 44444);
|
||||
expect(joined).toMatchObject({
|
||||
uin: 44444,
|
||||
uid: 'u_join',
|
||||
nickname: '',
|
||||
card: '',
|
||||
role: 'member',
|
||||
});
|
||||
expect(joined?.isRobot).toBeUndefined();
|
||||
expect(identity.findGroupMember(GROUP_ID, 33333)?.card).toBe('card');
|
||||
identity.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('drops a leaver from the live roster and keeps their identity mapping', () => {
|
||||
const identity = IdentityService.memory(SELF_UIN);
|
||||
identity.rememberGroups([makeGroup()]);
|
||||
@@ -989,7 +1039,7 @@ describe('IdentityService', () => {
|
||||
|
||||
expect(identity.findUidByUin(55555)).toBe('u_friend_request');
|
||||
expect(identity.findUinByUid('u_friend_request')).toBe(55555);
|
||||
expect(identity.findGroup(GROUP_ID)?.groupId).toBe(GROUP_ID);
|
||||
expect(identity.findGroup(GROUP_ID)).toBeNull();
|
||||
expect(identity.findUidByUin(66666)).toBe('u_group_request');
|
||||
|
||||
identity.close();
|
||||
|
||||
@@ -625,7 +625,6 @@ export class IdentityService {
|
||||
}
|
||||
this.runWrite('group requests', () => this.transaction(() => {
|
||||
for (const request of observed) {
|
||||
this.upsertGroup({ groupId: request.groupId, groupName: request.groupName });
|
||||
this.upsertUser({
|
||||
uid: request.targetUid,
|
||||
uin: request.targetUin,
|
||||
@@ -655,7 +654,6 @@ export class IdentityService {
|
||||
const observed = { ...identity };
|
||||
this.rememberUidUin(observed.uid, observed.uin);
|
||||
this.runWrite('request identity', () => this.transaction(() => {
|
||||
if (observed.groupId !== undefined) this.upsertGroup({ groupId: observed.groupId });
|
||||
this.upsertUser({
|
||||
uid: observed.uid,
|
||||
uin: observed.uin,
|
||||
@@ -666,19 +664,17 @@ export class IdentityService {
|
||||
}
|
||||
|
||||
rememberGroupMemberIdentity(
|
||||
groupId: number,
|
||||
_groupId: number,
|
||||
identity: { uid?: string; uin?: number; nickname?: string; card?: string },
|
||||
): void {
|
||||
this.beginObservation('group member identity');
|
||||
const observed = { ...identity };
|
||||
this.rememberUidUin(observed.uid, observed.uin);
|
||||
this.runWrite('group member identity', () => this.transaction(() => this.upsertGroupMember({
|
||||
groupId,
|
||||
this.runWrite('group member identity', () => this.transaction(() => this.upsertUser({
|
||||
uid: observed.uid,
|
||||
uin: observed.uin,
|
||||
nickname: observed.nickname,
|
||||
card: observed.card,
|
||||
active: true,
|
||||
source: 'group_member',
|
||||
})));
|
||||
}
|
||||
|
||||
@@ -695,7 +691,7 @@ export class IdentityService {
|
||||
if (!g || g.members.has(uin)) return;
|
||||
const uid = normalizeUid(identity.uid) ?? '';
|
||||
this.rememberUidUin(uid, uin);
|
||||
g.members.set(uin, {
|
||||
const joined: GroupMemberInfo = {
|
||||
uin,
|
||||
uid,
|
||||
nickname: '',
|
||||
@@ -706,7 +702,13 @@ export class IdentityService {
|
||||
joinTime: 0,
|
||||
lastSentTime: 0,
|
||||
shutUpTime: 0,
|
||||
});
|
||||
};
|
||||
g.members.set(uin, joined);
|
||||
this.runWrite('group member joined', () => this.transaction(() => this.upsertGroupMember({
|
||||
groupId,
|
||||
...joined,
|
||||
active: true,
|
||||
})));
|
||||
}
|
||||
|
||||
markGroupMemberInactive(groupId: number, identity: { uid?: string; uin?: number }): void {
|
||||
|
||||
Reference in New Issue
Block a user