fix(onebot): restore group join request delivery

Refs #658
This commit is contained in:
DrSmoothl committed 2026-11-06 22:49:52 +08:00
1 parent b0612d8d12
commit 43b63e9a75
11 files changed
+315 -176

No files matched your search

+42 -57
View File
@@ -1,5 +1,5 @@
import { GroupInviteTracker } from '@snowluma/protocol/group-invite-tracker';
import { isSelfGroupInvitation } from '@snowluma/protocol/qq-info';
import { groupRequestSubType } from '@snowluma/protocol/qq-info';
import { FetchDownloadRkeys } from '@snowluma/protocol/oidb-services/contacts/fetch-download-rkeys';
import {
FetchFriendListPage,
@@ -12,7 +12,8 @@ import { FetchGroupMemberListPage } from '@snowluma/protocol/oidb-services/conta
import {
FetchGroupRequests,
FetchGroupRequestsByUid,
groupRequestOperationType,
groupRequestNotifyType,
type DecodedGroupRequest,
} from '@snowluma/protocol/oidb-services/contacts/fetch-group-requests';
import {
FetchRobotUinRanges,
@@ -79,19 +80,43 @@ export function isRobotUin(uin: number, ranges: readonly RobotUinRange[]): boole
);
}
function normalizeGroupRequestSequence(
rawSequence: bigint | number | undefined,
function groupRequestMetadata(
raw: Pick<
DecodedGroupRequest,
'sequence' | 'state' | 'eventType' | 'comment' | 'operateTransInfo'
>,
groupId: number,
): number {
const sequence = Number(rawSequence ?? 0);
filtered: boolean,
) {
const sequence = Number(raw.sequence ?? 0);
if (!Number.isSafeInteger(sequence) || sequence <= 0) {
throw new Error(
`invalid group-request sequence: group=${groupId} sequence=${String(rawSequence ?? 0)}`,
`invalid group-request sequence: group=${groupId} sequence=${String(raw.sequence ?? 0)}`,
);
}
return sequence;
const eventType = raw.eventType ?? 0;
const notifyType = groupRequestNotifyType(eventType);
if (notifyType === undefined) {
log.warn(
'unsupported group-request wire type: group=%d sequence=%d type=%d',
groupId,
sequence,
eventType,
);
}
return {
sequence,
state: raw.state ?? 0,
eventType,
notifyType,
comment: raw.comment ?? '',
filtered,
operateTransInfo: raw.operateTransInfo?.length ? raw.operateTransInfo : undefined,
};
}
const MEMBER_LIST_TTL_MS = 60_000;
@@ -556,18 +581,6 @@ export class ContactsApi {
this.ctx.identity.findUidByUin(operatorUin, groupId) ||
this.ctx.identity.findUidByUin(operatorUin) ||
'';
const notifyType = raw.eventType ?? 0;
const operationType = groupRequestOperationType(notifyType);
const sequence = normalizeGroupRequestSequence(raw.sequence, groupId);
if (operationType === null) {
log.warn(
'unsupported group-request notification type: group=%d sequence=%s type=%d',
groupId,
String(raw.sequence ?? 0n),
notifyType,
);
}
requests.push({
groupId,
@@ -593,16 +606,7 @@ export class ContactsApi {
this.ctx.identity.findUinByUid(operatorUid) ||
0,
operatorName: raw.operatorUser?.name ?? '',
sequence,
state: raw.state ?? 0,
notifyType,
eventType: operationType ?? 0,
comment: raw.comment ?? '',
filtered,
operateTransInfo:
raw.operateTransInfo && raw.operateTransInfo.length > 0
? raw.operateTransInfo
: undefined,
...groupRequestMetadata(raw, groupId, filtered),
});
}
@@ -626,18 +630,6 @@ export class ContactsApi {
const targetUid = raw.target?.uid ?? '';
const invitorUid = raw.invitor?.uid ?? '';
const operatorUid = raw.operatorUser?.uid ?? '';
const notifyType = raw.eventType ?? 0;
const operationType = groupRequestOperationType(notifyType);
const sequence = normalizeGroupRequestSequence(raw.sequence, groupId);
if (operationType === null) {
log.warn(
'unsupported group-request notification type: group=%d sequence=%s type=%d',
groupId,
String(raw.sequence ?? 0n),
notifyType,
);
}
requests.push({
groupId,
@@ -660,16 +652,7 @@ export class ContactsApi {
this.ctx.identity.findUinByUid(operatorUid) ??
0,
operatorName: raw.operatorUser?.name ?? '',
sequence,
state: raw.state ?? 0,
notifyType,
eventType: operationType ?? 0,
comment: raw.comment ?? '',
filtered,
operateTransInfo:
raw.operateTransInfo && raw.operateTransInfo.length > 0
? raw.operateTransInfo
: undefined,
...groupRequestMetadata(raw, groupId, filtered),
});
}
@@ -698,15 +681,17 @@ export class ContactsApi {
return (
[...main.value, ...filtered.value].find((request) => {
if (request.groupId !== groupId || request.state !== 1) {
if (
request.groupId !== groupId ||
request.state !== 1 ||
groupRequestSubType(request) !== subType
) {
return false;
}
return subType === 'add'
? request.eventType === 1 && request.targetUid === uid
: (isSelfGroupInvitation(request) || request.eventType === 22) &&
request.invitorUid === uid &&
request.targetUid === invitedUid;
? request.targetUid === uid
: request.invitorUid === uid && request.targetUid === invitedUid;
}) ?? null
);
}
+4 -2
View File
@@ -397,7 +397,7 @@ describe('apis/contacts / group requests', () => {
requests: [
{
sequence: 1_785_525_232_784_291n,
eventType: 7,
eventType: 1,
state: 1,
group: { groupUin: 1_095_186_374, groupName: 'group' },
target: { uin: 1_234_567_890, name: 'requester' },
@@ -439,7 +439,7 @@ describe('apis/contacts / group requests', () => {
requests: [
{
sequence: 42n,
eventType: 7,
eventType: 1,
state: 1,
group: { groupUin: 999, groupName: 'group' },
target: { uid: 'target_uid', name: 'requester' },
@@ -462,6 +462,8 @@ describe('apis/contacts / group requests', () => {
targetUin: 1_234_567_890,
invitorUid: 'inviter_uid',
operatorUid: 'operator_uid',
notifyType: 7,
eventType: 1,
filtered: true,
}),
]);