From cdf3cee9c8d25c40a7ea5a30bd4b85c81672dca1 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 8 Aug 2017 18:21:03 +0200 Subject: [PATCH] split out message rendering into ui --- www/common/common-messaging.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js index 01fa6e8df..842700a3a 100644 --- a/www/common/common-messaging.js +++ b/www/common/common-messaging.js @@ -188,6 +188,18 @@ define([ UI.addToFriendList(common, $block, display, remove, curvePublic); }; + ui.createMessage = function (msg, name) { + var $msg = $('
', {'class': 'message'}) + .attr('title', msg.time ? new Date(msg.time).toLocaleString(): '?'); + + if (name) { + $('
', {'class':'sender'}).text(name).appendTo($msg); + } + + $('
', {'class':'content'}).html(parseMessage(msg.text)).appendTo($msg); + return $msg; + }; + return ui; }; @@ -599,7 +611,7 @@ define([ }); }; - Msg.init = function (common, ui) { //$listContainer, $msgContainer) { + Msg.init = function (common, ui) { // declare common variables var network = common.getNetwork(); var proxy = common.getProxy(); @@ -641,21 +653,11 @@ define([ var last = typeof(channel.lastDisplayed) === 'number'? channel.lastDisplayed: -1; for (var i = last + 1; i', {'class': 'message'}).appendTo($messages); - - // date - date = msg.time ? new Date(msg.time).toLocaleString(): '?'; - //$('
', {'class':'date'}).text(date).appendTo($msg); - $msg.attr('title', date); + name = (msg.channel !== channel.lastSender)? + getFriend(common, msg.channel).displayName: undefined; - // name - if (msg.channel !== channel.lastSender) { - name = getFriend(common, msg.channel).displayName; - $('
', {'class':'sender'}).text(name).appendTo($msg); - } + ui.createMessage(msg, name).appendTo($messages); channel.lastSender = msg.channel; - - $('
', {'class':'content'}).html(parseMessage(msg.text)).appendTo($msg); } $messages.scrollTop($messages[0].scrollHeight); channel.lastDisplayed = i-1;