split out message rendering into ui

pull/1/head
ansuz 7 years ago
parent fcdfa52aa9
commit cdf3cee9c8

@ -188,6 +188,18 @@ define([
UI.addToFriendList(common, $block, display, remove, curvePublic); UI.addToFriendList(common, $block, display, remove, curvePublic);
}; };
ui.createMessage = function (msg, name) {
var $msg = $('<div>', {'class': 'message'})
.attr('title', msg.time ? new Date(msg.time).toLocaleString(): '?');
if (name) {
$('<div>', {'class':'sender'}).text(name).appendTo($msg);
}
$('<div>', {'class':'content'}).html(parseMessage(msg.text)).appendTo($msg);
return $msg;
};
return ui; return ui;
}; };
@ -599,7 +611,7 @@ define([
}); });
}; };
Msg.init = function (common, ui) { //$listContainer, $msgContainer) { Msg.init = function (common, ui) {
// declare common variables // declare common variables
var network = common.getNetwork(); var network = common.getNetwork();
var proxy = common.getProxy(); var proxy = common.getProxy();
@ -641,21 +653,11 @@ define([
var last = typeof(channel.lastDisplayed) === 'number'? channel.lastDisplayed: -1; var last = typeof(channel.lastDisplayed) === 'number'? channel.lastDisplayed: -1;
for (var i = last + 1; i<messages.length; i++) { for (var i = last + 1; i<messages.length; i++) {
msg = messages[i]; msg = messages[i];
$msg = $('<div>', {'class': 'message'}).appendTo($messages); name = (msg.channel !== channel.lastSender)?
getFriend(common, msg.channel).displayName: undefined;
// date
date = msg.time ? new Date(msg.time).toLocaleString(): '?';
//$('<div>', {'class':'date'}).text(date).appendTo($msg);
$msg.attr('title', date);
// name ui.createMessage(msg, name).appendTo($messages);
if (msg.channel !== channel.lastSender) {
name = getFriend(common, msg.channel).displayName;
$('<div>', {'class':'sender'}).text(name).appendTo($msg);
}
channel.lastSender = msg.channel; channel.lastSender = msg.channel;
$('<div>', {'class':'content'}).html(parseMessage(msg.text)).appendTo($msg);
} }
$messages.scrollTop($messages[0].scrollHeight); $messages.scrollTop($messages[0].scrollHeight);
channel.lastDisplayed = i-1; channel.lastDisplayed = i-1;

Loading…
Cancel
Save