From 7ee8baa3116b3c9f5f6ae0d4b848be8a9fc03b47 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sat, 5 Apr 2025 03:41:52 +0800 Subject: [PATCH] extract messageForSaveFilter --- packages/ui/src/common/utils/chat-list.ts | 9 +++++++++ packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts | 12 ++---------- .../main/flow/READ_NO_REPLY_AUTO_REMINDER/index.ts | 12 ++---------- 3 files changed, 13 insertions(+), 20 deletions(-) create mode 100644 packages/ui/src/common/utils/chat-list.ts diff --git a/packages/ui/src/common/utils/chat-list.ts b/packages/ui/src/common/utils/chat-list.ts new file mode 100644 index 0000000..4691af3 --- /dev/null +++ b/packages/ui/src/common/utils/chat-list.ts @@ -0,0 +1,9 @@ +export function messageForSaveFilter(it) { + return ( + it.status !== 3 && // filter system notification out + it.templateId === 1 && // filter system notification out + ((['text', 'sticker', 'image', 'sound', 'comDesc'].includes(it.messageType) && + !it.extend?.greetingQuestionAnswer) || // include those message, filter out auto ask + (it.messageType === 'dialog' && [0, 1, 2, 8, 11, 12, 14, 17, 33].includes(it?.dialog?.type))) // include message like resume, phone, map, etc., filter out auto ask + ) +} diff --git a/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts b/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts index 19858ae..ff97e1c 100644 --- a/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts +++ b/packages/ui/src/main/flow/LAUNCH_BOSS_SITE/index.ts @@ -29,6 +29,7 @@ import gtag from '../../utils/gtag' import attachListenerForKillSelfOnParentExited from '../../utils/attachListenerForKillSelfOnParentExited' import { type ChatMessageRecord } from '@geekgeekrun/sqlite-plugin/src/entity/ChatMessageRecord' import { BossInfo } from '@geekgeekrun/sqlite-plugin/dist/entity/BossInfo' +import { messageForSaveFilter } from '../../../common/utils/chat-list' const __dirname = url.fileURLToPath(new URL('.', import.meta.url)) const isRunFromUi = Boolean(process.env.MAIN_BOSSGEEKGO_UI_RUN_MODE) @@ -213,16 +214,7 @@ const attachRequestsListener = async (target: Target) => { await page.evaluate( 'document.querySelector(".message-content .chat-record").__vue__.list$' ) - )?.filter((it) => { - return ( - it.status !== 3 && // filter system notification out - it.templateId === 1 && // filter system notification out - ( - (['text', 'sticker', 'image', 'sound', 'comDesc'].includes(it.messageType) && !it.extend?.greetingQuestionAnswer) // include those message, filter out auto ask - || (it.messageType === 'dialog' && [0, 1, 2, 8, 11, 12, 14, 17, 33].includes(it?.dialog?.type)) // include message like resume, phone, map, etc., filter out auto ask - ) - ) - }) ?? [] + )?.filter(messageForSaveFilter) ?? [] const chatRecordList = rawChatRecordList.map(it => { const mappedItem = {} as InstanceType diff --git a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/index.ts b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/index.ts index 8f70f77..063c76a 100644 --- a/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/index.ts +++ b/packages/ui/src/main/flow/READ_NO_REPLY_AUTO_REMINDER/index.ts @@ -16,6 +16,7 @@ import { writeStorageFile } from '@geekgeekrun/geek-auto-start-chat-with-boss/ru import * as fs from 'fs' import { pipeWriteRegardlessError } from '../utils/pipe' import { BossInfo } from '@geekgeekrun/sqlite-plugin/dist/entity/BossInfo' +import { messageForSaveFilter } from '../../../common/utils/chat-list' const throttleIntervalMinutes = readConfigFile('boss.json').autoReminder?.throttleIntervalMinutes ?? 10 @@ -261,16 +262,7 @@ const mainLoop = async () => { await pageMapByName.boss?.evaluate(() => { return document.querySelector('.message-content .chat-record')?.__vue__?.list$ ?? [] }) - )?.filter((it) => { - return ( - it.status !== 3 && // filter system notification out - it.templateId === 1 && // filter system notification out - ((['text', 'sticker', 'image', 'sound', 'comDesc'].includes(it.messageType) && - !it.extend?.greetingQuestionAnswer) || // include those message, filter out auto ask - (it.messageType === 'dialog' && - [0, 1, 2, 8, 11, 12, 14, 17, 33].includes(it?.dialog?.type))) // include message like resume, phone, map, etc., filter out auto ask - ) - }) ?? [] + )?.filter(messageForSaveFilter) ?? [] const lastGeekMessageSendTime = historyMessageList.findLast((it) => it.isSelf)?.time ?? 0 if (