diff --git a/packages/rocketchat-lib/client/MessageAction.coffee b/packages/rocketchat-lib/client/MessageAction.coffee
index 3aec40bcb3ed1..43af02e468951 100644
--- a/packages/rocketchat-lib/client/MessageAction.coffee
+++ b/packages/rocketchat-lib/client/MessageAction.coffee
@@ -32,6 +32,10 @@ RocketChat.MessageAction = new class
btns[id] = _.extend btns[id], config
buttons.set btns
+ getButtonById = (id) ->
+ allButtons = buttons.get()
+ return allButtons[id]
+
getButtons = (message) ->
allButtons = _.toArray buttons.get()
if message
@@ -50,6 +54,7 @@ RocketChat.MessageAction = new class
removeButton: removeButton
updateButton: updateButton
getButtons: getButtons
+ getButtonById: getButtonById
resetButtons: resetButtons
Meteor.startup ->
@@ -111,4 +116,4 @@ Meteor.startup ->
chatMessages[Session.get('openedRoom')].deleteMsg(message)
validation: (message) ->
return RocketChat.authz.hasAtLeastOnePermission('delete-message', message.rid ) or RocketChat.settings.get('Message_AllowDeleting') and message.u?._id is Meteor.userId()
- order: 2
\ No newline at end of file
+ order: 2
diff --git a/packages/rocketchat-ui-message/message/message.coffee b/packages/rocketchat-ui-message/message/message.coffee
index 2792c4cf8cb74..b934b460ecd41 100644
--- a/packages/rocketchat-ui-message/message/message.coffee
+++ b/packages/rocketchat-ui-message/message/message.coffee
@@ -1,6 +1,4 @@
Template.message.helpers
- actions: ->
- return RocketChat.MessageAction.getButtons(this)
own: ->
return 'own' if this.u?._id is Meteor.userId()
chatops: ->
diff --git a/packages/rocketchat-ui-message/message/message.html b/packages/rocketchat-ui-message/message/message.html
index b602ff943c335..5768abe8696ec 100644
--- a/packages/rocketchat-ui-message/message/message.html
+++ b/packages/rocketchat-ui-message/message/message.html
@@ -22,19 +22,10 @@
{{#if private}}
{{_ "Only_you_can_see_this_message"}}
{{/if}}
- {{#if actions.length}}
-
{{{body}}}
diff --git a/packages/rocketchat-ui-message/message/messageDropdown.html b/packages/rocketchat-ui-message/message/messageDropdown.html
new file mode 100644
index 0000000000000..93468e4bd65a7
--- /dev/null
+++ b/packages/rocketchat-ui-message/message/messageDropdown.html
@@ -0,0 +1,12 @@
+
+
+
+
+ {{#if actions.length}}
+ {{#each actions}}
+
+ {{/each}}
+ {{/if}}
+
+
+
diff --git a/packages/rocketchat-ui-message/package.js b/packages/rocketchat-ui-message/package.js
index f06271a56d727..b62401731bf28 100644
--- a/packages/rocketchat-ui-message/package.js
+++ b/packages/rocketchat-ui-message/package.js
@@ -24,6 +24,7 @@ Package.onUse(function(api) {
api.addFiles('message/message.html', 'client');
api.addFiles("message/messageBox.html", "client");
+ api.addFiles("message/messageDropdown.html", "client");
api.addFiles("message/popup/messagePopup.html", "client");
api.addFiles("message/popup/messagePopupChannel.html", "client");
api.addFiles("message/popup/messagePopupConfig.html", "client");
@@ -38,4 +39,4 @@ Package.onUse(function(api) {
api.addFiles("message/popup/messagePopupEmoji.coffee", "client");
-});
\ No newline at end of file
+});
diff --git a/packages/rocketchat-ui/lib/RoomManager.coffee b/packages/rocketchat-ui/lib/RoomManager.coffee
index a9e8a7a406b3d..ee2ad7308e196 100644
--- a/packages/rocketchat-ui/lib/RoomManager.coffee
+++ b/packages/rocketchat-ui/lib/RoomManager.coffee
@@ -21,13 +21,14 @@ Tracker.autorun ->
Meteor.startup ->
ChatMessage.find().observe
removed: (record) ->
- recordBefore = ChatMessage.findOne {ts: {$lt: record.ts}}, {sort: {ts: -1}}
- if recordBefore?
- ChatMessage.update {_id: recordBefore._id}, {$set: {tick: new Date}}
+ if RoomManager.getOpenedRoomByRid(record.rid)?
+ recordBefore = ChatMessage.findOne {ts: {$lt: record.ts}}, {sort: {ts: -1}}
+ if recordBefore?
+ ChatMessage.update {_id: recordBefore._id}, {$set: {tick: new Date}}
- recordAfter = ChatMessage.findOne {ts: {$gt: record.ts}}, {sort: {ts: 1}}
- if recordAfter?
- ChatMessage.update {_id: recordAfter._id}, {$set: {tick: new Date}}
+ recordAfter = ChatMessage.findOne {ts: {$gt: record.ts}}, {sort: {ts: 1}}
+ if recordAfter?
+ ChatMessage.update {_id: recordAfter._id}, {$set: {tick: new Date}}
onDeleteMessageStream = (msg) ->
@@ -43,7 +44,6 @@ RocketChat.Notifications.onUser 'message', (msg) ->
@RoomManager = new class
- defaultTime = 600000 # 10 minutes
openedRooms = {}
subscription = null
msgStream = new Meteor.Stream 'messages'
@@ -67,12 +67,16 @@ RocketChat.Notifications.onUser 'message', (msg) ->
openedRooms[typeName].ready = false
openedRooms[typeName].active = false
- delete openedRooms[typeName].timeout
+ Blaze.remove openedRooms[typeName].template
delete openedRooms[typeName].dom
+ delete openedRooms[typeName].template
+
+ rid = openedRooms[typeName].rid
+ delete openedRooms[typeName]
+
+ if rid?
+ RoomHistoryManager.clear rid
- if openedRooms[typeName].rid?
- RoomHistoryManager.clear openedRooms[typeName].rid
- ChatMessage.remove rid: openedRooms[typeName].rid
computation = Tracker.autorun ->
for typeName, record of openedRooms when record.active is true
@@ -116,25 +120,29 @@ RocketChat.Notifications.onUser 'message', (msg) ->
Dep.changed()
- setRoomExpireExcept = (except) ->
- if openedRooms[except]?.timeout?
- clearTimeout openedRooms[except].timeout
- delete openedRooms[except].timeout
+ closeOlderRooms = ->
+ maxRoomsOpen = 10
+ if Object.keys(openedRooms).length <= maxRoomsOpen
+ return
- for typeName of openedRooms
- if typeName isnt except and not openedRooms[typeName].timeout?
- openedRooms[typeName].timeout = setTimeout close, defaultTime, typeName
+ roomsToClose = _.sortBy(_.values(openedRooms), 'lastSeen').reverse().slice(maxRoomsOpen)
+ for roomToClose in roomsToClose
+ close roomToClose.typeName
- open = (typeName) ->
+ open = (typeName) ->
if not openedRooms[typeName]?
openedRooms[typeName] =
+ typeName: typeName
active: false
ready: false
unreadSince: new ReactiveVar undefined
- setRoomExpireExcept typeName
+ openedRooms[typeName].lastSeen = new Date
+
+ if openedRooms[typeName].ready
+ closeOlderRooms()
if subscription.ready()
@@ -149,6 +157,11 @@ RocketChat.Notifications.onUser 'message', (msg) ->
return openedRooms[typeName].ready
}
+ getOpenedRoomByRid = (rid) ->
+ for typeName, openedRoom of openedRooms
+ if openedRoom.rid is rid
+ return openedRoom
+
getDomOfRoom = (typeName, rid) ->
room = openedRooms[typeName]
if not room?
@@ -157,7 +170,11 @@ RocketChat.Notifications.onUser 'message', (msg) ->
if not room.dom? and rid?
room.dom = document.createElement 'div'
room.dom.classList.add 'room-container'
- Blaze.renderWithData Template.room, { _id: rid }, room.dom
+ contentAsFunc = (content) ->
+ return -> content
+
+ room.template = Blaze._TemplateWith { _id: rid }, contentAsFunc(Template.room)
+ Blaze.render room.template, room.dom #, nextNode, parentView
return room.dom
@@ -205,3 +222,4 @@ RocketChat.Notifications.onUser 'message', (msg) ->
updateUserStatus: updateUserStatus
onlineUsers: onlineUsers
updateMentionsMarksOfRoom: updateMentionsMarksOfRoom
+ getOpenedRoomByRid: getOpenedRoomByRid
diff --git a/packages/rocketchat-ui/views/app/room.coffee b/packages/rocketchat-ui/views/app/room.coffee
index 015d6eed9276d..e1fe97dec71be 100644
--- a/packages/rocketchat-ui/views/app/room.coffee
+++ b/packages/rocketchat-ui/views/app/room.coffee
@@ -332,9 +332,29 @@ Template.room.events
instance.showUsersOffline.set(!instance.showUsersOffline.get())
'click .message-cog': (e) ->
- message_id = $(e.currentTarget).closest('.message').attr('id')
+ message = @_arguments[1]
$('.message-dropdown:visible').hide()
- $(".messages-box \##{message_id} .message-dropdown").show()
+
+ dropDown = $(".messages-box \##{message._id} .message-dropdown")
+
+ if dropDown.length is 0
+ actions = RocketChat.MessageAction.getButtons message
+
+ el = Blaze.toHTMLWithData Template.messageDropdown,
+ actions: actions
+
+ $(".messages-box \##{message._id} .message-cog-container").append el
+
+ dropDown = $(".messages-box \##{message._id} .message-dropdown")
+
+ dropDown.show()
+
+ 'click .message-dropdown .message-action': (e, t) ->
+ el = $(e.currentTarget)
+
+ button = RocketChat.MessageAction.getButtonById el.data('id')
+ if button?.action?
+ button.action.call @, e, t
'click .message-dropdown-close': ->
$('.message-dropdown:visible').hide()
@@ -416,12 +436,6 @@ Template.room.onCreated ->
@autorun ->
self.subscribe 'fullUserData', Session.get('showUserInfo'), 1
- for button in RocketChat.MessageAction.getButtons()
- if _.isFunction button.action
- evt = {}
- evt["click .#{button.id}"] = button.action
- Template.room.events evt
-
Template.room.onDestroyed ->
RocketChat.TabBar.resetButtons()