fix(protocol): support image replies in existing temp sessions

Allow image replies in existing group temporary conversations while preserving passive-only restrictions. Missing, expired, or mismatched sessions remain rejected before media processing, and sending never creates or refreshes a session.

Fixes #471
This commit is contained in:
DrSmoothl committed 2026-09-26 16:30:54 +08:00
1 parent ad360c8eba
commit 1914880df4
11 files changed
+210 -30

No files matched your search

+7 -1
View File
@@ -27,6 +27,8 @@ export interface SendContext {
bridge: BridgeContext;
groupId?: number;
userUid?: string;
/** Source group of an already authorized passive temp-session reply. */
tempGroupId?: number;
/** Explicit transport scene used by scene-limited message elements. */
scene?: OutboundMessageScene;
/**
@@ -386,7 +388,11 @@ async function makeImageElem(ctx: SendContext, element: MessageElement): Promise
throw new Error('private image target uid is missing');
}
const msgInfo = await uploadImageMsgInfo(ctx.bridge, isGroup, targetIdOrUid, element);
const tempGroupId = ctx.scene === 'group-temp' ? ctx.tempGroupId : undefined;
if (ctx.scene === 'group-temp' && tempGroupId === undefined) {
throw new Error('temp-session image source group is missing');
}
const msgInfo = await uploadImageMsgInfo(ctx.bridge, isGroup, targetIdOrUid, element, tempGroupId);
const nt: ProtoElem = {
commonElem: {
serviceType: 48,
@@ -116,6 +116,7 @@ export async function uploadImageMsgInfo(
isGroup: boolean,
targetIdOrUid: string | number,
element: MessageElement,
tempGroupId?: number,
): Promise<Uint8Array> {
const log = loggerFor(bridge);
const image = await loadImage(element);
@@ -128,11 +129,12 @@ export async function uploadImageMsgInfo(
subType: image.subType, summary: image.summary,
}) }),
};
log.debug('uploading %d bytes md5=%s... → %s %s',
log.debug('uploading %d bytes md5=%s... → %s %s%s',
image.fileSize,
image.md5Hex.slice(0, 8),
isGroup ? 'group' : 'c2c',
String(targetIdOrUid));
isGroup ? 'group' : tempGroupId !== undefined ? 'group-temp' : 'c2c',
String(targetIdOrUid),
tempGroupId !== undefined ? ` sourceGroup=${tempGroupId}` : '');
const uploads: MediaSubFileUpload[] = [{
source: 'top',
@@ -147,6 +149,7 @@ export async function uploadImageMsgInfo(
bridge,
isGroup,
targetIdOrUid,
tempGroupId,
oidbCmd: isGroup ? 0x11C4 : 0x11C5,
serviceCmd: isGroup ? 'OidbSvcTrpcTcp.0x11c4_100' : 'OidbSvcTrpcTcp.0x11c5_100',
requestId: 1,
+6 -2
View File
@@ -66,6 +66,8 @@ export interface NtV2UploadParams {
isGroup: boolean;
/** Group uin when isGroup, otherwise the recipient's uid string. */
targetIdOrUid: string | number;
/** Existing passive group temp session; never creates or refreshes a session. */
tempGroupId?: number;
/** OIDB command id (e.g. 0x11C4 / 0x11C5 / 0x126E / 0x126D / 0x11EA / 0x11E9). */
oidbCmd: number;
/** Service cmd (e.g. 'OidbSvcTrpcTcp.0x11c4_100'). */
@@ -147,10 +149,11 @@ export function runNtv2Upload(params: NtV2UploadParams): Promise<NTV2UploadRespB
let didPut = false;
return runWithTraceRequest(async () => {
moduleLog.trace(() => [
'highway_media_start label=%j scope=%s target=%j oidbCmd=%d serviceCmd=%j requestId=%d businessType=%d uploads=%s',
'highway_media_start label=%j scope=%s target=%j sourceGroup=%s oidbCmd=%d serviceCmd=%j requestId=%d businessType=%d uploads=%s',
label,
params.isGroup ? 'group' : 'private',
params.isGroup ? 'group' : params.tempGroupId !== undefined ? 'group-temp' : 'private',
String(params.targetIdOrUid),
params.tempGroupId === undefined ? '-' : String(params.tempGroupId),
params.oidbCmd,
params.serviceCmd,
params.requestId,
@@ -209,6 +212,7 @@ async function runNtv2UploadOperation(
oidbCmd,
isGroup,
targetIdOrUid,
tempGroupId: params.tempGroupId,
requestId: params.requestId,
businessType: params.businessType,
uploadInfo: params.uploadInfo,
@@ -1,5 +1,6 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { RoutingHead } from '@snowluma/proto-defs/action';
import type {
NTV2ExtBizInfo,
NTV2UploadInfo,
@@ -23,6 +24,7 @@ export namespace Ntv2UploadRequest {
oidbCmd: number;
isGroup: boolean;
targetIdOrUid: string | number;
tempGroupId?: number;
requestId: number;
businessType: number;
uploadInfo: NTV2UploadInfo[];
@@ -37,30 +39,42 @@ export namespace Ntv2UploadRequest {
export const resolveCommand = (params: Params): number => params.oidbCmd;
export const serialize = (_ctx: Deps, params: Params): NTV2UploadRichMediaReq => ({
reqHead: {
common: { requestId: params.requestId, command: 100 },
scene: {
requestType: 2,
businessType: params.businessType,
sceneType: params.isGroup ? 2 : 1,
...(params.isGroup
? { group: { groupUin: Number(params.targetIdOrUid) } }
: { c2c: { accountType: 2, targetUid: String(params.targetIdOrUid) } }),
export const serialize = (_ctx: Deps, params: Params): NTV2UploadRichMediaReq => {
let routingHead: Uint8Array | undefined;
if (params.tempGroupId !== undefined) {
if (params.isGroup || !Number.isSafeInteger(params.tempGroupId) || params.tempGroupId <= 0
|| typeof params.targetIdOrUid !== 'string' || !params.targetIdOrUid.trim()) {
throw new Error('invalid temp-session image upload context');
}
routingHead = protobuf_encode<RoutingHead>({
grpTmp: { groupUin: BigInt(params.tempGroupId), toUid: params.targetIdOrUid },
});
}
return {
reqHead: {
common: { requestId: params.requestId, command: 100 },
scene: {
requestType: 2,
businessType: params.businessType,
sceneType: params.isGroup ? 2 : 1,
...(params.isGroup
? { group: { groupUin: Number(params.targetIdOrUid) } }
: { c2c: { accountType: 2, targetUid: String(params.targetIdOrUid), routingHead } }),
},
client: { agentType: 2 },
},
client: { agentType: 2 },
},
upload: {
uploadInfo: params.uploadInfo,
tryFastUploadCompleted: params.tryFast,
srvSendMsg: false,
clientRandomId: params.clientRandomId,
compatQmsgSceneType: params.compatQmsgSceneType,
extBizInfo: params.extBizInfo,
clientSeq: 0,
noNeedCompatMsg: false,
},
});
upload: {
uploadInfo: params.uploadInfo,
tryFastUploadCompleted: params.tryFast,
srvSendMsg: false,
clientRandomId: params.clientRandomId,
compatQmsgSceneType: params.compatQmsgSceneType,
extBizInfo: params.extBizInfo,
clientSeq: 0,
noNeedCompatMsg: false,
},
};
};
export const deserializeUpload = (body: NTV2UploadRichMediaResp, label = 'media'): NTV2UploadRespBody => {
if (!body) throw new Error(`${label} upload response body missing`);