diff --git a/webmail/public/js/message_detail.js b/webmail/public/js/message_detail.js index cbe6566..cd378d0 100644 --- a/webmail/public/js/message_detail.js +++ b/webmail/public/js/message_detail.js @@ -10,9 +10,28 @@ console.log(mail);//XXX + var timeStr = ""; + + if (mail.time){ + var time_m = moment(mail.time * 1000); + var durationStr = moment.duration(time_m - moment()).humanize(true); + + timeStr = time_m.format("YYYY-MM-DD HH:mm:ss") + " (" + durationStr + ")"; + } + + var body = []; + + mail.body.split("\n").forEach(function(line){ + body.push(line); + body.push( m("br") ); + }); + return [ - m("div") - ]; + m("h2", mail.subject), + m("h5", [ "From: ", m("b", mail.sender) ]), + m("h5", [ "Sent: ", m("b", timeStr) ]), + m("div", body) + ] } }; diff --git a/webmail/public/js/service.js b/webmail/public/js/service.js index 23662ba..7a79050 100644 --- a/webmail/public/js/service.js +++ b/webmail/public/js/service.js @@ -78,12 +78,16 @@ service.countUnread = function(){ service.readMail = function(index){ if (webmail.mails && webmail.mails.length){ - //mark as read with api - webmail.api.markRead(index); - //mark read locally var mail = webmail.mails[index-1]; - mail.unread = false; + + //mark as read with api + if (mail.unread){ + webmail.api.markRead(index); + + //mark read locally + mail.unread = false; + } return mail; }