mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
feat: getForwardedMessages
This commit is contained in:
parent
d0e43472f9
commit
dd360070d7
@ -69,5 +69,32 @@ export class LaanaMessageActionHandler {
|
|||||||
message: await this.laana.utils.msg.rawMessageToLaana(msg),
|
message: await this.laana.utils.msg.rawMessageToLaana(msg),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getForwardedMessages: async (params) => {
|
||||||
|
const { rootMsgLaanaId, currentMsgId } = this.laana.utils.msg.decodeLaanaForwardMsgRefId(params.refId);
|
||||||
|
const decodedRootMsgId = this.laana.utils.msg.decodeLaanaMsgId(rootMsgLaanaId);
|
||||||
|
const rawForwardedMessages = await this.core.apis.MsgApi.getMultiMsg(
|
||||||
|
{
|
||||||
|
chatType: decodedRootMsgId.chatType,
|
||||||
|
peerUid: decodedRootMsgId.peerUid,
|
||||||
|
guildId: '',
|
||||||
|
},
|
||||||
|
decodedRootMsgId.msgId,
|
||||||
|
currentMsgId,
|
||||||
|
);
|
||||||
|
if (!rawForwardedMessages || rawForwardedMessages.result !== 0 || rawForwardedMessages.msgList.length === 0) {
|
||||||
|
throw new Error('获取转发消息失败');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
forwardMessage: {
|
||||||
|
refId: params.refId,
|
||||||
|
messages: await Promise.all(
|
||||||
|
rawForwardedMessages.msgList.map(async msg => {
|
||||||
|
return await this.laana.utils.msg.rawMessageToLaana(msg, rootMsgLaanaId);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -279,8 +279,7 @@ export class LaanaMessageUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async rawMessageToLaana(msg: RawMessage): Promise<LaanaMessage> {
|
async rawMessageToLaana(msg: RawMessage, rootForwardMsgId?: string): Promise<LaanaMessage> {
|
||||||
const msgContent = await this.createLaanaMessageContent(msg);
|
|
||||||
return {
|
return {
|
||||||
msgId: this.encodeMsgToLaanaMsgId(msg.msgId, msg.chatType, msg.peerUid),
|
msgId: this.encodeMsgToLaanaMsgId(msg.msgId, msg.chatType, msg.peerUid),
|
||||||
time: BigInt(msg.msgTime),
|
time: BigInt(msg.msgTime),
|
||||||
@ -290,11 +289,11 @@ export class LaanaMessageUtils {
|
|||||||
type: msg.chatType === ChatType.KCHATTYPEGROUP ?
|
type: msg.chatType === ChatType.KCHATTYPEGROUP ?
|
||||||
Peer_Type.GROUP : Peer_Type.BUDDY,
|
Peer_Type.GROUP : Peer_Type.BUDDY,
|
||||||
},
|
},
|
||||||
content: msgContent,
|
content: await this.createLaanaMessageContent(msg, rootForwardMsgId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createLaanaMessageContent(msg: RawMessage): Promise<LaanaMessage['content']> {
|
private async createLaanaMessageContent(msg: RawMessage, rootForwardMsgId?: string): Promise<LaanaMessage['content']> {
|
||||||
const firstElement = msg.elements[0];
|
const firstElement = msg.elements[0];
|
||||||
|
|
||||||
if (!firstElement) {
|
if (!firstElement) {
|
||||||
@ -481,7 +480,10 @@ export class LaanaMessageUtils {
|
|||||||
return {
|
return {
|
||||||
oneofKind: 'forwardMsgRef',
|
oneofKind: 'forwardMsgRef',
|
||||||
forwardMsgRef: {
|
forwardMsgRef: {
|
||||||
refId: this.encodeMsgToLaanaMsgId(msg.msgId, msg.chatType, msg.peerUid),
|
refId: this.encodeMsgToForwardMsgRefId(
|
||||||
|
rootForwardMsgId ?? this.encodeMsgToLaanaMsgId(msg.msgId, msg.chatType, msg.peerUid),
|
||||||
|
msg.msgId,
|
||||||
|
),
|
||||||
displayText: firstElement.multiForwardMsgElement.xmlContent,
|
displayText: firstElement.multiForwardMsgElement.xmlContent,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -509,6 +511,9 @@ export class LaanaMessageUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
decodeLaanaMsgId(laanaMsgId: string) {
|
decodeLaanaMsgId(laanaMsgId: string) {
|
||||||
|
if (!laanaMsgId.startsWith('LaanaMsgId@')) {
|
||||||
|
throw Error('不合法的 LaanaMsgId');
|
||||||
|
}
|
||||||
const [msgId, chatType, peerUid] = laanaMsgId.split('@').slice(1);
|
const [msgId, chatType, peerUid] = laanaMsgId.split('@').slice(1);
|
||||||
return {
|
return {
|
||||||
msgId,
|
msgId,
|
||||||
@ -517,6 +522,24 @@ export class LaanaMessageUtils {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
encodeMsgToForwardMsgRefId(
|
||||||
|
rootMsgLaanaId: string,
|
||||||
|
currentMsgId: string,
|
||||||
|
) {
|
||||||
|
return `LaanaForwardMsgRefId|${rootMsgLaanaId}|${currentMsgId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
decodeLaanaForwardMsgRefId(laanaForwardMsgId: string) {
|
||||||
|
if (!laanaForwardMsgId.startsWith('LaanaForwardMsgRefId|')) {
|
||||||
|
throw Error('不合法的 LaanaForwardMsgRefId');
|
||||||
|
}
|
||||||
|
const [rootMsgLaanaId, currentMsgId] = laanaForwardMsgId.split('|').slice(1);
|
||||||
|
return {
|
||||||
|
rootMsgLaanaId,
|
||||||
|
currentMsgId,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async getRepliedMsgId(element: ReplyElement, msg: RawMessage) {
|
async getRepliedMsgId(element: ReplyElement, msg: RawMessage) {
|
||||||
const record = msg.records.find(
|
const record = msg.records.find(
|
||||||
msgRecord => msgRecord.msgId === element.sourceMsgIdInRecords
|
msgRecord => msgRecord.msgId === element.sourceMsgIdInRecords
|
||||||
|
Loading…
x
Reference in New Issue
Block a user