From 81cbb3f6fe3023e8823fb63fee695c4424ab5b5b Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 15 Oct 2019 18:03:31 +0200 Subject: [PATCH] Sort support messages differently --- www/admin/app-admin.less | 5 +++++ www/admin/inner.js | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/www/admin/app-admin.less b/www/admin/app-admin.less index a1c1ee779..10e178308 100644 --- a/www/admin/app-admin.less +++ b/www/admin/app-admin.less @@ -18,5 +18,10 @@ display: flex; flex-flow: column; + + .cp-support-container { + display: flex; + flex-flow: column; + } } diff --git a/www/admin/inner.js b/www/admin/inner.js index 4c335dd12..7478442c5 100644 --- a/www/admin/inner.js +++ b/www/admin/inner.js @@ -170,10 +170,36 @@ define([ var supportKey = ApiConfig.supportMailbox; create['support-list'] = function () { if (!supportKey || !APP.privateKey) { return; } - var $div = makeBlock('support-list'); - $div.addClass('cp-support-container'); + var $container = makeBlock('support-list'); + var $div = $(h('div.cp-support-container')).appendTo($container); var hashesById = {}; + var reorder = function () { + var order = Object.keys(hashesById); + order.sort(function (id1, id2) { + var t1 = hashesById[id1]; + var t2 = hashesById[id2]; + if (!Array.isArray(t1)) { return 1; } + if (!Array.isArray(t2)) { return -1; } + var lastMsg1 = t1[t1.length - 1]; + var lastMsg2 = t2[t2.length - 1]; + var time1 = Util.find(lastMsg1, ['content', 'msg', 'content', 'time']); + var time2 = Util.find(lastMsg2, ['content', 'msg', 'content', 'time']); + var authorEd1 = Util.find(lastMsg1, ['content', 'msg', 'content', 'sender', 'edPublic']); + var authorEd2 = Util.find(lastMsg2, ['content', 'msg', 'content', 'sender', 'edPublic']); + var admin1 = ApiConfig.adminKeys.indexOf(authorEd1) !== -1; + var admin2 = ApiConfig.adminKeys.indexOf(authorEd2) !== -1; + // If one is answered and not the other, put the unanswered first + if (admin1 && !admin2) { return 1; } + if (!admin1 && admin2) { return -1; } + // Otherwise, sort them by time + return time2 - time1; + }); + order.forEach(function (id, i) { + $div.find('[data-id="'+id+'"]').css('order', i); + }); + }; + // Register to the "support" mailbox common.mailbox.subscribe(['supportadmin'], { onMessage: function (data) { @@ -219,11 +245,13 @@ define([ }); } $ticket.append(APP.support.makeMessage(content, hash)); + reorder(); } }); - return $div; + return $container; }; + var checkAdminKey = function (priv) { if (!supportKey) { return; } return Hash.checkBoxKeyPair(priv, supportKey);