Skip to content

Commit

Permalink
Merge pull request #1537 from RocketChat/improvements/performance
Browse files Browse the repository at this point in the history
Improvements/performance
  • Loading branch information
rodrigok committed Dec 1, 2015
2 parents 81cf44c + cdab22d commit 7738f7c
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 46 deletions.
7 changes: 6 additions & 1 deletion packages/rocketchat-lib/client/MessageAction.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,6 +54,7 @@ RocketChat.MessageAction = new class
removeButton: removeButton
updateButton: updateButton
getButtons: getButtons
getButtonById: getButtonById
resetButtons: resetButtons

Meteor.startup ->
Expand Down Expand Up @@ -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
order: 2
2 changes: 0 additions & 2 deletions packages/rocketchat-ui-message/message/message.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Template.message.helpers
actions: ->
return RocketChat.MessageAction.getButtons(this)
own: ->
return 'own' if this.u?._id is Meteor.userId()
chatops: ->
Expand Down
17 changes: 4 additions & 13 deletions packages/rocketchat-ui-message/message/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,10 @@
{{#if private}}
<span class="private">{{_ "Only_you_can_see_this_message"}}</span>
{{/if}}
{{#if actions.length}}
<div class="message-cog-container">
<i class="icon-cog message-cog" aria-label="{{_ "Actions"}}"></i>
<div class="message-dropdown">
<ul>
<li class="message-dropdown-close"><i class=" icon-angle-left" aria-label="{{_ "Close"}}"></i></li>
{{#each actions}}
<li class="{{id}} {{classes}} message-action" title="{{_ i18nLabel}}"><i class="{{icon}}" aria-label="{{_ i18nLabel}}"></i></li>
{{/each}}
</ul>
</div>
</div>
{{/if}}

<div class="message-cog-container">
<i class="icon-cog message-cog" aria-label="{{_ "Actions"}}"></i>
</div>
</span>
<div class="body" dir="auto">
{{{body}}}
Expand Down
12 changes: 12 additions & 0 deletions packages/rocketchat-ui-message/message/messageDropdown.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template name="messageDropdown">
<div class="message-dropdown">
<ul>
<li class="message-dropdown-close"><i class=" icon-angle-left" aria-label="{{_ "Close"}}"></i></li>
{{#if actions.length}}
{{#each actions}}
<li class="{{id}} {{classes}} message-action" title="{{_ i18nLabel}}" data-id="{{id}}"><i class="{{icon}}" aria-label="{{_ i18nLabel}}"></i></li>
{{/each}}
{{/if}}
</ul>
</div>
</template>
3 changes: 2 additions & 1 deletion packages/rocketchat-ui-message/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -38,4 +39,4 @@ Package.onUse(function(api) {
api.addFiles("message/popup/messagePopupEmoji.coffee", "client");


});
});
60 changes: 39 additions & 21 deletions packages/rocketchat-ui/lib/RoomManager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -43,7 +44,6 @@ RocketChat.Notifications.onUser 'message', (msg) ->


@RoomManager = new class
defaultTime = 600000 # 10 minutes
openedRooms = {}
subscription = null
msgStream = new Meteor.Stream 'messages'
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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?
Expand All @@ -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

Expand Down Expand Up @@ -205,3 +222,4 @@ RocketChat.Notifications.onUser 'message', (msg) ->
updateUserStatus: updateUserStatus
onlineUsers: onlineUsers
updateMentionsMarksOfRoom: updateMentionsMarksOfRoom
getOpenedRoomByRid: getOpenedRoomByRid
30 changes: 22 additions & 8 deletions packages/rocketchat-ui/views/app/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7738f7c

Please sign in to comment.