Skip to content

Commit

Permalink
feat: 查看嵌套转发消息记录
Browse files Browse the repository at this point in the history
  • Loading branch information
clansty committed Sep 17, 2024
1 parent 5a20205 commit a824aa5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions main/src/api/q2tgServlet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>();

Expand All @@ -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(() => {
Expand Down
4 changes: 2 additions & 2 deletions main/src/client/QQClient/entity.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -70,6 +70,6 @@ export interface ForwardMessage {
group_id?: number;
time: number;
seq: number;
message: SendableElem[];
message: MessageElem[];
raw_message: string;
}
24 changes: 24 additions & 0 deletions main/src/utils/processNestedForward.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
}
11 changes: 11 additions & 0 deletions ui/src/views/ChatRecord/Viewer/components/JsonElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ 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: {
json: { required: true, type: String },
},
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 <div class="c-blue-5 cursor-pointer" onClick={() => openForward(jsonObj.value.uuid)}>[嵌套合并转发消息]</div>;
}
if (jsonObj.value.app === 'com.tencent.mannounce') {
try {
const title = atob(jsonObj.value.meta.mannounce.title);
Expand Down

0 comments on commit a824aa5

Please sign in to comment.