From eb3f17c1fdb5f7641d95293c77e56259a7a6f359 Mon Sep 17 00:00:00 2001 From: daria <95225431+dariiing@users.noreply.github.com> Date: Wed, 29 Apr 2026 14:27:29 +0300 Subject: [PATCH] update notification when chat history is cleared --- src/worker/modules/messenger.js | 16 ++++++++++++++++ www/common/messenger-ui.js | 9 +++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/worker/modules/messenger.js b/src/worker/modules/messenger.js index ad55143a7..3956f9464 100644 --- a/src/worker/modules/messenger.js +++ b/src/worker/modules/messenger.js @@ -15,6 +15,7 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging, var Types = { message: 'MSG', + cleared: 'CLEARED', unfriend: 'UNFRIEND', mapId: 'MAP_ID', mapIdAck: 'MAP_ID_ACK' @@ -271,6 +272,11 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging, return true; } var proxy = ctx.store.proxy; + if (parsedMsg[0] === Types.cleared) { + channel.messages = []; + ctx.emit('CLEAR_CHANNEL', channel.id, channel.clients); + return; + } if (parsedMsg[0] === Types.unfriend) { curvePublic = parsedMsg[1]; @@ -917,11 +923,21 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging, var channel = ctx.channels[id]; if (!channel) { return void cb({error: 'NO_CHANNEL'}); } if (!ctx.store.rpc) { return void cb({error: 'RPC_NOT_READY'}); } + var proxy = ctx.store.proxy || {}; ctx.store.rpc.clearOwnedChannel(id, function (err) { cb({error:err}); if (!err) { channel.messages = []; ctx.emit('CLEAR_CHANNEL', id, channel.clients); + var msg = [Types.cleared, proxy.curvePublic, +new Date()]; + var msgStr = JSON.stringify(msg); + var cryptMsg = channel.encrypt(msgStr); + + channel.wc.bcast(cryptMsg).then(function () { + // Success (message sent) + }, function (err) { + console.error('Failed to send message:', err); + }); } }); }; diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index f95749bcd..95d1e083b 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -253,7 +253,8 @@ define([ var displaySystemMessage = function (id, message) { var $messagebox = $(getChat(id)).find('.cp-app-contacts-messages'); if (!$messagebox.length) { return; } - $messagebox.append(h('div.cp-app-contacts-message.cp-app-contacts-system-notification', message)); + var noticeElement = h('div.cp-app-contacts-message.cp-app-contacts-system-notification', message); + $messagebox.append(noticeElement); normalizeLabels($messagebox); scrollChatToBottom(); }; @@ -357,7 +358,6 @@ define([ return; } clearChannel(id); - send(Messages.contacts_historyCleared); }); }); }); @@ -780,10 +780,6 @@ define([ debug(message); - if (message.text === Messages.contacts_historyCleared) { - displaySystemMessage(chanId, message.text); - return; - } var el_message = markup.message(message); if (message.type === 'MSG') { @@ -1155,6 +1151,7 @@ define([ } if (cmd === 'CLEAR_CHANNEL') { clearChannel(data); + displaySystemMessage(data, Messages.contacts_historyCleared); return; } if (cmd === 'PADCHAT_READY') {