messages not sent to author

This commit is contained in:
Zuzanna 2026-01-01 17:13:04 +01:00
parent 8f1fdf822c
commit 58a962aa5d
7 changed files with 127 additions and 112 deletions

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -41,6 +41,7 @@ define([
mailbox.sendTo = function (type, content, user, cb) {
cb = cb || function () {};
console.log("hii")
execCommand('SENDTO', {
type: type,
msg: content,

View File

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