From 58a962aa5d7829bd075eb3cec2d9aa4b425dbe1d Mon Sep 17 00:00:00 2001 From: Zuzanna Date: Thu, 1 Jan 2026 17:13:04 +0100 Subject: [PATCH] messages not sent to author --- src/worker/components/mailbox-handlers.js | 78 ++++++++-------- src/worker/components/roster.js | 8 +- src/worker/modules/mailbox.js | 107 +++++++++++----------- www/common/messenger-ui.js | 16 +++- www/common/notifications.js | 23 +++-- www/common/sframe-common-mailbox.js | 1 + www/notifications/inner.js | 6 +- 7 files changed, 127 insertions(+), 112 deletions(-) diff --git a/src/worker/components/mailbox-handlers.js b/src/worker/components/mailbox-handlers.js index 40dc72043..cf67a740a 100644 --- a/src/worker/components/mailbox-handlers.js +++ b/src/worker/components/mailbox-handlers.js @@ -259,53 +259,53 @@ 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") + // console.log("here2") - var msg = data.msg; - var hash = data.hash; - var content = msg.content; - // content.name, content.title, content.href, content.password + // 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'; + // 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; - } + // 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); - } + // if (content.password) { + // content.password = encryptPassword(ctx, content.password); + // } - // Update the data - channels[channel] = { - mode: mode, - data: { - type: box.type, - hash: hash - } - }; + // // Update the data + // channels[channel] = { + // mode: mode, + // data: { + // type: box.type, + // hash: hash + // } + // }; - cb(false, toRemove); + // cb(false, toRemove); }; removeHandlers['SHARE_PAD'] = function (ctx, box, data, hash) { - var content = data.content; - var channel = Hash.hrefToHexChannelId(content.href, content.password); - var old = channels[channel]; - if (old && old.data && old.data.hash === hash) { - delete channels[channel]; - } + // var content = data.content; + // var channel = Hash.hrefToHexChannelId(content.href, content.password); + // var old = channels[channel]; + // if (old && old.data && old.data.hash === hash) { + // delete channels[channel]; + // } }; // Hide duplicates when receiving a SUPPORT_MESSAGE notification diff --git a/src/worker/components/roster.js b/src/worker/components/roster.js index 198b37f3c..8493b8ca7 100644 --- a/src/worker/components/roster.js +++ b/src/worker/components/roster.js @@ -644,10 +644,10 @@ var factory = function (Util, Hash, CPNetflux, Sortify, nThen, Crypto) { // count messages received since the last checkpoint // even if they fail to parse - if (lastHash !== hash) { - // Don't count duplicate lkh message on reconnect - ref.internal.sinceLastCheckpoint++; - } + // if (lastHash !== hash) { + // // Don't count duplicate lkh message on reconnect + // ref.internal.sinceLastCheckpoint++; + // } lastHash = hash; var parsed = Util.tryParse(msg); diff --git a/src/worker/modules/mailbox.js b/src/worker/modules/mailbox.js index 1c0a5e10b..01943a80a 100644 --- a/src/worker/modules/mailbox.js +++ b/src/worker/modules/mailbox.js @@ -87,6 +87,7 @@ proxy.mailboxes = { // Send a message to someone else var sendTo = Mailbox.sendTo = function (ctx, type, msg, user, _cb) { + console.log("hello", user, msg) user = user || {}; var cb = _cb || function (obj) { if (obj && obj.error) { @@ -348,59 +349,59 @@ proxy.mailboxes = { }; var lastReceivedHash; // Don't send a duplicate of the last known hash on reconnect box.onMessage = cfg.onMessage = function (msg, user, vKey, isCp, hash, author, data) { - if (hash === m.lastKnownHash) { return; } - if (hash === lastReceivedHash) { return; } - var time = data && data.time; - lastReceivedHash = hash; - try { - msg = JSON.parse(msg); - } catch (e) { - console.error(e); - } - if (author) { msg.author = author; } - box.history.push(hash); - if (isMessageNew(hash, m)) { - // Message should be displayed - var message = { - msg: msg, - hash: hash, - time: time - }; - var notify = box.ready; - Handlers.add(ctx, box, message, function (dismissed, toDismiss, invalid) { - 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; } - showMessage(ctx, type, message, null, function (obj) { - if (!obj || !obj.msg || !notify) { return; } - Notify.system(undefined, obj.msg); - }); - }); - } else { - // Message has already been viewed by the user - if (Object.keys(box.content).length === 0) { - // If nothing is displayed yet, we can bump our lastKnownHash and remove this hash - // from our "viewed" array - m.lastKnownHash = hash; - box.history = []; - var idxViewed = m.viewed.indexOf(hash); - if (idxViewed !== -1) { m.viewed.splice(idxViewed, 1); } - } - } + // if (hash === m.lastKnownHash) { return; } + // if (hash === lastReceivedHash) { return; } + // var time = data && data.time; + // lastReceivedHash = hash; + // try { + // msg = JSON.parse(msg); + // } catch (e) { + // console.error(e); + // } + // if (author) { msg.author = author; } + // box.history.push(hash); + // if (isMessageNew(hash, m)) { + // // // Message should be displayed + // // var message = { + // // msg: msg, + // // hash: hash, + // // time: time + // // }; + // // var notify = box.ready; + // // Handlers.add(ctx, box, message, function (dismissed, toDismiss, invalid) { + // // // 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; } + // // showMessage(ctx, type, message, null, function (obj) { + // // if (!obj || !obj.msg || !notify) { return; } + // // Notify.system(undefined, obj.msg); + // // }); + // // }); + // } else { + // // Message has already been viewed by the user + // if (Object.keys(box.content).length === 0) { + // // If nothing is displayed yet, we can bump our lastKnownHash and remove this hash + // // from our "viewed" array + // m.lastKnownHash = hash; + // box.history = []; + // var idxViewed = m.viewed.indexOf(hash); + // if (idxViewed !== -1) { m.viewed.splice(idxViewed, 1); } + // } + // } }; cfg.onReady = function () { // Clean the "viewed" array: make sure all the "viewed" hashes are diff --git a/www/common/messenger-ui.js b/www/common/messenger-ui.js index d749160a7..6bb44beeb 100644 --- a/www/common/messenger-ui.js +++ b/www/common/messenger-ui.js @@ -669,12 +669,22 @@ define([ force: toolbar && toolbar.team && !toolbar['chat'].hasClass('cp-leftside-active') }); - common.mailbox.sendTo("SEND_CHAT_MESSAGE", { - name: name + // console.log("data", channel, contactsData[channel.curvePublic]) + // console.log("common", common.getMetadataMgr().getUserData().curvePublic) + console.log("message", message, channel.curvePublic) + // console.log("test", common.getMetadataMgr().getUserData().curvePublic !== message.author) + if (common.getMetadataMgr().getUserData().curvePublic !== message.author) { + common.mailbox.sendTo("SEND_CHAT_MESSAGE", { + name: name, + author: message.author + // messa }, { channel: contactsData[channel.curvePublic].notifications, - curvePublic: channel.curvePublic + // curvePublic: channel.curvePublic + curvePublic: message.author }) + } + } notifyToolbar(); diff --git a/www/common/notifications.js b/www/common/notifications.js index 0a1d773a2..395d07295 100644 --- a/www/common/notifications.js +++ b/www/common/notifications.js @@ -147,6 +147,9 @@ define([ var content = data.content; var msg = content.msg; var key = 'sent_chatMessage'; // Msg.notification_padSharedTeam + console.log("content", data.content.msg.content) + console.log("author", msg.author) + console.log("common", common.getMetadataMgr().getUserData()) var name = Util.fixHTML(msg.content.name) || Messages.anonymous; content.getFormatText = function() { @@ -657,17 +660,17 @@ define([ return { add: function(common, data) { - var type = data.content.msg.type; + // var type = data.content.msg.type; - if (handlers[type]) { - handlers[type](common, data); - // add getters to access simply some informations - data.content.isClickable = typeof data.content.handler === "function"; - data.content.isDismissible = typeof data.content.dismissHandler === "function"; - } else { - data.content.dismissHandler = defaultDismiss(common, data); - data.content.isDismissible = typeof data.content.dismissHandler === "function"; - } + // if (handlers[type]) { + // handlers[type](common, data); + // // add getters to access simply some informations + // data.content.isClickable = typeof data.content.handler === "function"; + // data.content.isDismissible = typeof data.content.dismissHandler === "function"; + // } else { + // data.content.dismissHandler = defaultDismiss(common, data); + // data.content.isDismissible = typeof data.content.dismissHandler === "function"; + // } }, remove: function(common, data) { common.removeFriendRequest(data.hash); diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index bb3fb7708..6c681cd50 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -41,6 +41,7 @@ define([ mailbox.sendTo = function (type, content, user, cb) { cb = cb || function () {}; + console.log("hii") execCommand('SENDTO', { type: type, msg: content, diff --git a/www/notifications/inner.js b/www/notifications/inner.js index 1c0700ba1..3b86b8f6e 100644 --- a/www/notifications/inner.js +++ b/www/notifications/inner.js @@ -189,9 +189,9 @@ define([ }; create['pads'] = function () { - var key = 'pads'; - var filter = ["SHARE_PAD"]; - return makeNotificationList(key, filter); + // var key = 'pads'; + // var filter = ["SHARE_PAD"]; + // return makeNotificationList(key, filter); }; create['archived'] = function () {