update notification when chat history is cleared

This commit is contained in:
daria 2026-04-29 14:27:29 +03:00
parent a8f66a078b
commit eb3f17c1fd
No known key found for this signature in database
GPG Key ID: 3B75240E6B2F2701
2 changed files with 19 additions and 6 deletions

View File

@ -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);
});
}
});
};

View File

@ -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') {