refactor: replace polling with event-driven updates
Trigger account detection and group requests from observed changes. Remove native stage log forwarding and its lifecycle state, and simplify the README.
This commit is contained in:
1 parent
1b74747251
commit
e5cfec01bd
33 files changed
+1314
-1958
No files matched your search
@@ -581,11 +581,48 @@ export class ContactsApi {
|
||||
return requests;
|
||||
}
|
||||
|
||||
/** Live observation write. IncomingPacketPipeline and tests only. */
|
||||
rememberGroupInviteCardSequence(groupUin: number, sequence: number): void {
|
||||
if (groupUin > 0 && sequence > 0) {
|
||||
this.groupInviteCardSeqs_.set(groupUin, sequence);
|
||||
async resolveGroupJoinRequest(
|
||||
groupId: number,
|
||||
uid: string,
|
||||
subType: 'add' | 'invite',
|
||||
invitedUid?: string,
|
||||
): Promise<GroupRequestInfo | null> {
|
||||
const [main, filtered] = await Promise.allSettled([
|
||||
this.fetchGroupRequestsByUid(false),
|
||||
this.fetchGroupRequestsByUid(true),
|
||||
]);
|
||||
|
||||
if (main.status === 'rejected') {
|
||||
throw main.reason;
|
||||
}
|
||||
|
||||
if (filtered.status === 'rejected') {
|
||||
throw filtered.reason;
|
||||
}
|
||||
|
||||
return (
|
||||
[...main.value, ...filtered.value].find((request) => {
|
||||
if (request.groupId !== groupId || request.state !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return subType === 'add'
|
||||
? request.eventType === 1 && request.targetUid === uid
|
||||
: (request.eventType === 2 || request.eventType === 22) &&
|
||||
request.invitorUid === uid &&
|
||||
request.targetUid === invitedUid;
|
||||
}) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
/** Returns whether this live card introduces a new approval sequence. */
|
||||
rememberGroupInviteCardSequence(groupUin: number, sequence: number): boolean {
|
||||
if (this.groupInviteCardSeqs_.get(groupUin) === sequence) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.groupInviteCardSeqs_.set(groupUin, sequence);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** The approval msgseq captured from a private "qun.invite" card for this
|
||||
|
||||
@@ -61,72 +61,10 @@ export class Bridge implements BridgeInterface {
|
||||
fetchGroupMemberList: async (groupId) => {
|
||||
await this.apis.contacts.fetchGroupMemberList(groupId);
|
||||
},
|
||||
resolveGroupJoinRequest: async (groupId, uid, subType) => {
|
||||
const [main, filtered] = await Promise.allSettled([
|
||||
this.apis.contacts.fetchGroupRequestsByUid(false),
|
||||
this.apis.contacts.fetchGroupRequestsByUid(true),
|
||||
]);
|
||||
|
||||
if (main.status === 'rejected') {
|
||||
log.warn(
|
||||
'group-request enrichment main inbox failed: group=%d uid=%s err=%s',
|
||||
groupId,
|
||||
uid,
|
||||
main.reason instanceof Error ? main.reason.message : String(main.reason),
|
||||
);
|
||||
}
|
||||
|
||||
if (filtered.status === 'rejected') {
|
||||
log.warn(
|
||||
'group-request enrichment filtered inbox failed: group=%d uid=%s err=%s',
|
||||
groupId,
|
||||
uid,
|
||||
filtered.reason instanceof Error
|
||||
? filtered.reason.message
|
||||
: String(filtered.reason),
|
||||
);
|
||||
}
|
||||
|
||||
if (main.status === 'rejected' && filtered.status === 'rejected') {
|
||||
throw new Error('failed to fetch group requests from both inboxes');
|
||||
}
|
||||
|
||||
const requests = [
|
||||
...(main.status === 'fulfilled' ? main.value : []),
|
||||
...(filtered.status === 'fulfilled' ? filtered.value : []),
|
||||
];
|
||||
const matches = requests.filter((r) => {
|
||||
if (r.groupId !== groupId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return subType === 'invite' ? r.invitorUid === uid : r.targetUid === uid;
|
||||
});
|
||||
|
||||
if (subType === 'invite') {
|
||||
return matches.find((r) => r.notifyType === 1) ?? matches[0] ?? null;
|
||||
}
|
||||
|
||||
return matches.find((r) => r.notifyType === 7) ?? matches[0] ?? null;
|
||||
},
|
||||
resolveGroupInviteCardSequence: async (groupId) => {
|
||||
const deadline = Date.now() + 1_000;
|
||||
|
||||
do {
|
||||
const sequence = this.apis.contacts.getGroupInviteCardSequence(groupId);
|
||||
|
||||
if (sequence) {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 25));
|
||||
} while (Date.now() < deadline);
|
||||
|
||||
return null;
|
||||
},
|
||||
rememberGroupInviteCardSequence: (groupUin, sequence) => {
|
||||
this.apis.contacts.rememberGroupInviteCardSequence(groupUin, sequence);
|
||||
},
|
||||
resolveGroupJoinRequest: (groupId, uid, subType, invitedUid) =>
|
||||
this.apis.contacts.resolveGroupJoinRequest(groupId, uid, subType, invitedUid),
|
||||
rememberGroupInviteCardSequence: (groupUin, sequence) =>
|
||||
this.apis.contacts.rememberGroupInviteCardSequence(groupUin, sequence),
|
||||
});
|
||||
this.pipeline.registerCmd(MSG_PUSH_CMD, (pkt, identity) =>
|
||||
parseMsgPushOrThrow(pkt, identity, this.sysMsgDedup_),
|
||||
|
||||
Reference in new issue
Block a user