Skip to content

Commit

Permalink
Merge pull request #158 from RocketChat/group-messages
Browse files Browse the repository at this point in the history
Group messages
  • Loading branch information
engelgabriel committed Jun 5, 2015
2 parents 2f04da7 + fec6927 commit 8b3d5f7
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 65 deletions.
31 changes: 29 additions & 2 deletions client/stylesheets/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ a.github-fork {

.messages-box {
position: relative;
margin: 60px 20px 0px;
margin: 60px 20px 0px 0px;
overflow: hidden;
.calc(width, ~'100% - 20px');
.calc(height, ~'100% - 120px');
Expand Down Expand Up @@ -1699,6 +1699,7 @@ a.github-fork {
padding-left: 50px;
position: relative;
line-height: 20px;
margin-left: 20px;
&.with-thumb {
margin-top: 12px;
min-height: 40px;
Expand Down Expand Up @@ -1792,14 +1793,40 @@ a.github-fork {
}
}
}
.time {
.time, .time-single {
font-size: 12px;
position: absolute;
display: inline-block;
color: #888;
left: 6px;
opacity: 0;
}
.time-single {
opacity: 1;
left: -15px;
width: 64px;
.time-single-time {
display: none;
}
.time-single-edited {
text-align: center;
}
}
.message.own:hover {
.time-single {
.time-single-time {
display: block;
}
.time-single-edited {
display: none;
text-align: center;
}
}
.edit-message {
display: inline-block;
}
}

.thumb {
position: absolute;
left: 0;
Expand Down
3 changes: 3 additions & 0 deletions client/views/app/chatMessageDashboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Template.chatMessageDashboard.helpers
username: ->
return this.u.username

messageDate: (date) ->
return moment(date).format('LL')

isSystemMessage: ->
return this.t in ['s', 'p', 'f', 'r', 'au', 'ru', 'ul', 'nu', 'wm']

Expand Down
22 changes: 21 additions & 1 deletion client/views/app/chatMessageDashboard.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<template name="chatMessageDashboard">
<li class="message with-thumb {{own}} {{data.type}}" data-scroll-to-bottom="{{scroll}}">
{{#if dateSeparator}}
<li class="date">
<span>{{messageDate data.ts}}</span>
</li>
{{/if}}
<li class="message {{#unless single}}with-thumb{{/unless}} {{own}} {{data.type}}" data-scroll-to-bottom="{{scroll}}">
{{#with data}}
{{#if isSystemMessage}}
<p class="system">{{{message}}}</p>
{{else}}
{{#unless ../single}}
<a class="thumb user-card-message" href="#" data-username="{{username}}" tabindex="1">
{{> avatar username=username}}
</a>
Expand All @@ -15,12 +21,26 @@
{{/if}}
<i class="icon-pencil edit-message"></i>
</span>
{{/unless}}
{{#if isEditing}}
<div class="input-message-editing-container">
{{> messagePopupConfig getPupupConfig}}
<textarea class="input-message-editing">{{message}}</textarea>
</div>
{{else}}
{{#if ../single}}
<span class="time-single">
<div class="time-single-time">
<i class="icon-pencil edit-message"></i>
{{time}}
</div>
{{#if ets}}
<div class="time-single-edited">
({{_ "edited"}})
</div>
{{/if}}
</span>
{{/if}}
<div>
{{#emojione}}{{preProcessingMessage message}}{{/emojione}}
</div>
Expand Down
60 changes: 14 additions & 46 deletions client/views/app/chatWindowDashboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -71,55 +71,23 @@ Template.chatWindowDashboard.helpers
users: usernames.join " #{t 'general.and'} "
}

newDate: ->
console.log 'chatWindowDashboard.newDate' if window.rocketDebug
messageInfo: (from) ->
collection = ChatMessage

lastMessageDate = window.lastMessageWindow[this.rid]
d = moment(this.ts).format('YYYYMMDD')
if from is 'history'
collection = ChatMessageHistory

window.lastMessageWindow[this.rid] =
mid: this._id
date: d

if not lastMessageDate?
return false

if lastMessageDate.mid is this._id
last = ChatMessage.find({ts: {$lt: this.ts}, t: {$exists: false}}, { sort: { ts: -1 }, limit: 1 }).fetch()[0]
if not last?
return false
lastMessageDate =
mid: last._id
date: moment(last.ts).format('YYYYMMDD')

return lastMessageDate.date isnt d

newDateHistory: ->
console.log 'chatWindowDashboard.newDate' if window.rocketDebug

lastMessageDate = window.lastMessageWindowHistory[this.rid]
d = moment(this.ts).format('YYYYMMDD')

window.lastMessageWindowHistory[this.rid] =
mid: this._id
date: d

if not lastMessageDate?
return false

if lastMessageDate.mid is this._id
last = ChatMessageHistory.find({ts: {$lt: this.ts}, t: {$exists: false}}, { sort: { ts: -1 }, limit: 1 }).fetch()[0]
if not last?
return false
lastMessageDate =
mid: last._id
date: moment(last.ts).format('YYYYMMDD')

return lastMessageDate.date isnt d
last = collection.find({ts: {$lt: this.ts}, t: {$exists: false}}, { sort: { ts: -1 }, limit: 1 }).fetch()[0]
if not last?
return {
single: false
newDay: false
}

messageDate: ->
console.log 'chatWindowDashboard.messageDate' if window.rocketDebug
return moment(this.ts).format('LL')
return {
single: last.u.username is this.u.username and this.ts - last.ts < 30000
newDay: moment(last.ts).format('YYYYMMDD') isnt moment(this.ts).format('YYYYMMDD')
}

roomName: ->
console.log 'chatWindowDashboard.roomName' if window.rocketDebug
Expand Down
28 changes: 12 additions & 16 deletions client/views/app/chatWindowDashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,20 @@ <h2>
{{/if}}
{{#each messagesHistory}}
{{#unless showTyping}}
{{#if newDateHistory}}
<li class="date">
<span>{{messageDate}}</span>
</li>
{{/if}}
{{> chatMessageDashboard data=this}}
{{/unless}}
{{/each}}
{{#each messages}}
{{#unless showTyping}}
{{#if newDate}}
<li class="date">
<span>{{messageDate}}</span>
</li>
{{/if}}
{{> chatMessageDashboard data=this scroll="true"}}
{{#with messageInfo 'history'}}
{{> chatMessageDashboard data=.. single=single dateSeparator=newDay}}
{{/with}}
{{/unless}}
{{/each}}
{{#with messages}}
{{#each .}}
{{#unless showTyping}}
{{#with messageInfo}}
{{> chatMessageDashboard data=.. scroll="true" single=single dateSeparator=newDay}}
{{/with}}
{{/unless}}
{{/each}}
{{/with}}
</ul>
</div>
<div class="new-message not">
Expand Down

0 comments on commit 8b3d5f7

Please sign in to comment.