From a824aa54ea86e61bb5fb467f09a43585452128b1 Mon Sep 17 00:00:00 2001 From: Clansty Date: Wed, 18 Sep 2024 07:41:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9F=A5=E7=9C=8B=E5=B5=8C=E5=A5=97?= =?UTF-8?q?=E8=BD=AC=E5=8F=91=E6=B6=88=E6=81=AF=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/src/api/q2tgServlet/index.ts | 2 ++ main/src/client/QQClient/entity.ts | 4 ++-- main/src/utils/processNestedForward.ts | 24 +++++++++++++++++++ .../Viewer/components/JsonElement.tsx | 11 +++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 main/src/utils/processNestedForward.ts diff --git a/main/src/api/q2tgServlet/index.ts b/main/src/api/q2tgServlet/index.ts index 8e34e0a..a1e1d7a 100644 --- a/main/src/api/q2tgServlet/index.ts +++ b/main/src/api/q2tgServlet/index.ts @@ -2,6 +2,7 @@ import { Elysia, t } from 'elysia'; import db from '../../models/db'; import { Pair } from '../../models/Pair'; import OicqClient from '../../client/OicqClient'; +import processNestedForward from '../../utils/processNestedForward'; const forwardCache = new Map(); @@ -18,6 +19,7 @@ let app = new Elysia() if (pair.qqClient instanceof OicqClient) { await pair.qqClient.refreshImageRKey(messages); } + await processNestedForward(messages, data.fromPairId); forwardCache.set(uuid, messages); setTimeout(() => { diff --git a/main/src/client/QQClient/entity.ts b/main/src/client/QQClient/entity.ts index bf55829..7d719d3 100644 --- a/main/src/client/QQClient/entity.ts +++ b/main/src/client/QQClient/entity.ts @@ -1,4 +1,4 @@ -import type { MessageRet, MfaceElem, Quotable } from '@icqqjs/icqq'; +import type { MessageElem, MessageRet, MfaceElem, Quotable } from '@icqqjs/icqq'; import { Gender, GroupRole } from '@icqqjs/icqq/lib/common'; import { AtElem, FaceElem, ImageElem, PttElem, TextElem, VideoElem } from '@icqqjs/icqq/lib/message/elements'; @@ -70,6 +70,6 @@ export interface ForwardMessage { group_id?: number; time: number; seq: number; - message: SendableElem[]; + message: MessageElem[]; raw_message: string; } diff --git a/main/src/utils/processNestedForward.ts b/main/src/utils/processNestedForward.ts new file mode 100644 index 0000000..a70c4d0 --- /dev/null +++ b/main/src/utils/processNestedForward.ts @@ -0,0 +1,24 @@ +import { ForwardMessage } from '../client/QQClient'; +import forwardHelper from '../helpers/forwardHelper'; +import db from '../models/db'; + +export default async (messages: ForwardMessage[], fromPairId: number) => { + for (const message of messages) { + for (const elem of message.message) { + if (elem.type !== 'json') continue; + const parsed = forwardHelper.processJson(elem.data); + if (parsed.type !== 'forward') continue; + let entity = await db.forwardMultiple.findFirst({ where: { resId: parsed.resId } }); + if (!entity) { + entity = await db.forwardMultiple.create({ + data: { + resId: parsed.resId, + fileName: parsed.fileName, + fromPairId, + }, + }); + } + elem.data = JSON.stringify({ type: 'forward', uuid: entity.id }); + } + } +} diff --git a/ui/src/views/ChatRecord/Viewer/components/JsonElement.tsx b/ui/src/views/ChatRecord/Viewer/components/JsonElement.tsx index 538b5c4..231f1e1 100644 --- a/ui/src/views/ChatRecord/Viewer/components/JsonElement.tsx +++ b/ui/src/views/ChatRecord/Viewer/components/JsonElement.tsx @@ -2,6 +2,7 @@ import { computed, defineComponent } from 'vue'; import type BilibiliMiniApp from '../types/BilibiliMiniApp'; import type StructMessageCard from '../types/StructMessageCard'; import { NSpace } from 'naive-ui'; +import { useBrowserLocation } from '@vueuse/core'; export default defineComponent({ props: { @@ -9,8 +10,18 @@ export default defineComponent({ }, setup(props) { const jsonObj = computed(() => JSON.parse(props.json)); + const location = useBrowserLocation(); + + const openForward = (uuid: string) => { + const params = new URLSearchParams(location.value.search); + params.set('tgWebAppStartParam', uuid); + location.value.search = params.toString(); + }; return () => { + if (jsonObj.value.type === 'forward') { + return
openForward(jsonObj.value.uuid)}>[嵌套合并转发消息]
; + } if (jsonObj.value.app === 'com.tencent.mannounce') { try { const title = atob(jsonObj.value.meta.mannounce.title);