fix:Fix the issue where quoting a message in replies was ineffective

Previous behavior:
Replies visually displayed a quote block, but the quoted content was blank or invalid, and clicking to jump to the original message also failed.

Fixed behavior:
The quote now correctly references the original message, displaying its actual content and enabling a functional jump to the quoted message.
This commit is contained in:
venti1112 committed 2026-05-06 15:53:11 +08:00
1 parent 4a92292e49
commit de7533ca81
8 files changed
+407 -27

No files matched your search

+100 -5
View File
@@ -1,5 +1,5 @@
import type { Bridge } from '../bridge/bridge';
import type { ForwardNodePayload } from '../bridge/events';
import type { ForwardNodePayload, MessageElement } from '../bridge/events';
import type { QQInfo } from '../bridge/qq-info';
import type { ApiActionContext, MessageSendResult } from './api-handler';
import { elementsToOneBotSegments } from './event-converter';
@@ -7,6 +7,9 @@ import { MessageStore } from './message-store';
import { parseMessage } from './message-parser';
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT, hashMessageIdInt32 } from './message-id';
import type { JsonObject, JsonValue, MessageMeta } from './types';
import { createLogger } from '../utils/logger';
const log = createLogger('OneBot');
export interface InstanceRef {
uin: string;
@@ -412,6 +415,68 @@ async function handleSetEssence(bridge: Bridge, messageStore: MessageStore, mess
await bridge.setGroupEssence(meta.targetId, meta.sequence, meta.random, enable);
}
// --- Send message logging ---
function logSentMessage(isGroup: boolean, targetId: number, elements: MessageElement[]): void {
const type = isGroup ? '群聊' : '私聊';
const parts: string[] = [];
// Check for reply element
const replyElem = elements.find(e => e.type === 'reply');
if (replyElem && replyElem.replyMessageId) {
parts.push(`[回复:${replyElem.replyMessageId}]`);
}
// Build message content preview
for (const elem of elements) {
if (elem.type === 'reply') continue; // Already handled
switch (elem.type) {
case 'text':
if (elem.text) {
const preview = elem.text.length > 50 ? elem.text.substring(0, 50) + '...' : elem.text;
parts.push(preview);
}
break;
case 'image':
parts.push('[图片]');
break;
case 'face':
parts.push('[表情]');
break;
case 'at':
if (elem.text) parts.push(elem.text.trim());
break;
case 'record':
parts.push('[语音]');
break;
case 'video':
parts.push('[视频]');
break;
case 'json':
parts.push('[JSON消息]');
break;
case 'xml':
parts.push('[XML消息]');
break;
case 'markdown':
parts.push('[Markdown]');
break;
case 'forward':
parts.push('[转发消息]');
break;
case 'poke':
parts.push('[戳一戳]');
break;
default:
break;
}
}
const content = parts.join(' ').trim() || '[空消息]';
log.info(`${type} ${targetId} | 发送:${content}`);
}
// --- Send message ---
async function handleSendPrivate(
@@ -421,8 +486,20 @@ async function handleSendPrivate(
autoEscape: boolean,
): Promise<MessageSendResult> {
const elements = await parseMessage(message, autoEscape, {
resolveReplySequence: (replyMessageId) =>
ref.messageStore.resolveReplySequence(false, userId, replyMessageId),
resolveReplySequence: (replyMessageId) => {
return ref.messageStore.resolveReplySequence(false, userId, replyMessageId);
},
resolveReplyMeta: (replyMessageId) => {
const meta = ref.messageStore.findMeta(replyMessageId);
if (meta) {
return {
senderUin: meta.targetId, // For received messages, targetId is the sender
time: meta.timestamp,
random: meta.random,
};
}
return null;
},
musicSignUrl: ref.musicSignUrl,
});
if (elements.length === 0) throw new Error('message is empty');
@@ -430,6 +507,9 @@ async function handleSendPrivate(
const receipt = await ref.bridge.sendPrivateMessage(userId, elements);
const messageId = hashMessageIdInt32(receipt.sequence, userId, PRIVATE_MESSAGE_EVENT);
// Log sent message
logSentMessage(false, userId, elements);
// Cache the sent message meta
ref.cacheMessageMeta(messageId, {
isGroup: false,
@@ -451,8 +531,20 @@ async function handleSendGroup(
autoEscape: boolean,
): Promise<MessageSendResult> {
const elements = await parseMessage(message, autoEscape, {
resolveReplySequence: (replyMessageId) =>
ref.messageStore.resolveReplySequence(true, groupId, replyMessageId),
resolveReplySequence: (replyMessageId) => {
return ref.messageStore.resolveReplySequence(true, groupId, replyMessageId);
},
resolveReplyMeta: (replyMessageId) => {
const event = ref.messageStore.findEvent(replyMessageId);
if (event) {
return {
senderUin: typeof event.user_id === 'number' ? event.user_id : parseInt(String(event.user_id || '0'), 10),
time: typeof event.time === 'number' ? event.time : parseInt(String(event.time || '0'), 10),
random: 0, // Group messages might not have random field in event
};
}
return null;
},
musicSignUrl: ref.musicSignUrl,
});
if (elements.length === 0) throw new Error('message is empty');
@@ -460,6 +552,9 @@ async function handleSendGroup(
const receipt = await ref.bridge.sendGroupMessage(groupId, elements);
const messageId = hashMessageIdInt32(receipt.sequence, groupId, GROUP_MESSAGE_EVENT);
// Log sent message
logSentMessage(true, groupId, elements);
// Cache the sent message meta
ref.cacheMessageMeta(messageId, {
isGroup: true,