From 1ca9d4472a33a49bf7c82fb300fe6c7be5ee23c6 Mon Sep 17 00:00:00 2001 From: xiyuesaves Date: Mon, 8 Apr 2024 20:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20#197=20=E9=AB=98=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E9=98=BB=E6=AD=A2=E6=92=A4=E5=9B=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/view.html | 10 ++++++ src/defaultConfig/defaultConfig.json | 1 + src/main.js | 52 +++++++++++++--------------- src/pages/configView.js | 1 + src/render_modules/debug.js | 12 +++---- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/src/config/view.html b/src/config/view.html index e9f9611e..ffbbf559 100644 --- a/src/config/view.html +++ b/src/config/view.html @@ -634,6 +634,16 @@

拦截自己的撤回操作


+
  • +
    +

    拦截所有群组的撤回事件

    + 不开启时仅拦截最近打开过的聊天对象,启用后会占用更多资源,仅限高版本 - 重启生效 +
    +
    + +
    +
  • +
  • 持久化保存

    diff --git a/src/defaultConfig/defaultConfig.json b/src/defaultConfig/defaultConfig.json index 1dd1ab42..f32ff0f0 100644 --- a/src/defaultConfig/defaultConfig.json +++ b/src/defaultConfig/defaultConfig.json @@ -79,6 +79,7 @@ "localStorage": false, "customColor": false, "preventSelfMsg": false, + "blockAllRetractions": false, "textColor": "#ff6666" }, "tail": { diff --git a/src/main.js b/src/main.js index df573b7e..e87580fd 100644 --- a/src/main.js +++ b/src/main.js @@ -891,8 +891,9 @@ function onBrowserWindowCreated(window, plugin) { if (options.debug.showChannedCommunication) { log("get", args[2], args[3]?.[1]?.[0], args); } - ipc_message(args); - return target.apply(thisArg, args); + if (ipc_message(args)) { + return target.apply(thisArg, args); + } }, }); @@ -901,6 +902,7 @@ function onBrowserWindowCreated(window, plugin) { * @param {Array} args ipc参数 */ function ipc_message(args) { + // 消息发送事件 if (args[3]?.[1]?.[0] === "nodeIKernelMsgService/sendMsg") { log("消息发送事件", args); if (checkChatType(args[3][1][1].peer)) { @@ -936,6 +938,7 @@ function onBrowserWindowCreated(window, plugin) { log("消息发送事件-拒绝处理"); } } + // 切换聊天对象 if (args[3]?.[1]?.[0] === "changeRecentContacPeerUid") { if (checkChatType(args[3]?.[1]?.[1].peer)) { log("切换聊天对象", args[3]?.[1]?.[1]); @@ -945,6 +948,7 @@ function onBrowserWindowCreated(window, plugin) { log("切换聚焦窗口-拒绝处理"); } } + // 切换聚焦窗口 if (args[3]?.[1]?.[0] === "nodeIKernelMsgService/setMsgRead") { if (checkChatType(args[3]?.[1]?.[1].peer)) { log("切换聚焦窗口", args[3]?.[1]?.[1]); @@ -954,6 +958,13 @@ function onBrowserWindowCreated(window, plugin) { log("切换聚焦窗口-拒绝处理"); } } + // 删除窗口激活 + if (options.preventMessageRecall.blockAllRetractions && args[3]?.[1]?.[0] === "nodeIKernelMsgService/deleteActiveChatByUid") { + log("丢弃删除激活窗口参数"); + // 丢弃这条事件 + return false; + } + return true; } if (window.webContents._events["-ipc-message"]?.[0]) { @@ -1212,9 +1223,9 @@ function onBrowserWindowCreated(window, plugin) { } } - // 最近联系人列表更新事件 + // 最近联系人列表更新事件 - 选项>阻止撤回>拦截所有撤回 const findRecentListIndex = findEventIndex(args, "nodeIKernelRecentContactListener/onRecentContactListChangedVer2"); - if (findRecentListIndex !== -1) { + if (options.preventMessageRecall.blockAllRetractions && findRecentListIndex !== -1) { const recentContactList = args?.[1]?.[findRecentListIndex]; log("检测到联系人列表更新", recentContactList); const recentContactLists = recentContactList?.payload?.changedRecentContactLists; @@ -1235,30 +1246,15 @@ function onBrowserWindowCreated(window, plugin) { continue; } log("激活聊天", activeMessageList.size, peer); - if (false) { - activeMessageList.add(peer.peerUid); - ipcMain.emit("IPC_UP_2", {}, { type: "request", callbackId: crypto.randomUUID(), eventName: "ns-ntApi-2" }, [ - "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", - { - peer, - cnt: 10, - }, - null, - ]); - } - if (true) { - activeMessageList.add(peer.peerUid); - ipcMain.emit("IPC_UP_2", {}, { type: "request", callbackId: crypto.randomUUID(), eventName: "ns-ntApi-2" }, [ - "nodeIKernelMsgService/getMsgsIncludeSelfAndAddActiveChat", - { - peer, - msgId: "0", - cnt: 10, - queryOrder: false, - }, - null, - ]); - } + activeMessageList.add(peer.peerUid); + ipcMain.emit("IPC_UP_2", {}, { type: "request", callbackId: crypto.randomUUID(), eventName: "ns-ntApi-2" }, [ + "nodeIKernelMsgService/getAioFirstViewLatestMsgsAndAddActiveChat", + { + peer, + cnt: 10, + }, + null, + ]); } } } diff --git a/src/pages/configView.js b/src/pages/configView.js index 4b2191fb..0dcb3400 100644 --- a/src/pages/configView.js +++ b/src/pages/configView.js @@ -193,6 +193,7 @@ async function onConfigView(view) { addSwitchEventlistener("preventMessageRecall.localStorage", ".localStorage"); addSwitchEventlistener("preventMessageRecall.preventSelfMsg", ".preventSelfMsg"); addSwitchEventlistener("preventMessageRecall.customColor", ".custom-color"); + addSwitchEventlistener("preventMessageRecall.blockAllRetractions", ".blockAllRetractions"); // 初始化自定义撤回样式 const customTextColorEl = view.querySelector(".custom-text-color"); diff --git a/src/render_modules/debug.js b/src/render_modules/debug.js index 9be862f9..f966e65f 100644 --- a/src/render_modules/debug.js +++ b/src/render_modules/debug.js @@ -1,4 +1,4 @@ -import superjson from 'superjson'; +import superjson from "superjson"; // 导出到window对象便于调试 window.superjson = superjson; @@ -6,8 +6,8 @@ window.superjson = superjson; const port = location.port; console.log("通信端口", port); (async () => { - try { - while (true) { + while (true) { + try { let log = superjson.parse(await (await fetch(`http://localhost:${port}/`)).text()); if (log && log.length) { for (let i = 0; i < log.length; i++) { @@ -17,8 +17,8 @@ console.log("通信端口", port); } } } + } catch (err) { + // console.log("=========已断开连接=========", err); } - } catch (err) { - console.log("=========已断开连接========="); } -})(); \ No newline at end of file +})();