11 files changed
+315
-176
No files matched your search
@@ -19,45 +19,31 @@ import type {
|
||||
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
// Current QQ's EncodeOperateSysNotify maps the high-level list notification
|
||||
// type to the discriminator sent by 0x10C8. This table was read directly from
|
||||
// the current Linux client; keeping the distinction prevents list type 7
|
||||
// (join request) from being incorrectly sent back as operation type 7.
|
||||
const GROUP_REQUEST_OPERATION_TYPE = new Map<number, number>([
|
||||
// Field 2 in a list entry and in its approval uses the same wire value.
|
||||
// Only the client-facing notification type needs translation.
|
||||
const GROUP_REQUEST_NOTIFY_TYPES = new Map<number, number>([
|
||||
[0, 0],
|
||||
[1, 2],
|
||||
[2, 10],
|
||||
[3, 11],
|
||||
[4, 12],
|
||||
[5, 22],
|
||||
[6, 35],
|
||||
[7, 1],
|
||||
[8, 3],
|
||||
[9, 6],
|
||||
[10, 7],
|
||||
[11, 13],
|
||||
[12, 15],
|
||||
[13, 16],
|
||||
[14, 17],
|
||||
[15, 19],
|
||||
[16, 8],
|
||||
[17, 100],
|
||||
[1, 7],
|
||||
[2, 1],
|
||||
[3, 8],
|
||||
[6, 9],
|
||||
[7, 10],
|
||||
[8, 16],
|
||||
[10, 2],
|
||||
[11, 3],
|
||||
[12, 4],
|
||||
[13, 11],
|
||||
[15, 12],
|
||||
[16, 13],
|
||||
[17, 14],
|
||||
[19, 15],
|
||||
[22, 5],
|
||||
[35, 6],
|
||||
[100, 17],
|
||||
]);
|
||||
const GROUP_REQUEST_OPERATION_OUTPUT = new Set(GROUP_REQUEST_OPERATION_TYPE.values());
|
||||
|
||||
export function groupRequestOperationType(notifyType: number): number | null {
|
||||
const mapped = GROUP_REQUEST_OPERATION_TYPE.get(notifyType);
|
||||
|
||||
if (mapped !== undefined) {
|
||||
return mapped;
|
||||
}
|
||||
|
||||
// Some list replies already carry the mapped discriminator (e.g. 22).
|
||||
if (GROUP_REQUEST_OPERATION_OUTPUT.has(notifyType)) {
|
||||
return notifyType;
|
||||
}
|
||||
|
||||
return null;
|
||||
export function groupRequestNotifyType(eventType: number): number | undefined {
|
||||
return GROUP_REQUEST_NOTIFY_TYPES.get(eventType);
|
||||
}
|
||||
|
||||
export interface DecodedGroupRequestUser {
|
||||
|
||||
@@ -152,19 +152,33 @@ export interface GroupRequestInfo {
|
||||
operatorName: string;
|
||||
sequence: number;
|
||||
state: number;
|
||||
/** High-level notification type returned by the request list. */
|
||||
/** Client notification type corresponding to the wire discriminator, when known. */
|
||||
notifyType?: number;
|
||||
/** 0x10C8 operation discriminator derived from notifyType. */
|
||||
/** Wire discriminator shared by the request list and approval. */
|
||||
eventType: number;
|
||||
comment: string;
|
||||
filtered: boolean;
|
||||
operateTransInfo?: Uint8Array;
|
||||
}
|
||||
|
||||
/** Invitations handled by the invited account, rather than a group administrator.
|
||||
* Notification types 1 and 2 use different approval discriminators. */
|
||||
/** A member invited the account to join. Wire type 10 reports a refused invitation. */
|
||||
export function isSelfGroupInvitation(request: Pick<GroupRequestInfo, 'eventType'>): boolean {
|
||||
return request.eventType === 2 || request.eventType === 10;
|
||||
return request.eventType === 2;
|
||||
}
|
||||
|
||||
/** Only joins and invitations correspond to a OneBot group request. */
|
||||
export function groupRequestSubType(
|
||||
request: Pick<GroupRequestInfo, 'eventType'>,
|
||||
): 'add' | 'invite' | undefined {
|
||||
if (request.eventType === 1) {
|
||||
return 'add';
|
||||
}
|
||||
|
||||
if (isSelfGroupInvitation(request) || request.eventType === 22) {
|
||||
return 'invite';
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Approval tuple required by OIDB 0x10C8. The OneBot flag is opaque to
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||
import {
|
||||
FetchGroupRequests,
|
||||
FetchGroupRequestsByUid,
|
||||
groupRequestOperationType,
|
||||
groupRequestNotifyType,
|
||||
} from '../../../src/oidb-services/contacts/fetch-group-requests';
|
||||
|
||||
interface ObservedGroupRequestUserByUin {
|
||||
@@ -49,14 +49,15 @@ function makeSender() {
|
||||
}
|
||||
|
||||
describe('FetchGroupRequests namespace', () => {
|
||||
it('maps native list notification types to 0x10C8 operation types', () => {
|
||||
expect(groupRequestOperationType(1)).toBe(2);
|
||||
expect(groupRequestOperationType(2)).toBe(10);
|
||||
expect(groupRequestOperationType(7)).toBe(1);
|
||||
expect(groupRequestOperationType(17)).toBe(100);
|
||||
expect(groupRequestOperationType(5)).toBe(22);
|
||||
expect(groupRequestOperationType(22)).toBe(22);
|
||||
expect(groupRequestOperationType(99)).toBeNull();
|
||||
it('interprets list discriminators in the wire-to-notification direction', () => {
|
||||
expect(groupRequestNotifyType(1)).toBe(7);
|
||||
expect(groupRequestNotifyType(2)).toBe(1);
|
||||
expect(groupRequestNotifyType(7)).toBe(10);
|
||||
expect(groupRequestNotifyType(10)).toBe(2);
|
||||
expect(groupRequestNotifyType(22)).toBe(5);
|
||||
expect(groupRequestNotifyType(100)).toBe(17);
|
||||
expect(groupRequestNotifyType(5)).toBeUndefined();
|
||||
expect(groupRequestNotifyType(99)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('declares 0x10C0', () => {
|
||||
@@ -131,7 +132,7 @@ describe('FetchGroupRequests namespace', () => {
|
||||
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' },
|
||||
@@ -156,6 +157,7 @@ describe('FetchGroupRequests namespace', () => {
|
||||
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||
|
||||
expect(response.requests?.[0]).toMatchObject({
|
||||
eventType: 1,
|
||||
target: { uin: 1_234_567_890, uid: '', name: 'requester' },
|
||||
invitor: { uin: 2_345_678_901, uid: '', name: 'inviter' },
|
||||
operatorUser: { uin: 3_456_789_012, uid: '', name: 'operator' },
|
||||
@@ -170,7 +172,7 @@ describe('FetchGroupRequests namespace', () => {
|
||||
requests: [
|
||||
{
|
||||
sequence: 99n,
|
||||
eventType: 5,
|
||||
eventType: 22,
|
||||
state: 1,
|
||||
group: { groupUin: 1001, groupName: 'group' },
|
||||
target: { uid: 'u_target', name: 'invitee' },
|
||||
@@ -194,7 +196,7 @@ describe('FetchGroupRequests namespace', () => {
|
||||
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||
|
||||
expect(response.requests?.[0]).toMatchObject({
|
||||
eventType: 5,
|
||||
eventType: 22,
|
||||
target: { uid: 'u_target', uin: 0, name: 'invitee' },
|
||||
invitor: { uid: 'u_inviter', uin: 0, name: 'inviter' },
|
||||
comment: 'join us',
|
||||
|
||||
Reference in new issue
Block a user