fix(core): write album comments with the official header fields

The comment packet header only needs the feed time and id. Extra locator fields from the feed cell are not part of the official write.

Refs #436
This commit is contained in:
DrSmoothl committed 2026-09-21 14:13:16 +08:00
1 parent dad2b0c5a7
commit 1dffb22d05
3 files changed
+11 -38

No files matched your search

+5 -10
View File
@@ -2,6 +2,7 @@ import type { JsonObject, JsonValue } from '@snowluma/common/json';
import { createLogger } from '@snowluma/common/logger';
import type {
AlbumCreator,
CommentReqBodyHeader,
CommentReqPhotoInfo,
CommentRespData,
DeleteMediasRequest,
@@ -344,7 +345,7 @@ export class GroupAlbumApi {
groupId: groupId.toString(),
field3: 2,
reqBody: {
field1: commentReqHeader(feed.cellCommon, groupId, albumId, batchId, mediaLloc),
field1: commentReqHeader(feed.cellCommon),
...(ownerUin ? { field2: { field1: { uin: ownerUin } } } : {}),
field5: photoInfo,
},
@@ -693,16 +694,10 @@ function qunFeedCellId(
return `${head}^||^421_1_0_${groupId}|${albumId}|${lloc}^||^0`;
}
function commentReqHeader(
cell: QunFeedCellCommon,
groupId: number,
albumId: string,
batchId: bigint,
lloc: string,
): QunFeedCellCommon {
function commentReqHeader(cell: QunFeedCellCommon): CommentReqBodyHeader {
return {
...cell,
cellId: cell.cellId || qunFeedCellId(groupId, albumId, batchId, lloc),
...(cell.time !== undefined ? { time: cell.time } : {}),
...(cell.feedId ? { feedId: cell.feedId } : {}),
};
}
@@ -704,11 +704,8 @@ describe('apis/group-album', () => {
field3: 2,
reqBody: {
field1: {
type: 422,
time: 1700000123n,
feedId: 'official-feed-id',
cellId: '421_1_0_12345|album-id|77^||^421_1_0_12345|album-id|photo-lloc^||^0',
field6: 3,
},
field2: { field1: { uin: '3119936551' } },
field5: {
@@ -777,7 +774,7 @@ describe('apis/group-album', () => {
});
});
it('copies the official feed cell_common locator into the comment header', async () => {
it('writes only the official comment header fields even when the feed cell has extra locator data', async () => {
const cellId = '421_1_0_964445447|album-id|2147483665^||^421_1_0_964445447|album-id|photo-lloc^||^0';
const bridge = mockBridge();
bridge.sendRawPacket.mockImplementation(commentMocks((cmd) => {
@@ -792,31 +789,13 @@ describe('apis/group-album', () => {
await new GroupAlbumApi(bridge as never).comment(964445447, 'album-id', 'photo-lloc', 'hello');
expect(commentRequestOf(bridge).body?.reqBody?.field1).toEqual({
type: 422,
expect(commentRequestOf(bridge).body?.reqBody?.field1).toMatchObject({
time: 1789315793n,
feedId: '422_0_2147483665',
cellId,
field6: 3,
});
});
it('synthesizes the 421 locator when the official feed omits cell_common field 5', async () => {
const bridge = mockBridge();
bridge.sendRawPacket.mockImplementation(commentMocks((cmd) => {
if (cmd.endsWith('GetQunFeedDetail')) {
return packFeedDetail('422_0_77', 1700000123n, { ownerUin: '3119936551' });
}
return undefined;
}));
await new GroupAlbumApi(bridge as never).comment(12345, 'album-id', 'photo-lloc', 'hello');
expect(commentRequestOf(bridge).body?.reqBody?.field1).toMatchObject({
time: 1700000123n,
feedId: '422_0_77',
cellId: '421_1_0_12345|album-id|77^||^421_1_0_12345|album-id|photo-lloc^||^0',
});
expect(commentRequestOf(bridge).body?.reqBody?.field1?.type ?? 0).toBe(0);
expect(commentRequestOf(bridge).body?.reqBody?.field1?.cellId ?? '').toBe('');
expect(commentRequestOf(bridge).body?.reqBody?.field1?.field6 ?? 0).toBe(0);
});
it('comments a video with the cover location and video media type', async () => {
@@ -160,8 +160,7 @@ export interface CommentReqPhotoInfo {
batchId?: pb<5, uint_64>;
}
export interface CommentReqBodyHeader {
// Official feed cell_common: type 422, time, short feed id, composite
// 421_1_0 locator, and field 6 = 3. DoQunComment copies this cell.
// FeedWorker encode writes only time and feed id into this cell.
type?: pb<1, uint_32>;
time?: pb<3, uint_64>;
feedId?: pb<4, string>;