fix(onebot): restore group and doubt request accounts
get_group_system_msg now keeps join and invite records, reports the inviter, and fills a missing requester nick from the user profile. get_doubt_friends_add_request returns the QQ number plus the request message, source, and time that QQ actually sends. Closes #400 Closes #401 Closes #402 Closes #403
This commit is contained in:
13 files changed
+418
-79
No files matched your search
@@ -354,6 +354,18 @@ export class ContactsApi {
|
|||||||
const targetUin = raw.target?.uin ?? 0;
|
const targetUin = raw.target?.uin ?? 0;
|
||||||
const invitorUin = raw.invitor?.uin ?? 0;
|
const invitorUin = raw.invitor?.uin ?? 0;
|
||||||
const operatorUin = raw.operatorUser?.uin ?? 0;
|
const operatorUin = raw.operatorUser?.uin ?? 0;
|
||||||
|
const targetUid = raw.target?.uid
|
||||||
|
|| this.ctx.identity.findUidByUin(targetUin, groupId)
|
||||||
|
|| this.ctx.identity.findUidByUin(targetUin)
|
||||||
|
|| '';
|
||||||
|
const invitorUid = raw.invitor?.uid
|
||||||
|
|| this.ctx.identity.findUidByUin(invitorUin, groupId)
|
||||||
|
|| this.ctx.identity.findUidByUin(invitorUin)
|
||||||
|
|| '';
|
||||||
|
const operatorUid = raw.operatorUser?.uid
|
||||||
|
|| this.ctx.identity.findUidByUin(operatorUin, groupId)
|
||||||
|
|| this.ctx.identity.findUidByUin(operatorUin)
|
||||||
|
|| '';
|
||||||
const notifyType = raw.eventType ?? 0;
|
const notifyType = raw.eventType ?? 0;
|
||||||
const operationType = groupRequestOperationType(notifyType);
|
const operationType = groupRequestOperationType(notifyType);
|
||||||
const sequence = normalizeGroupRequestSequence(raw.sequence, groupId);
|
const sequence = normalizeGroupRequestSequence(raw.sequence, groupId);
|
||||||
@@ -368,20 +380,23 @@ export class ContactsApi {
|
|||||||
requests.push({
|
requests.push({
|
||||||
groupId,
|
groupId,
|
||||||
groupName: raw.group?.groupName ?? '',
|
groupName: raw.group?.groupName ?? '',
|
||||||
targetUid: this.ctx.identity.findUidByUin(targetUin, groupId)
|
targetUid,
|
||||||
?? this.ctx.identity.findUidByUin(targetUin)
|
targetUin: targetUin
|
||||||
?? '',
|
|| this.ctx.identity.findUinByUid(targetUid, groupId)
|
||||||
targetUin,
|
|| this.ctx.identity.findUinByUid(targetUid)
|
||||||
|
|| 0,
|
||||||
targetName: raw.target?.name ?? '',
|
targetName: raw.target?.name ?? '',
|
||||||
invitorUid: this.ctx.identity.findUidByUin(invitorUin, groupId)
|
invitorUid,
|
||||||
?? this.ctx.identity.findUidByUin(invitorUin)
|
invitorUin: invitorUin
|
||||||
?? '',
|
|| this.ctx.identity.findUinByUid(invitorUid, groupId)
|
||||||
invitorUin,
|
|| this.ctx.identity.findUinByUid(invitorUid)
|
||||||
|
|| 0,
|
||||||
invitorName: raw.invitor?.name ?? '',
|
invitorName: raw.invitor?.name ?? '',
|
||||||
operatorUid: this.ctx.identity.findUidByUin(operatorUin, groupId)
|
operatorUid,
|
||||||
?? this.ctx.identity.findUidByUin(operatorUin)
|
operatorUin: operatorUin
|
||||||
?? '',
|
|| this.ctx.identity.findUinByUid(operatorUid, groupId)
|
||||||
operatorUin,
|
|| this.ctx.identity.findUinByUid(operatorUid)
|
||||||
|
|| 0,
|
||||||
operatorName: raw.operatorUser?.name ?? '',
|
operatorName: raw.operatorUser?.name ?? '',
|
||||||
sequence,
|
sequence,
|
||||||
state: raw.state ?? 0,
|
state: raw.state ?? 0,
|
||||||
|
|||||||
@@ -48,8 +48,19 @@ export class FriendApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** List doubtful friend-add requests (可能认识的人). */
|
/** List doubtful friend-add requests (可能认识的人). */
|
||||||
getDoubtRequests(count: number): Promise<DoubtBuddyRequest[]> {
|
async getDoubtRequests(count: number): Promise<DoubtBuddyRequest[]> {
|
||||||
return GetDoubtBuddyReq.invoke(this.ctx, { count });
|
const list = await GetDoubtBuddyReq.invoke(this.ctx, { count });
|
||||||
|
return list.map((item) => {
|
||||||
|
let uid = item.uid;
|
||||||
|
let userId = item.user_id;
|
||||||
|
if (userId <= 0 && uid) {
|
||||||
|
userId = this.ctx.identity.findUinByUid(uid) ?? 0;
|
||||||
|
}
|
||||||
|
if (!uid && userId > 0) {
|
||||||
|
uid = this.ctx.identity.findUidByUin(userId) ?? '';
|
||||||
|
}
|
||||||
|
return { ...item, uid, user_id: userId };
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Approve a doubtful friend-add request by its uid (the list item's flag). */
|
/** Approve a doubtful friend-add request by its uid (the list item's flag). */
|
||||||
|
|||||||
@@ -996,12 +996,10 @@ export const actions = [
|
|||||||
params: {
|
params: {
|
||||||
nickname: f.string().optional(),
|
nickname: f.string().optional(),
|
||||||
personal_note: f.string().optional(),
|
personal_note: f.string().optional(),
|
||||||
|
sex: f.int({ min: 0, max: 2 }).optional().describe('0 未知,1 男,2 女'),
|
||||||
},
|
},
|
||||||
run: async (p, ctx) => {
|
run: async (p, ctx) => {
|
||||||
const nickname = p.nickname;
|
await ctx.bridge.apis.profile.setProfile(p.nickname, p.personal_note, p.sex);
|
||||||
const personalNote = p.personal_note;
|
|
||||||
|
|
||||||
await ctx.bridge.apis.profile.setProfile(nickname, personalNote);
|
|
||||||
return okResponse();
|
return okResponse();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -1400,6 +1398,41 @@ export const actions = [
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
defineAction({
|
||||||
|
name: 'get_msg_emoji_likes',
|
||||||
|
summary: '获取一条消息的全部表情回应',
|
||||||
|
readOnly: true,
|
||||||
|
returns: '该消息上每个表情回应的编号、数量与用户列表。',
|
||||||
|
returnsSchema: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
emoji_id: { type: 'string', description: '表情编号' },
|
||||||
|
emoji_type: { type: 'integer', description: '表情类型' },
|
||||||
|
count: { type: 'integer', description: '回应数量' },
|
||||||
|
last_reaction_time: { type: 'integer', description: '最近一次回应时间' },
|
||||||
|
users: {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
properties: { user_id: { type: 'integer', description: '用户 QQ 号' } },
|
||||||
|
required: ['user_id'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['emoji_id', 'emoji_type', 'count', 'last_reaction_time', 'users'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
params: { message_id: f.messageId() },
|
||||||
|
run: async (p, ctx) => {
|
||||||
|
if (!ctx.fetchEmojiLikeSummary) {
|
||||||
|
return failedResponse(RETCODE.ACTION_FAILED, 'emoji reaction summary is unavailable');
|
||||||
|
}
|
||||||
|
return okResponse(await ctx.fetchEmojiLikeSummary(p.message_id));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
defineAction({
|
defineAction({
|
||||||
name: 'get_friends_with_category',
|
name: 'get_friends_with_category',
|
||||||
summary: '获取分组好友列表',
|
summary: '获取分组好友列表',
|
||||||
@@ -1746,12 +1779,15 @@ export const actions = [
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
uid: { type: 'string', description: '申请人 uid(回传作 set_doubt_friends_add_request 的 flag)' },
|
uid: { type: 'string', description: '申请人 uid(回传作 set_doubt_friends_add_request 的 flag)' },
|
||||||
|
user_id: { type: 'integer', description: '申请人 QQ 号' },
|
||||||
nick: { type: 'string', description: '申请人昵称' },
|
nick: { type: 'string', description: '申请人昵称' },
|
||||||
source: { type: 'string', description: '申请来源' },
|
source: { type: 'string', description: '申请来源' },
|
||||||
|
reason: { type: 'string', description: '附加说明' },
|
||||||
msg: { type: 'string', description: '验证留言' },
|
msg: { type: 'string', description: '验证留言' },
|
||||||
|
group_code: { type: 'string', description: '来源群号,无则为空串' },
|
||||||
reqTime: { type: 'integer', description: '申请时间戳' },
|
reqTime: { type: 'integer', description: '申请时间戳' },
|
||||||
},
|
},
|
||||||
required: ['uid', 'nick', 'source', 'msg', 'reqTime'],
|
required: ['uid', 'user_id', 'nick', 'source', 'reason', 'msg', 'group_code', 'reqTime'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
params: { count: f.int({ min: 0 }).default(50) },
|
params: { count: f.int({ min: 0 }).default(50) },
|
||||||
|
|||||||
@@ -224,13 +224,16 @@ export const actions = [
|
|||||||
request_id: { type: 'integer', description: '请求序列号' },
|
request_id: { type: 'integer', description: '请求序列号' },
|
||||||
requester_uin: { type: 'integer', description: '申请人 QQ 号' },
|
requester_uin: { type: 'integer', description: '申请人 QQ 号' },
|
||||||
requester_nick: { type: 'string', description: '申请人昵称' },
|
requester_nick: { type: 'string', description: '申请人昵称' },
|
||||||
|
invitor_uin: { type: 'integer', description: '邀请人 QQ 号,无邀请时为 0' },
|
||||||
|
invitor_nick: { type: 'string', description: '邀请人昵称' },
|
||||||
message: { type: 'string', description: '验证留言' },
|
message: { type: 'string', description: '验证留言' },
|
||||||
checked: { type: 'boolean', description: '是否已处理' },
|
checked: { type: 'boolean', description: '是否已处理' },
|
||||||
flag: { type: 'string', description: '处理请求使用的规范 flag' },
|
flag: { type: 'string', description: '处理请求使用的规范 flag' },
|
||||||
},
|
},
|
||||||
required: [
|
required: [
|
||||||
'group_id', 'group_name', 'request_id', 'requester_uin',
|
'group_id', 'group_name', 'request_id', 'requester_uin',
|
||||||
'requester_nick', 'message', 'checked', 'flag',
|
'requester_nick', 'invitor_uin', 'invitor_nick',
|
||||||
|
'message', 'checked', 'flag',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -280,35 +280,39 @@ export async function getGroupFiles(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatStrangerInfo(p: UserProfileInfo): JsonObject {
|
||||||
|
return {
|
||||||
|
user_id: p.uin,
|
||||||
|
nickname: p.nickname,
|
||||||
|
remark: p.remark,
|
||||||
|
sex: p.sex,
|
||||||
|
age: p.age,
|
||||||
|
long_nick: p.sign,
|
||||||
|
qq_level: p.level,
|
||||||
|
level: p.level,
|
||||||
|
status: p.status ?? 0,
|
||||||
|
extStatus: p.extStatus ?? 0,
|
||||||
|
ext_status: p.extStatus ?? 0,
|
||||||
|
batteryStatus: p.batteryStatus ?? 0,
|
||||||
|
customStatus: p.customStatus ?? null,
|
||||||
|
customStatusDescInfo: p.customStatusDesc ?? '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function getStrangerInfo(
|
export async function getStrangerInfo(
|
||||||
bridge: BridgeInterface,
|
bridge: BridgeInterface,
|
||||||
userId: number,
|
userId: number,
|
||||||
): Promise<JsonObject | null> {
|
): Promise<JsonObject | null> {
|
||||||
try {
|
try {
|
||||||
const p = await bridge.apis.contacts.fetchUserProfile(userId);
|
const p = await bridge.apis.contacts.fetchUserProfile(userId);
|
||||||
return {
|
return formatStrangerInfo(p);
|
||||||
user_id: p.uin,
|
|
||||||
nickname: p.nickname,
|
|
||||||
remark: p.remark,
|
|
||||||
sex: p.sex,
|
|
||||||
age: p.age,
|
|
||||||
long_nick: p.sign,
|
|
||||||
qq_level: p.level,
|
|
||||||
level: p.level,
|
|
||||||
};
|
|
||||||
} catch {
|
} catch {
|
||||||
const p = bridge.identity.findUserProfile(userId);
|
const p = bridge.identity.findUserProfile(userId);
|
||||||
if (p) {
|
if (p) {
|
||||||
return {
|
return formatStrangerInfo({
|
||||||
user_id: p.uin,
|
...p,
|
||||||
nickname: p.nickname,
|
|
||||||
remark: p.remark || bridge.identity.findFriend(userId)?.remark || '',
|
remark: p.remark || bridge.identity.findFriend(userId)?.remark || '',
|
||||||
sex: p.sex,
|
});
|
||||||
age: p.age,
|
|
||||||
long_nick: p.sign,
|
|
||||||
qq_level: p.level,
|
|
||||||
level: p.level,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const friend = bridge.identity.findFriend(userId);
|
const friend = bridge.identity.findFriend(userId);
|
||||||
@@ -327,24 +331,33 @@ export async function getStrangerInfo(
|
|||||||
async function resolveRequesterUins(
|
async function resolveRequesterUins(
|
||||||
bridge: BridgeInterface,
|
bridge: BridgeInterface,
|
||||||
requests: readonly GroupRequestInfo[],
|
requests: readonly GroupRequestInfo[],
|
||||||
): Promise<Map<string, number>> {
|
): Promise<Map<string, { uin: number; name: string }>> {
|
||||||
const resolved = new Map<string, number>();
|
const resolved = new Map<string, { uin: number; name: string }>();
|
||||||
const unresolved = new Set<string>();
|
const unresolved = new Set<string>();
|
||||||
|
const names = new Map<string, string>();
|
||||||
|
const unresolvedUins = new Set<number>();
|
||||||
|
|
||||||
for (const request of requests) {
|
for (const request of requests) {
|
||||||
const actor = groupRequestActor(request);
|
const actor = groupRequestActor(request);
|
||||||
const uid = actor.uid;
|
const uid = actor.uid;
|
||||||
if (!uid || resolved.has(uid)) continue;
|
if (actor.name) names.set(uid || `uin:${actor.uin}`, actor.name);
|
||||||
if (actor.uin > 0) {
|
if (uid && actor.uin > 0 && actor.name) {
|
||||||
resolved.set(uid, actor.uin);
|
resolved.set(uid, { uin: actor.uin, name: actor.name });
|
||||||
unresolved.delete(uid);
|
unresolved.delete(uid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (unresolved.has(uid)) continue;
|
if (uid) {
|
||||||
const cached = bridge.identity.findUinByUid(uid, request.groupId)
|
if (resolved.has(uid) || unresolved.has(uid)) continue;
|
||||||
?? bridge.identity.findUinByUid(uid);
|
const cached = bridge.identity.findUinByUid(uid, request.groupId)
|
||||||
if (cached && cached > 0) resolved.set(uid, cached);
|
?? bridge.identity.findUinByUid(uid);
|
||||||
else unresolved.add(uid);
|
if (cached && cached > 0 && actor.name) {
|
||||||
|
resolved.set(uid, { uin: cached, name: actor.name });
|
||||||
|
} else {
|
||||||
|
unresolved.add(uid);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (actor.uin > 0 && !actor.name) unresolvedUins.add(actor.uin);
|
||||||
}
|
}
|
||||||
|
|
||||||
const profiles = await mapWithConcurrency(
|
const profiles = await mapWithConcurrency(
|
||||||
@@ -361,13 +374,43 @@ async function resolveRequesterUins(
|
|||||||
if (!Number.isSafeInteger(profile.uin) || profile.uin <= 0) {
|
if (!Number.isSafeInteger(profile.uin) || profile.uin <= 0) {
|
||||||
throw new Error(`failed to resolve requester UIN for UID ${uid}`);
|
throw new Error(`failed to resolve requester UIN for UID ${uid}`);
|
||||||
}
|
}
|
||||||
return [uid, profile.uin] as const;
|
return [uid, profile] as const;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
for (const [uid, uin] of profiles) resolved.set(uid, uin);
|
for (const [uid, profile] of profiles) {
|
||||||
|
resolved.set(uid, {
|
||||||
|
uin: profile.uin,
|
||||||
|
name: names.get(uid) || profile.nickname || '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const uinProfiles = await mapWithConcurrency(
|
||||||
|
[...unresolvedUins],
|
||||||
|
REQUESTER_PROFILE_CONCURRENCY,
|
||||||
|
async (uin) => {
|
||||||
|
try {
|
||||||
|
return [uin, await bridge.apis.contacts.fetchUserProfile(uin)] as const;
|
||||||
|
} catch {
|
||||||
|
return [uin, undefined] as const;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
for (const [uin, profile] of uinProfiles) {
|
||||||
|
if (!profile) continue;
|
||||||
|
resolved.set(`uin:${uin}`, { uin: profile.uin, name: profile.nickname || '' });
|
||||||
|
}
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Join request (7) or invite that still needs an admin (5 / mapped 22). */
|
||||||
|
function isJoinOrInviteNotify(notifyType: number | undefined): boolean {
|
||||||
|
return notifyType === undefined
|
||||||
|
|| notifyType === 1
|
||||||
|
|| notifyType === 5
|
||||||
|
|| notifyType === 7
|
||||||
|
|| notifyType === 22;
|
||||||
|
}
|
||||||
|
|
||||||
function groupRequestActor(request: GroupRequestInfo): {
|
function groupRequestActor(request: GroupRequestInfo): {
|
||||||
uid: string;
|
uid: string;
|
||||||
uin: number;
|
uin: number;
|
||||||
@@ -401,9 +444,7 @@ export async function getGroupSystemMessages(
|
|||||||
]);
|
]);
|
||||||
const unique = new Map<string, GroupRequestInfo>();
|
const unique = new Map<string, GroupRequestInfo>();
|
||||||
for (const request of [...main, ...filtered]) {
|
for (const request of [...main, ...filtered]) {
|
||||||
if (request.notifyType !== undefined
|
if (!isJoinOrInviteNotify(request.notifyType)) continue;
|
||||||
&& request.notifyType !== 1
|
|
||||||
&& request.notifyType !== 7) continue;
|
|
||||||
if (request.eventType <= 0) continue;
|
if (request.eventType <= 0) continue;
|
||||||
const flag = formatGroupRequestFlag(request);
|
const flag = formatGroupRequestFlag(request);
|
||||||
if (!unique.has(flag)) unique.set(flag, request);
|
if (!unique.has(flag)) unique.set(flag, request);
|
||||||
@@ -417,12 +458,16 @@ export async function getGroupSystemMessages(
|
|||||||
|
|
||||||
return requests.map((request) => {
|
return requests.map((request) => {
|
||||||
const actor = groupRequestActor(request);
|
const actor = groupRequestActor(request);
|
||||||
|
const resolved = (actor.uid ? requesterUins.get(actor.uid) : undefined)
|
||||||
|
?? (actor.uin > 0 ? requesterUins.get(`uin:${actor.uin}`) : undefined);
|
||||||
return {
|
return {
|
||||||
group_id: request.groupId,
|
group_id: request.groupId,
|
||||||
group_name: request.groupName,
|
group_name: request.groupName,
|
||||||
request_id: request.sequence,
|
request_id: request.sequence,
|
||||||
requester_uin: requesterUins.get(actor.uid) ?? actor.uin,
|
requester_uin: resolved?.uin ?? actor.uin,
|
||||||
requester_nick: actor.name,
|
requester_nick: resolved?.name || actor.name,
|
||||||
|
invitor_uin: request.invitorUin,
|
||||||
|
invitor_nick: request.invitorName,
|
||||||
message: request.comment,
|
message: request.comment,
|
||||||
checked: request.state !== 1,
|
checked: request.state !== 1,
|
||||||
flag: formatGroupRequestFlag(request),
|
flag: formatGroupRequestFlag(request),
|
||||||
|
|||||||
@@ -627,6 +627,30 @@ describe('onebot/contact-actions / getGroupSystemMessages', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes admin-approval invitations with the invited account and inviter', async () => {
|
||||||
|
const bridge = fakeBridge({
|
||||||
|
fetchGroupRequests: vi.fn(async (filtered: boolean) => filtered ? [] : [
|
||||||
|
makeGroupRequest({
|
||||||
|
notifyType: 5,
|
||||||
|
eventType: 22,
|
||||||
|
targetUin: 10_001,
|
||||||
|
targetName: 'invitee',
|
||||||
|
invitorUin: 45_678,
|
||||||
|
invitorName: 'inviter',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await getGroupSystemMessages(bridge);
|
||||||
|
|
||||||
|
expect(result).toEqual([expect.objectContaining({
|
||||||
|
requester_uin: 10_001,
|
||||||
|
requester_nick: 'invitee',
|
||||||
|
invitor_uin: 45_678,
|
||||||
|
invitor_nick: 'inviter',
|
||||||
|
})]);
|
||||||
|
});
|
||||||
|
|
||||||
it('reports the inviter as requester for group invitations', async () => {
|
it('reports the inviter as requester for group invitations', async () => {
|
||||||
const bridge = fakeBridge({
|
const bridge = fakeBridge({
|
||||||
fetchGroupRequests: vi.fn(async (filtered: boolean) => filtered ? [] : [
|
fetchGroupRequests: vi.fn(async (filtered: boolean) => filtered ? [] : [
|
||||||
@@ -646,6 +670,8 @@ describe('onebot/contact-actions / getGroupSystemMessages', () => {
|
|||||||
expect(result).toEqual([expect.objectContaining({
|
expect(result).toEqual([expect.objectContaining({
|
||||||
requester_uin: 45_678,
|
requester_uin: 45_678,
|
||||||
requester_nick: 'inviter',
|
requester_nick: 'inviter',
|
||||||
|
invitor_uin: 45_678,
|
||||||
|
invitor_nick: 'inviter',
|
||||||
})]);
|
})]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2027,7 +2027,10 @@ describe('extended-actions / TierB ③ share + doubt + robot-option', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('get_doubt_friends_add_request returns the mapped list', async () => {
|
it('get_doubt_friends_add_request returns the mapped list', async () => {
|
||||||
const list = [{ uid: 'u1', nick: 'A', source: 's', msg: 'm', reqTime: 123 }];
|
const list = [{
|
||||||
|
uid: 'u1', user_id: 10001, nick: 'A', source: 's', reason: '',
|
||||||
|
msg: 'm', group_code: '', reqTime: 123,
|
||||||
|
}];
|
||||||
const getDoubtRequests = vi.fn(async () => list);
|
const getDoubtRequests = vi.fn(async () => list);
|
||||||
const bridge = fakeBridge({ apis: { friend: { getDoubtRequests } } });
|
const bridge = fakeBridge({ apis: { friend: { getDoubtRequests } } });
|
||||||
const res = await makeHandler(fakeCtx(bridge)).handle('get_doubt_friends_add_request', { count: 5 });
|
const res = await makeHandler(fakeCtx(bridge)).handle('get_doubt_friends_add_request', { count: 5 });
|
||||||
|
|||||||
@@ -411,6 +411,34 @@ describe('buildApiContext setMsgEmojiLike', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('buildApiContext fetchEmojiLikeSummary', () => {
|
||||||
|
it('returns every emoji on the message with cached users', async () => {
|
||||||
|
const listUsers = vi.fn(() => [
|
||||||
|
{ operatorUin: 20002, operatorUid: 'u_20002', setAt: 1_700_000_001 },
|
||||||
|
]);
|
||||||
|
const fetchReactionSummary = vi.fn(async () => [
|
||||||
|
{ emojiId: '76', emojiType: 1, count: 1, lastReactionTime: 1_700_000_001 },
|
||||||
|
]);
|
||||||
|
const { api, metas } = makeRef({
|
||||||
|
reactionStore: { listUsers, summarizeMessage: vi.fn(() => []) },
|
||||||
|
apis: { interaction: { setReaction: vi.fn(), fetchReactionSummary } },
|
||||||
|
});
|
||||||
|
metas.set(-20, groupMeta({ targetId: 710301, sequence: 55 }));
|
||||||
|
|
||||||
|
await expect(api.fetchEmojiLikeSummary(-20)).resolves.toEqual([
|
||||||
|
{
|
||||||
|
emoji_id: '76',
|
||||||
|
emoji_type: 1,
|
||||||
|
count: 1,
|
||||||
|
last_reaction_time: 1_700_000_001,
|
||||||
|
users: [{ user_id: 20002 }],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
expect(fetchReactionSummary).toHaveBeenCalledWith(710301, 55);
|
||||||
|
expect(listUsers).toHaveBeenCalledWith(710301, 55, '76', 1000, 0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('buildApiContext fetchEmojiLikeUsers', () => {
|
describe('buildApiContext fetchEmojiLikeUsers', () => {
|
||||||
it('throws when the message is missing', async () => {
|
it('throws when the message is missing', async () => {
|
||||||
const { api } = makeRef();
|
const { api } = makeRef();
|
||||||
@@ -770,6 +798,12 @@ describe('buildApiContext contact reads', () => {
|
|||||||
long_nick: 'hello sign',
|
long_nick: 'hello sign',
|
||||||
qq_level: 17,
|
qq_level: 17,
|
||||||
level: 17,
|
level: 17,
|
||||||
|
status: 0,
|
||||||
|
extStatus: 0,
|
||||||
|
ext_status: 0,
|
||||||
|
batteryStatus: 0,
|
||||||
|
customStatus: null,
|
||||||
|
customStatusDescInfo: '',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -879,6 +913,8 @@ describe('buildApiContext contact reads', () => {
|
|||||||
request_id: 888,
|
request_id: 888,
|
||||||
requester_uin: 20002,
|
requester_uin: 20002,
|
||||||
requester_nick: 'applicant',
|
requester_nick: 'applicant',
|
||||||
|
invitor_uin: 30003,
|
||||||
|
invitor_nick: 'inviter',
|
||||||
message: 'please add',
|
message: 'please add',
|
||||||
checked: false,
|
checked: false,
|
||||||
flag: 'slreq:1:888:710010:22:0',
|
flag: 'slreq:1:888:710010:22:0',
|
||||||
|
|||||||
@@ -27,11 +27,17 @@ export interface OidbDoubtGetReq {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface OidbDoubtItem {
|
export interface OidbDoubtItem {
|
||||||
uid?: pb<1, string>; // HIGH (kStrTargetUid)
|
uid?: pb<1, string>;
|
||||||
nick?: pb<2, string>; // MEDIUM (generic Nick attr 20002)
|
nick?: pb<2, string>;
|
||||||
source?: pb<5, string>; // MEDIUM
|
age?: pb<3, uint_32>;
|
||||||
reqTime?: pb<9, uint_64>; // HIGH (attr 60001)
|
sex?: pb<4, uint_32>;
|
||||||
msg?: pb<11, string>; // MEDIUM
|
msg?: pb<5, string>;
|
||||||
|
source?: pb<6, string>;
|
||||||
|
reason?: pb<7, string>;
|
||||||
|
uin?: pb<8, uint_64>;
|
||||||
|
reqTime?: pb<9, uint_64>;
|
||||||
|
commFriendNum?: pb<10, uint_32>;
|
||||||
|
groupCode?: pb<11, string>;
|
||||||
}
|
}
|
||||||
export interface OidbDoubtGetRespBody {
|
export interface OidbDoubtGetRespBody {
|
||||||
list?: pb_repeated<1, OidbDoubtItem>;
|
list?: pb_repeated<1, OidbDoubtItem>;
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
// 0x10C0 — fetch pending group-add requests.
|
// 0x10C0 — fetch pending group-add requests.
|
||||||
// subCommand 1 = main inbox, 2 = filtered (low-priority) inbox
|
// subCommand 1 = main inbox, 2 = filtered (low-priority) inbox
|
||||||
//
|
//
|
||||||
// Current QQ uses the UIN-form envelope for its native list path. The server
|
// Current QQ uses the UIN-form envelope for the native list path, but the
|
||||||
// changes user field 1 from a UID string to a numeric UIN when that envelope
|
// per-user record still carries a string account on field 1. Decode both
|
||||||
// bit changes, so the two forms deliberately have separate decoders below.
|
// shapes and merge so neither identifier is dropped. The UID-form request
|
||||||
// The UID form remains necessary for correlating UID-only real-time pushes.
|
// remains necessary for correlating UID-only real-time pushes.
|
||||||
|
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
import type {
|
import type {
|
||||||
OidbBase,
|
OidbBase,
|
||||||
OidbSvcTrpcTcp0x10C0Response,
|
OidbSvcTrpcTcp0x10C0Response,
|
||||||
OidbSvcTrpcTcp0x10C0ResponseByUin,
|
OidbSvcTrpcTcp0x10C0ResponseByUin,
|
||||||
|
OidbSvcTrpcTcp0x10C0ResponseRequest,
|
||||||
|
OidbSvcTrpcTcp0x10C0ResponseRequestByUin,
|
||||||
|
OidbSvcTrpcTcp0x10C0ResponseUser,
|
||||||
|
OidbSvcTrpcTcp0x10C0ResponseUserByUin,
|
||||||
} from '@snowluma/proto-defs/oidb';
|
} from '@snowluma/proto-defs/oidb';
|
||||||
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
||||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
@@ -24,9 +28,92 @@ const GROUP_REQUEST_OPERATION_TYPE = new Map<number, number>([
|
|||||||
[6, 35], [7, 1], [8, 3], [9, 6], [10, 7], [11, 13],
|
[6, 35], [7, 1], [8, 3], [9, 6], [10, 7], [11, 13],
|
||||||
[12, 15], [13, 16], [14, 17], [15, 19], [16, 8], [17, 100],
|
[12, 15], [13, 16], [14, 17], [15, 19], [16, 8], [17, 100],
|
||||||
]);
|
]);
|
||||||
|
const GROUP_REQUEST_OPERATION_OUTPUT = new Set(GROUP_REQUEST_OPERATION_TYPE.values());
|
||||||
|
|
||||||
export function groupRequestOperationType(notifyType: number): number | null {
|
export function groupRequestOperationType(notifyType: number): number | null {
|
||||||
return GROUP_REQUEST_OPERATION_TYPE.get(notifyType) ?? 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 interface DecodedGroupRequestUser {
|
||||||
|
uid: string;
|
||||||
|
uin: number;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DecodedGroupRequest {
|
||||||
|
sequence?: bigint;
|
||||||
|
eventType?: number;
|
||||||
|
state?: number;
|
||||||
|
group?: { groupUin?: number; groupName?: string };
|
||||||
|
target?: DecodedGroupRequestUser;
|
||||||
|
invitor?: DecodedGroupRequestUser;
|
||||||
|
operatorUser?: DecodedGroupRequestUser;
|
||||||
|
comment?: string;
|
||||||
|
operateTransInfo?: Uint8Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DecodedGroupRequestList {
|
||||||
|
requests?: DecodedGroupRequest[];
|
||||||
|
field2?: bigint;
|
||||||
|
newLatestSeq?: bigint;
|
||||||
|
field4?: number;
|
||||||
|
field5?: bigint;
|
||||||
|
field6?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeRequestUser(
|
||||||
|
byUin?: OidbSvcTrpcTcp0x10C0ResponseUserByUin,
|
||||||
|
byUid?: OidbSvcTrpcTcp0x10C0ResponseUser,
|
||||||
|
): DecodedGroupRequestUser {
|
||||||
|
return {
|
||||||
|
uid: byUid?.uid ?? '',
|
||||||
|
uin: byUin?.uin ?? 0,
|
||||||
|
name: (byUin?.name || byUid?.name) ?? '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeRequestItem(
|
||||||
|
byUin?: OidbSvcTrpcTcp0x10C0ResponseRequestByUin,
|
||||||
|
byUid?: OidbSvcTrpcTcp0x10C0ResponseRequest,
|
||||||
|
): DecodedGroupRequest {
|
||||||
|
const src = byUin ?? byUid;
|
||||||
|
return {
|
||||||
|
sequence: src?.sequence,
|
||||||
|
eventType: src?.eventType,
|
||||||
|
state: src?.state,
|
||||||
|
group: src?.group,
|
||||||
|
target: mergeRequestUser(byUin?.target, byUid?.target),
|
||||||
|
invitor: mergeRequestUser(byUin?.invitor, byUid?.invitor),
|
||||||
|
operatorUser: mergeRequestUser(byUin?.operatorUser, byUid?.operatorUser),
|
||||||
|
comment: src?.comment ?? '',
|
||||||
|
operateTransInfo: src?.operateTransInfo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeRequestList(
|
||||||
|
byUin?: OidbSvcTrpcTcp0x10C0ResponseByUin,
|
||||||
|
byUid?: OidbSvcTrpcTcp0x10C0Response,
|
||||||
|
): DecodedGroupRequestList {
|
||||||
|
const src = byUin ?? byUid;
|
||||||
|
const uinItems = byUin?.requests ?? [];
|
||||||
|
const uidItems = byUid?.requests ?? [];
|
||||||
|
const count = Math.max(uinItems.length, uidItems.length);
|
||||||
|
const requests: DecodedGroupRequest[] = [];
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
requests.push(mergeRequestItem(uinItems[i], uidItems[i]));
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
requests,
|
||||||
|
field2: src?.field2,
|
||||||
|
newLatestSeq: src?.newLatestSeq,
|
||||||
|
field4: src?.field4,
|
||||||
|
field5: src?.field5,
|
||||||
|
field6: src?.field6,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace FetchGroupRequests {
|
export namespace FetchGroupRequests {
|
||||||
@@ -51,15 +138,21 @@ export namespace FetchGroupRequests {
|
|||||||
field2: p.cursor ?? 0n,
|
field2: p.cursor ?? 0n,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const deserialize = (_ctx: Deps, body: OidbSvcTrpcTcp0x10C0ResponseByUin): OidbSvcTrpcTcp0x10C0ResponseByUin => body;
|
export const deserialize = (_ctx: Deps, body: DecodedGroupRequestList): DecodedGroupRequestList => body;
|
||||||
|
|
||||||
export const encode = (env: OidbBase<OidbGroupRequestList>): Uint8Array =>
|
export const encode = (env: OidbBase<OidbGroupRequestList>): Uint8Array =>
|
||||||
protobuf_encode<OidbBase<OidbGroupRequestList>>(env);
|
protobuf_encode<OidbBase<OidbGroupRequestList>>(env);
|
||||||
|
|
||||||
export const decode = (bytes: Uint8Array): OidbBase<OidbSvcTrpcTcp0x10C0ResponseByUin> =>
|
export const decode = (bytes: Uint8Array): OidbBase<DecodedGroupRequestList> => {
|
||||||
protobuf_decode<OidbBase<OidbSvcTrpcTcp0x10C0ResponseByUin>>(bytes);
|
const byUin = protobuf_decode<OidbBase<OidbSvcTrpcTcp0x10C0ResponseByUin>>(bytes);
|
||||||
|
const byUid = protobuf_decode<OidbBase<OidbSvcTrpcTcp0x10C0Response>>(bytes);
|
||||||
|
return {
|
||||||
|
...byUin,
|
||||||
|
body: mergeRequestList(byUin.body, byUid.body),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const invoke = (deps: Deps, params: Params): Promise<OidbSvcTrpcTcp0x10C0ResponseByUin> =>
|
export const invoke = (deps: Deps, params: Params): Promise<DecodedGroupRequestList> =>
|
||||||
invokeOidb(deps, FetchGroupRequests, params);
|
invokeOidb(deps, FetchGroupRequests, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,19 +7,31 @@
|
|||||||
// uid (tag1) and reqTime (tag9) are HIGH confidence.
|
// uid (tag1) and reqTime (tag9) are HIGH confidence.
|
||||||
|
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
|
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
|
||||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||||
import type {
|
import type {
|
||||||
OidbDoubtGetReq, OidbDoubtGetResp,
|
OidbDoubtGetReq, OidbDoubtGetResp,
|
||||||
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
} from '@snowluma/proto-defs/oidb-actions/doubt-buddy';
|
||||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||||
|
|
||||||
|
interface OidbDoubtItemAccountOnTag1 {
|
||||||
|
uin?: pb<1, uint_64>;
|
||||||
|
}
|
||||||
|
interface OidbDoubtGetRespAccountOnTag1 {
|
||||||
|
status?: pb<1, uint_32>;
|
||||||
|
body?: pb<2, { list?: pb_repeated<1, OidbDoubtItemAccountOnTag1> }>;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DoubtBuddyRequest {
|
export interface DoubtBuddyRequest {
|
||||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||||
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
|
/** Opaque uid — pass back as `flag` to set_doubt_friends_add_request. */
|
||||||
uid: string;
|
uid: string;
|
||||||
|
user_id: number;
|
||||||
nick: string;
|
nick: string;
|
||||||
source: string;
|
source: string;
|
||||||
|
reason: string;
|
||||||
msg: string;
|
msg: string;
|
||||||
|
group_code: string;
|
||||||
reqTime: number;
|
reqTime: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,17 +51,32 @@ export namespace GetDoubtBuddyReq {
|
|||||||
export const deserialize = (_ctx: Deps, body: OidbDoubtGetResp): DoubtBuddyRequest[] =>
|
export const deserialize = (_ctx: Deps, body: OidbDoubtGetResp): DoubtBuddyRequest[] =>
|
||||||
(body.body?.list ?? []).map((it) => ({
|
(body.body?.list ?? []).map((it) => ({
|
||||||
uid: it.uid ?? '',
|
uid: it.uid ?? '',
|
||||||
|
user_id: Number(it.uin ?? 0),
|
||||||
nick: it.nick ?? '',
|
nick: it.nick ?? '',
|
||||||
source: it.source ?? '',
|
source: it.source ?? '',
|
||||||
|
reason: it.reason ?? '',
|
||||||
msg: it.msg ?? '',
|
msg: it.msg ?? '',
|
||||||
|
group_code: it.groupCode ?? '',
|
||||||
reqTime: Number(it.reqTime ?? 0),
|
reqTime: Number(it.reqTime ?? 0),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
|
export const encode = (env: OidbBase<OidbDoubtGetReq>): Uint8Array =>
|
||||||
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
|
protobuf_encode<OidbBase<OidbDoubtGetReq>>(env);
|
||||||
|
|
||||||
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> =>
|
export const decode = (bytes: Uint8Array): OidbBase<OidbDoubtGetResp> => {
|
||||||
protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
|
const decoded = protobuf_decode<OidbBase<OidbDoubtGetResp>>(bytes);
|
||||||
|
const numeric = protobuf_decode<OidbBase<OidbDoubtGetRespAccountOnTag1>>(bytes);
|
||||||
|
const items = decoded.body?.body?.list ?? [];
|
||||||
|
const numericItems = numeric.body?.body?.list ?? [];
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
const item = items[i];
|
||||||
|
if (!item) continue;
|
||||||
|
if ((item.uin ?? 0n) === 0n && numericItems[i]?.uin) {
|
||||||
|
item.uin = numericItems[i]!.uin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return decoded;
|
||||||
|
};
|
||||||
|
|
||||||
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
|
export const invoke = (deps: Deps, params: Params): Promise<DoubtBuddyRequest[]> =>
|
||||||
invokeOidb(deps, GetDoubtBuddyReq, params);
|
invokeOidb(deps, GetDoubtBuddyReq, params);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { describe, expect, it, vi } from 'vitest';
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
|
||||||
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
|
import type { pb, pb_repeated, uint_32, uint_64 } from '@snowluma/proton';
|
||||||
import type { OidbBase } from '@snowluma/proto-defs/oidb';
|
import type { OidbBase, OidbSvcTrpcTcp0x10C0Response } from '@snowluma/proto-defs/oidb';
|
||||||
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
import type { OidbGroupRequestList } from '@snowluma/proto-defs/oidb-actions/base';
|
||||||
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
import type { SendPacketResult } from '@snowluma/common/packet-sender';
|
||||||
|
|
||||||
@@ -47,6 +47,8 @@ describe('FetchGroupRequests namespace', () => {
|
|||||||
expect(groupRequestOperationType(1)).toBe(2);
|
expect(groupRequestOperationType(1)).toBe(2);
|
||||||
expect(groupRequestOperationType(7)).toBe(1);
|
expect(groupRequestOperationType(7)).toBe(1);
|
||||||
expect(groupRequestOperationType(17)).toBe(100);
|
expect(groupRequestOperationType(17)).toBe(100);
|
||||||
|
expect(groupRequestOperationType(5)).toBe(22);
|
||||||
|
expect(groupRequestOperationType(22)).toBe(22);
|
||||||
expect(groupRequestOperationType(99)).toBeNull();
|
expect(groupRequestOperationType(99)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -135,13 +137,43 @@ describe('FetchGroupRequests namespace', () => {
|
|||||||
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
|
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||||
|
|
||||||
expect(response.requests?.[0]).toMatchObject({
|
expect(response.requests?.[0]).toMatchObject({
|
||||||
target: { uin: 1_234_567_890, name: 'requester' },
|
target: { uin: 1_234_567_890, uid: '', name: 'requester' },
|
||||||
invitor: { uin: 2_345_678_901, name: 'inviter' },
|
invitor: { uin: 2_345_678_901, uid: '', name: 'inviter' },
|
||||||
operatorUser: { uin: 3_456_789_012, name: 'operator' },
|
operatorUser: { uin: 3_456_789_012, uid: '', name: 'operator' },
|
||||||
});
|
});
|
||||||
expect(response.field2).toBe(1_785_406_628_779_279n);
|
expect(response.field2).toBe(1_785_406_628_779_279n);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps string account identifiers from the native reply', async () => {
|
||||||
|
const responseData = Buffer.from(protobuf_encode<OidbBase<OidbSvcTrpcTcp0x10C0Response>>({
|
||||||
|
body: {
|
||||||
|
requests: [{
|
||||||
|
sequence: 99n,
|
||||||
|
eventType: 5,
|
||||||
|
state: 1,
|
||||||
|
group: { groupUin: 1001, groupName: 'group' },
|
||||||
|
target: { uid: 'u_target', name: 'invitee' },
|
||||||
|
invitor: { uid: 'u_inviter', name: 'inviter' },
|
||||||
|
comment: 'join us',
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
const sender = {
|
||||||
|
sendRawPacket: vi.fn(async () => ({
|
||||||
|
success: true, gotResponse: true, errorCode: 0, errorMessage: '', responseData,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await FetchGroupRequests.invoke(sender, { filtered: false });
|
||||||
|
|
||||||
|
expect(response.requests?.[0]).toMatchObject({
|
||||||
|
eventType: 5,
|
||||||
|
target: { uid: 'u_target', uin: 0, name: 'invitee' },
|
||||||
|
invitor: { uid: 'u_inviter', uin: 0, name: 'inviter' },
|
||||||
|
comment: 'join us',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('keeps the UID response path on the non-native envelope', async () => {
|
it('keeps the UID response path on the non-native envelope', async () => {
|
||||||
const sender = makeSender();
|
const sender = makeSender();
|
||||||
await FetchGroupRequestsByUid.invoke(sender, { filtered: false });
|
await FetchGroupRequestsByUid.invoke(sender, { filtered: false });
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ function makeSender(): { sendRawPacket: ReturnType<typeof vi.fn> } {
|
|||||||
const respEnv: OidbBase<OidbDoubtGetResp> = {
|
const respEnv: OidbBase<OidbDoubtGetResp> = {
|
||||||
command: 0xD69, subCommand: 0,
|
command: 0xD69, subCommand: 0,
|
||||||
body: { status: 1, body: { list: [
|
body: { status: 1, body: { list: [
|
||||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000n },
|
{
|
||||||
|
uid: 'u_alice', nick: 'Alice', source: '可能认识', reason: '',
|
||||||
|
msg: 'hi', uin: 12345n, groupCode: '', reqTime: 1700000000n,
|
||||||
|
},
|
||||||
], reason: '' } },
|
], reason: '' } },
|
||||||
};
|
};
|
||||||
const r: SendPacketResult = {
|
const r: SendPacketResult = {
|
||||||
@@ -46,7 +49,10 @@ describe('GetDoubtBuddyReq namespace', () => {
|
|||||||
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
|
it('deserializes the item list to the OneBot shape (uid + reqTime high-confidence)', async () => {
|
||||||
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
|
const list = await GetDoubtBuddyReq.invoke(makeSender(), { count: 10 });
|
||||||
expect(list).toEqual([
|
expect(list).toEqual([
|
||||||
{ uid: 'u_alice', nick: 'Alice', source: '可能认识', msg: 'hi', reqTime: 1700000000 },
|
{
|
||||||
|
uid: 'u_alice', user_id: 12345, nick: 'Alice', source: '可能认识',
|
||||||
|
reason: '', msg: 'hi', group_code: '', reqTime: 1700000000,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user