3 /* Would be nice if we could just fold this into prerender-helper, but at the moment
4 * async helpers for express-hbs only take a single parameter and we can't use them
5 * Also, this way is much faster, so it's not so bad
8 var _
= require('lodash');
9 var compileTemplate
= require('./compile-web-template');
10 var timeFormat
= require('gitter-web-shared/time/time-format');
11 const generatePermalink
= require('gitter-web-shared/chat/generate-permalink');
12 // var fullTimeFormat = require('gitter-web-shared/time/full-time-format');
13 const getProfileUrlFromVirtualUser
= require('gitter-web-shared/get-profile-url-from-virtual-user');
15 var chatWrapper
= compileTemplate
.compileString(
16 '<div class="chat-item model-id-{{id}} {{burstClass}} {{unreadClass}} {{deletedClass}} {{threadedConversationClass}}" role="listitem">{{{inner}}}</div>'
19 var chatItemTemplate
= compileTemplate('/js/views/chat/tmpl/chatItemView.hbs');
20 var statusItemTemplate
= compileTemplate('/js/views/chat/tmpl/statusItemView.hbs');
22 function getFormattedTime(model
, lang
, tz
, tzOffset
, isArchive
) {
23 /* In the chat environment, we don't want to prerender the time
24 * when we don't know what timezone the user is in: we'll just wait
25 * until the javascript kicks in and render it then.
27 * However, in the archive environment, we don't want to do this
28 * for SEO and also because the chats are not re-rendered, so no
29 * times will be shown.
31 if (!tz
&& !isArchive
) {
35 return timeFormat(model
.sent
, { lang
: lang
, tzOffset
: tzOffset
, forceUtc
: isArchive
});
38 module
.exports
= exports = function(model
, params
) {
41 var root
= params
.data
.root
;
43 const isArchive
= params
.hash
.type
=== 'archive';
45 var troupeName
= root
.troupeName
;
47 var locale
= root
.locale
;
49 var tzOffset
= root
.tzOffset
;
51 var text
= model
.text
|| '';
52 var html
= model
.html
|| model
.text
|| '';
54 // Handle empty messages as deleted
55 if (html
.length
=== 0) {
56 html
= '<i>This message was deleted</i>';
57 deletedClass
= 'deleted';
60 const sentTimeFormatted
= getFormattedTime(model
, lang
, tz
, tzOffset
, isArchive
);
61 // TODO: add sentTimeFull
63 var m
= _
.extend({}, model
, {
64 displayName
: model
.fromUser
&& model
.fromUser
.displayName
,
65 username
: model
.fromUser
&& model
.fromUser
.username
,
66 sentTimeFormatted
: sentTimeFormatted
,
73 permalinkUrl
: generatePermalink(troupeName
, model
.id
, model
.sent
, isArchive
),
74 showItemActions
: !isArchive
78 m
.virtualUser
.isMatrix
= m
.virtualUser
.type
=== 'matrix';
79 m
.virtualUser
.profileUrl
= getProfileUrlFromVirtualUser(m
.virtualUser
);
85 result
= statusItemTemplate(m
);
87 result
= chatItemTemplate(m
);
90 var unreadClass
= model
.unread
? 'unread' : 'read';
91 var burstClass
= model
.burstStart
? 'burstStart' : 'burstContinued';
92 const threadedConversationClass
= model
.parentId
? 'threaded-conversation-chat-item' : '';
99 threadedConversationClass
,