From 8f1fdf822c8ab7f96f0f5c8ab1063ecfcebda963 Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 1 Jan 2026 12:51:14 +0100 Subject: [PATCH] notification received when message sent --- customize.dist/messages.js | 1 + src/worker/components/mailbox-handlers.js | 60 +++++++++++++++++++++-- src/worker/modules/mailbox.js | 29 ++++++----- src/worker/modules/messenger.js | 7 --- www/common/messenger-ui.js | 23 ++++----- www/common/notifications.js | 21 +++++++- www/pad/comments.js | 2 + 7 files changed, 101 insertions(+), 42 deletions(-) diff --git a/customize.dist/messages.js b/customize.dist/messages.js index e0284fd64..434a57bf6 100755 --- a/customize.dist/messages.js +++ b/customize.dist/messages.js @@ -134,6 +134,7 @@ define(req, function(AppConfig, Default, Language) { } }; + Messages.sent_chatMessage = "{0} has sent you a message" // XXX return Messages; }); diff --git a/src/worker/components/mailbox-handlers.js b/src/worker/components/mailbox-handlers.js index 1c7b6ffc0..40dc72043 100644 --- a/src/worker/components/mailbox-handlers.js +++ b/src/worker/components/mailbox-handlers.js @@ -181,7 +181,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { }; // UI for accepted friend request handlers['FRIEND_REQUEST_ACCEPTED'] = function (ctx, box, data, cb) { - console.log("here") ctx.updateMetadata(); var curve = data.msg.content.user.curvePublic || data.msg.content.user; var toRemove = friendRequestDeclined[curve]; @@ -194,7 +193,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { cb(false, toRemove); }; removeHandlers['FRIEND_REQUEST_ACCEPTED'] = function (ctx, box, data) { - console.log("friend") var curve = data.content.user.curvePublic || data.content.user; if (friendRequestAccepted[curve]) { delete friendRequestAccepted[curve]; } }; @@ -261,6 +259,8 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { // Keep only one notification per channel: the stronger and more recent one var channels = {}; handlers['SHARE_PAD'] = function (ctx, box, data, cb) { + console.log("here2") + var msg = data.msg; var hash = data.hash; var content = msg.content; @@ -319,6 +319,59 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { supportMessage = false; }; + + var messageChannels = {}; + handlers['SEND_CHAT_MESSAGE'] = function (ctx, box, data, cb) { + console.log("here2") + + var msg = data.msg; + var hash = data.hash; + var content = msg.content; + // content.name, content.title, content.href, content.password + + if (isMuted(ctx, data)) { return void cb(true); } + // if the shared content is a 'link' then we can't use the channel to deduplicate notifications + // use href instead. + var channel = content.isStatic ? content.href : Hash.hrefToHexChannelId(content.href, content.password); + var parsed = Hash.parsePadUrl(content.href); + var mode = parsed.hashData && parsed.hashData.mode || 'n/a'; + + var old = channels[channel]; + var toRemove; + if (old) { + // New hash is weaker, ignore + if (old.mode === 'edit' && mode === 'view') { + return void cb(true); + } + // New hash is not weaker, clear the old one + toRemove = old.data; + } + + if (content.password) { + content.password = encryptPassword(ctx, content.password); + } + + // Update the data + messageChannels[channel] = { + mode: mode, + data: { + type: box.type, + hash: hash + } + }; + + cb(false, toRemove); + }; + removeHandlers['SEND_CHAT_MESSAGE'] = function (ctx, box, data, hash) { + var content = data.content; + var channel = Hash.hrefToHexChannelId(content.href, content.password); + var old = messageChannels[channel]; + if (old && old.data && old.data.hash === hash) { + delete messageChannels[channel]; + } + }; + + // Incoming edit rights request: add data before sending it to inner handlers['REQUEST_PAD_ACCESS'] = function (ctx, box, data, cb) { var msg = data.msg; @@ -349,7 +402,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { }; handlers['GIVE_PAD_ACCESS'] = function (ctx, box, data, cb) { - console.log("msgs2") var msg = data.msg; var content = msg.content; @@ -369,7 +421,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { }; handlers['ADD_TO_ACCESS_LIST'] = function(ctx, common, data, cb) { - var msg = data.msg; var content = msg.content; var channel = content.channel; @@ -681,7 +732,6 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { // Keep only one notification per channel: the stronger and more recent one var comments = {}; handlers['COMMENT_REPLY'] = function (ctx, box, data, cb) { - console.log("hello@") var msg = data.msg; var hash = data.hash; var content = msg.content; diff --git a/src/worker/modules/mailbox.js b/src/worker/modules/mailbox.js index 1f1d8dcd7..1c0a5e10b 100644 --- a/src/worker/modules/mailbox.js +++ b/src/worker/modules/mailbox.js @@ -368,21 +368,20 @@ proxy.mailboxes = { }; var notify = box.ready; Handlers.add(ctx, box, message, function (dismissed, toDismiss, invalid) { - console.log("hello???", toDismiss, invalid, dismissed) - // if (toDismiss) { // List of other messages to remove - // dismiss(ctx, toDismiss, '', function () { - // console.log('Notification handled automatically'); - // }); - // } - // if (invalid || dismissed) { // This message should be removed - // dismiss(ctx, { - // type: type, - // hash: hash - // }, '', function () { - // console.log('Notification handled automatically'); - // }); - // return; - // } + if (toDismiss) { // List of other messages to remove + dismiss(ctx, toDismiss, '', function () { + console.log('Notification handled automatically'); + }); + } + if (invalid || dismissed) { // This message should be removed + dismiss(ctx, { + type: type, + hash: hash + }, '', function () { + console.log('Notification handled automatically'); + }); + return; + } msg.ctime = time || 0; box.content[hash] = msg; if (opts.dump) { return; } diff --git a/src/worker/modules/messenger.js b/src/worker/modules/messenger.js index e43704e60..ad55143a7 100644 --- a/src/worker/modules/messenger.js +++ b/src/worker/modules/messenger.js @@ -293,7 +293,6 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging, }; var onDirectMessage = function (ctx, msg, sender) { - console.log("here!!") var hk = ctx.store.network.historyKeeper; if (sender !== hk) { return void onIdMessage(ctx, msg, sender); } var parsed = JSON.parse(msg); @@ -398,15 +397,9 @@ const factory = (Crypto, Hash, Util, Realtime, Messaging, }; var onMessage = function (ctx, msg, sender, chan) { - console.log("wkjhdkejdh") var channel = ctx.channels[chan.id]; if (!channel) { return; } pushMsg(ctx, channel, msg); - // ctx.emit('FRIEND_REQUEST_ACCEPTED', { - // curvePublic: curvePublic, - // fromMe: true - // }, ctx.friendsClients); - }; var onFriendRemoved = function (ctx, curvePublic, chanId) { diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index be44074fd..d749160a7 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -657,17 +657,8 @@ define([ debug(message); var el_message = markup.message(message); - console.log("PROXY", message, contactsData) - common.mailbox.sendTo("COMMENT_REPLY", { - channel: channel, - content: "hello" - }, { - channel: contactsData[message.author].notifications, - curvePublic: message.author - }) - // ProxyManager.sendNotification() - console.log("hello!!") + if (message.type === 'MSG') { var name = UI.getDisplayName(typeof message.name !== "undefined" ? message.name: @@ -677,11 +668,15 @@ define([ msg: message.text, force: toolbar && toolbar.team && !toolbar['chat'].hasClass('cp-leftside-active') }); + + common.mailbox.sendTo("SEND_CHAT_MESSAGE", { + name: name + }, { + channel: contactsData[channel.curvePublic].notifications, + curvePublic: channel.curvePublic + }) } - // ctx.emit('FRIEND_REQUEST_ACCEPTED', { - // curvePublic: curvePublic, - // fromMe: true - // }, ctx.friendsClients); + notifyToolbar(); channel.messages.push(message); diff --git a/www/common/notifications.js b/www/common/notifications.js index 293480fba..0a1d773a2 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -90,6 +90,7 @@ define([ // Share pad handlers['SHARE_PAD'] = function(common, data) { + console.log("here1", common, data) var content = data.content; var msg = content.msg; var type = Hash.parsePadUrl(msg.content.href).type; @@ -141,6 +142,25 @@ define([ } }; + // Send chat message + handlers['SEND_CHAT_MESSAGE'] = function(common, data) { + var content = data.content; + var msg = content.msg; + var key = 'sent_chatMessage'; // Msg.notification_padSharedTeam + + var name = Util.fixHTML(msg.content.name) || Messages.anonymous; + content.getFormatText = function() { + return Messages._getKey(key, [name]); + }; + content.handler = function() { + common.openURL('/contacts/'); + defaultDismiss(common, data)(); + }; + if (!content.archived) { + content.dismissHandler = defaultDismiss(common, data); + } + }; + // New support message from the admins handlers['SUPPORT_MESSAGE'] = function(common, data) { var content = data.content; @@ -364,7 +384,6 @@ define([ }; handlers['COMMENT_REPLY'] = function(common, data) { - console.log("hello$") var content = data.content; var msg = content.msg; diff --git a/www/pad/comments.js b/www/pad/comments.js index 5c313b081..ee455513f 100644 --- a/www/pad/comments.js +++ b/www/pad/comments.js @@ -122,6 +122,8 @@ define([ channel: data.notifications, curvePublic: data.curvePublic }); + + console.log("here!", privateData.channel, data.notifications, data.curvePublic) }); };