fix(core): resolve missing doubt-friend account ids before handle
Linux list replies often omit the id that the handle packet requires, and a cache-only lookup cannot see filtered applicants. Fixes #457
This commit is contained in:
4 files changed
+159
-10
No files matched your search
@@ -58,26 +58,53 @@ export class FriendApi {
|
||||
/** List doubtful friend-add requests (可能认识的人). */
|
||||
async getDoubtRequests(count: number): Promise<DoubtBuddyRequest[]> {
|
||||
const list = await GetDoubtBuddyReq.invoke(this.ctx, { count });
|
||||
return list.map((item) => {
|
||||
return Promise.all(list.map(async (item) => {
|
||||
let uid = item.uid;
|
||||
let userId = item.user_id;
|
||||
if (userId <= 0 && uid) {
|
||||
userId = this.ctx.identity.findUinByUid(uid) ?? 0;
|
||||
}
|
||||
// Current Linux replies often omit the account id even though the
|
||||
// official decoder still reads it as a string. The approval packet
|
||||
// cannot accept a raw number, so fill from the same uin→uid path
|
||||
// used by ordinary friend requests. Cache-only lookup is not
|
||||
// enough: filtered applicants are not friends or group members.
|
||||
if (!uid && userId > 0) {
|
||||
uid = this.ctx.identity.findUidByUin(userId) ?? '';
|
||||
try {
|
||||
uid = await this.ctx.resolveUserUid(userId);
|
||||
} catch (err: unknown) {
|
||||
log.warn(
|
||||
'doubt-request uid resolve failed: user=%d err=%s',
|
||||
userId,
|
||||
err instanceof Error ? err.message : String(err),
|
||||
);
|
||||
}
|
||||
}
|
||||
return { ...item, uid, user_id: userId };
|
||||
return { ...item, uid: uid || '', user_id: userId };
|
||||
}));
|
||||
}
|
||||
|
||||
/** Approve a doubtful friend-add request. `uidOrFlag` is the list uid, or a digit-only account number. */
|
||||
async approveDoubtRequest(uidOrFlag: string): Promise<void> {
|
||||
return ApproveDoubtBuddyReq.invoke(this.ctx, {
|
||||
uid: await this.resolveDoubtFlag(uidOrFlag),
|
||||
});
|
||||
}
|
||||
|
||||
/** Approve a doubtful friend-add request by its uid (the list item's flag). */
|
||||
approveDoubtRequest(uid: string): Promise<void> {
|
||||
return ApproveDoubtBuddyReq.invoke(this.ctx, { uid });
|
||||
/** Reject (delete/decline) a doubtful friend-add request. `uidOrFlag` matches `approveDoubtRequest`. */
|
||||
async rejectDoubtRequest(uidOrFlag: string): Promise<void> {
|
||||
return RejectDoubtBuddyReq.invoke(this.ctx, {
|
||||
uid: await this.resolveDoubtFlag(uidOrFlag),
|
||||
});
|
||||
}
|
||||
|
||||
/** Reject (delete/decline) a doubtful friend-add request by its uid. */
|
||||
rejectDoubtRequest(uid: string): Promise<void> {
|
||||
return RejectDoubtBuddyReq.invoke(this.ctx, { uid });
|
||||
/**
|
||||
* Digit-only flags are account numbers and must be translated before the
|
||||
* approval/reject packet is built. A raw number in that packet is rejected
|
||||
* by the server. Same rule as inbound friend-request handling.
|
||||
*/
|
||||
private resolveDoubtFlag(uidOrFlag: string): Promise<string> {
|
||||
if (!/^\d+$/.test(uidOrFlag)) return Promise.resolve(uidOrFlag);
|
||||
return this.ctx.resolveUserUid(parseInt(uidOrFlag, 10));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user