From c463d1ddd354e9ad292f93fd61d8c76f0fde5a4d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Fri, 28 Feb 2020 17:01:17 +0200 Subject: [PATCH] Emit an event to clear history on all open clients --- client/js/helpers/contextMenu.js | 6 ------ client/js/socket-events/history_clear.js | 14 ++++++++++++++ client/js/socket-events/index.js | 1 + src/client.js | 4 ++++ 4 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 client/js/socket-events/history_clear.js diff --git a/client/js/helpers/contextMenu.js b/client/js/helpers/contextMenu.js index 9f508ebf..49b3834e 100644 --- a/client/js/helpers/contextMenu.js +++ b/client/js/helpers/contextMenu.js @@ -147,12 +147,6 @@ export function generateChannelContextMenu($root, channel, network) { return; } - channel.messages = []; - channel.unread = 0; - channel.highlight = 0; - channel.firstUnread = 0; - channel.moreHistoryAvailable = false; - socket.emit("history:clear", { target: channel.id, }); diff --git a/client/js/socket-events/history_clear.js b/client/js/socket-events/history_clear.js new file mode 100644 index 00000000..e0d7b2b0 --- /dev/null +++ b/client/js/socket-events/history_clear.js @@ -0,0 +1,14 @@ +"use strict"; + +import socket from "../socket"; +import store from "../store"; + +socket.on("history:clear", function(data) { + const {channel} = store.getters.findChannel(data.target); + + channel.messages = []; + channel.unread = 0; + channel.highlight = 0; + channel.firstUnread = 0; + channel.moreHistoryAvailable = false; +}); diff --git a/client/js/socket-events/index.js b/client/js/socket-events/index.js index 722ec3a7..0384acd2 100644 --- a/client/js/socket-events/index.js +++ b/client/js/socket-events/index.js @@ -23,3 +23,4 @@ import "./sessions_list"; import "./configuration"; import "./changelog"; import "./setting"; +import "./history_clear"; diff --git a/src/client.js b/src/client.js index ee5f8de5..637f864d 100644 --- a/src/client.js +++ b/src/client.js @@ -514,6 +514,10 @@ Client.prototype.clearHistory = function(data) { target.chan.highlight = 0; target.chan.firstUnread = 0; + client.emit("history:clear", { + target: target.chan.id, + }); + if (!target.chan.isLoggable()) { return; }