Skip to content

Commit

Permalink
修复 #197 高版本阻止撤回功能无法正常工作
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyuesaves committed Apr 8, 2024
1 parent 7aecdfb commit 1ca9d44
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
10 changes: 10 additions & 0 deletions src/config/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,16 @@ <h2>拦截自己的撤回操作</h2>
</div>
</li>
<hr class="horizontal-dividing-line" />
<li class="vertical-list-item">
<div>
<h2>拦截所有群组的撤回事件</h2>
<span class="secondary-text">不开启时仅拦截最近打开过的聊天对象,启用后会占用更多资源,仅限高版本 - 重启生效</span>
</div>
<div class="blockAllRetractions q-switch">
<span class="q-switch__handle"></span>
</div>
</li>
<hr class="horizontal-dividing-line" />
<li title="" class="vertical-list-item">
<div>
<h2>持久化保存</h2>
Expand Down
1 change: 1 addition & 0 deletions src/defaultConfig/defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"localStorage": false,
"customColor": false,
"preventSelfMsg": false,
"blockAllRetractions": false,
"textColor": "#ff6666"
},
"tail": {
Expand Down
52 changes: 24 additions & 28 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});

Expand All @@ -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)) {
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand All @@ -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]) {
Expand Down Expand Up @@ -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;
Expand All @@ -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,
]);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/configView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
12 changes: 6 additions & 6 deletions src/render_modules/debug.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import superjson from 'superjson';
import superjson from "superjson";

// 导出到window对象便于调试
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++) {
Expand All @@ -17,8 +17,8 @@ console.log("通信端口", port);
}
}
}
} catch (err) {
// console.log("=========已断开连接=========", err);
}
} catch (err) {
console.log("=========已断开连接=========");
}
})();
})();

0 comments on commit 1ca9d44

Please sign in to comment.