fix(friend): verify and synchronize remark updates

Validate the service result before reporting friend remark changes as successful. Rejected, incomplete, or contradictory confirmations now reach callers instead of being reported as completed.

Keep confirmed remarks synchronized in the identity cache and consume cross-client remark updates without exposing a new OneBot event. Local cache failures remain observable without turning an already completed remote change into a retryable failure.

Preserve friend remarks exactly across restarts and add request, response, persistence, receive-pipeline, and action-level regression coverage.

Fixes #303.
This commit is contained in:
DrSmoothl committed 2026-07-31 23:21:05 +08:00
1 parent b8ccbdbf18
commit 659e0bd3d0
17 files changed
+511 -18

No files matched your search

@@ -10,6 +10,7 @@ import type {
} from '../../events';
import type {
FriendRecall,
FriendRemarkChangedNotify,
FriendRequest,
GeneralGrayTipInfo,
InputStatusNotify,
@@ -46,6 +47,7 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
case Event0x210SubType.FriendPokeNotice: return decodeFriendPoke(ctx);
case Event0x210SubType.InputStatusNotice: return decodeInputStatus(ctx);
case Event0x210SubType.OnlineDevicesNotice: return decodeOnlineDevices(ctx);
case Event0x210SubType.FriendRemarkChangedNotice: return decodeFriendRemarkChanged(ctx);
case Event0x210SubType.ProfileLikeNotice: return decodeProfileLike(ctx);
// 179 + 226 both carry the NewFriend payload — see enum comment.
case Event0x210SubType.NewFriendNotice:
@@ -70,6 +72,32 @@ export const decodeEvent0x210: MsgPushDecoder = (ctx) => {
return [];
};
function decodeFriendRemarkChanged(ctx: MsgPushContext): QQEventVariant[] {
const notify = protobuf_decode<FriendRemarkChangedNotify>(ctx.content);
const change = notify?.change;
const uid = change?.target?.uid?.trim() ?? '';
const rawUin = change?.target?.uin;
const uin = rawUin === undefined ? 0 : Number(rawUin);
if (rawUin !== undefined && (!Number.isSafeInteger(uin) || uin <= 0)) {
throw new Error(`friend remark synchronization has invalid UIN ${rawUin}`);
}
if (!uid && uin <= 0) {
throw new Error('friend remark synchronization is missing both UID and UIN');
}
if (change?.remark === undefined) {
throw new Error(`friend remark synchronization is missing the remark value (uid=${uid} uin=${uin})`);
}
if (ctx.isHistorical) return [];
return [{
kind: 'friend_remark_changed',
time: ctx.head.timestamp,
selfUin: ctx.selfUin,
userUid: uid,
userUin: uin,
remark: change.remark,
}];
}
const COMPUTER_CLIENT_TYPES = new Set([1, 5, 15]);
const PHONE_CLIENT_TYPES = new Set([2, 3, 4, 6, 7, 12]);
const PAD_CLIENT_TYPES = new Set([8, 9, 10, 11, 13]);
+2
View File
@@ -90,6 +90,8 @@ export enum Event0x210SubType {
* does not issue a separate network request.
*/
OnlineDevicesNotice = 349,
/** Server-authoritative friend/stranger remark synchronization push. */
FriendRemarkChangedNotice = 364,
/**
* Group-app state push (troop shortcut bar / discussion app).
*