From 632d5db8d2c9c49b059a456f7258b3cee39858dc Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 12 Mar 2021 18:13:05 +0100 Subject: [PATCH] Order notifications by creation time across all mailboxes --- www/common/outer/mailbox.js | 5 ++++- www/common/sframe-common-mailbox.js | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/www/common/outer/mailbox.js b/www/common/outer/mailbox.js index d365bbadb..2c7796001 100644 --- a/www/common/outer/mailbox.js +++ b/www/common/outer/mailbox.js @@ -299,6 +299,7 @@ proxy.mailboxes = { sendMessage(msg, function (err, hash) { if (err) { return void console.error(err); } box.history.push(hash); + _msg.ctime = +new Date(); box.content[hash] = _msg; var message = { msg: _msg, @@ -314,9 +315,10 @@ proxy.mailboxes = { box.queue = []; }; 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) { + 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); @@ -362,6 +364,7 @@ proxy.mailboxes = { }); return; } + msg.ctime = time || 0; box.content[hash] = msg; showMessage(ctx, type, message, null, function (obj) { if (!obj || !obj.msg || !notify) { return; } diff --git a/www/common/sframe-common-mailbox.js b/www/common/sframe-common-mailbox.js index dd031f005..4ab2b6f72 100644 --- a/www/common/sframe-common-mailbox.js +++ b/www/common/sframe-common-mailbox.js @@ -73,7 +73,9 @@ define([ Common.openURL(Hash.hashToHref(userData.profile, 'profile')); }); } + var order = -Math.floor((Util.find(data, ['content', 'msg', 'ctime']) || 0) / 1000); notif = h('div.cp-notification', { + style: 'order:'+order+';', 'data-hash': data.content.hash }, [ avatar,