diff --git a/client/lib/RoomManager.coffee b/client/lib/RoomManager.coffee index c9b445eccf7..61c703c66a1 100644 --- a/client/lib/RoomManager.coffee +++ b/client/lib/RoomManager.coffee @@ -30,9 +30,7 @@ Meteor.startup -> ChatMessage.update {_id: recordAfter._id}, {$set: {tick: new Date}} -onDeleteMessageStream = (eventName, msg) -> - if eventName isnt 'deleteMessage' then return - +onDeleteMessageStream = (msg) -> ChatMessage.remove _id: msg._id @@ -57,7 +55,7 @@ onDeleteMessageStream = (eventName, msg) -> if openedRooms[typeName].rid? msgStream.removeListener openedRooms[typeName].rid - RocketChat.Notifications.unRoom openedRooms[typeName].rid, onDeleteMessageStream + RocketChat.Notifications.unRoom openedRooms[typeName].rid, 'deleteMessage', onDeleteMessageStream openedRooms[typeName].ready = false openedRooms[typeName].active = false @@ -106,7 +104,7 @@ onDeleteMessageStream = (eventName, msg) -> RoomManager.close type + FlowRouter.getParam('name') FlowRouter.go FlowRouter.current().route.name, name: msg.msg - RocketChat.Notifications.onRoom openedRooms[typeName].rid, onDeleteMessageStream + RocketChat.Notifications.onRoom openedRooms[typeName].rid, 'deleteMessage', onDeleteMessageStream Dep.changed() diff --git a/client/lib/msgTyping.coffee b/client/lib/msgTyping.coffee index 20567e99fd2..58aa3fe1529 100644 --- a/client/lib/msgTyping.coffee +++ b/client/lib/msgTyping.coffee @@ -10,9 +10,7 @@ addStream = (room) -> if _.isEmpty usersTyping[room]?.users usersTyping[room] = { users: {} } - RocketChat.Notifications.onRoom room, (type, typing) -> - if type isnt 'typing' then return - + RocketChat.Notifications.onRoom room, 'typing', (typing) -> unless typing?.username is Meteor.user()?.username if typing.start users = usersTyping[room].users diff --git a/packages/rocketchat-lib/client/Notifications.coffee b/packages/rocketchat-lib/client/Notifications.coffee index 6a3e0c3f251..359404c5b30 100644 --- a/packages/rocketchat-lib/client/Notifications.coffee +++ b/packages/rocketchat-lib/client/Notifications.coffee @@ -10,10 +10,10 @@ RocketChat.Notifications = new class @onUser -> console.log "RocketChat.Notifications: onAll", arguments - notifyRoom: (room, args...) -> + notifyRoom: (room, eventName, args...) -> console.log "RocketChat.Notifications: notifyRoom", arguments if @debug is true - args = [room].concat args + args.unshift "#{room}/#{eventName}" @streamRoom.emit.apply @streamRoom, args notifyUser: (userId, args...) -> @@ -26,12 +26,12 @@ RocketChat.Notifications = new class onAll: (callback) -> @streamAll.on 'notify', callback - onRoom: (room, callback) -> + onRoom: (room, eventName, callback) -> console.log 'onRoom' if @debug is true @streamRoom.on room, -> console.log "RocketChat.Notifications: onRoom #{room}", arguments - @streamRoom.on room, callback + @streamRoom.on "#{room}/#{eventName}", callback onUser: (callback) -> @streamUser.on Meteor.userId(), callback @@ -40,8 +40,8 @@ RocketChat.Notifications = new class unAll: (callback) -> @streamAll.removeListener 'notify', callback - unRoom: (room, callback) -> - @streamRoom.removeListener room, callback + unRoom: (room, eventName, callback) -> + @streamRoom.removeListener "#{room}/#{eventName}", callback unUser: (callback) -> @streamUser.removeListener Meteor.userId(), callback diff --git a/packages/rocketchat-lib/server/Notifications.coffee b/packages/rocketchat-lib/server/Notifications.coffee index c2d7170ffa6..7c3173f33a8 100644 --- a/packages/rocketchat-lib/server/Notifications.coffee +++ b/packages/rocketchat-lib/server/Notifications.coffee @@ -13,20 +13,18 @@ RocketChat.Notifications = new class @streamAll.permissions.read -> return @userId? @streamRoom.permissions.write -> return @userId? - @streamRoom.permissions.read (event) -> + @streamRoom.permissions.read (eventName) -> if not @userId? then return false - if event is 'notify' then return true + roomId = eventName.split('/')[0] user = Meteor.users.findOne @userId, {fields: {username: 1}} - return ChatRoom.findOne({_id: event, usernames: user.username}, {fields: {_id: 1}})? + return ChatRoom.findOne({_id: roomId, usernames: user.username}, {fields: {_id: 1}})? @streamUser.permissions.write -> return @userId? - @streamUser.permissions.read (event) -> + @streamUser.permissions.read (eventName) -> if not @userId? then return false - return event is 'notify' or event is @userId - notifyAll: (args...) -> console.log 'notifyAll', arguments if @debug is true @@ -34,10 +32,10 @@ RocketChat.Notifications = new class args.unshift 'notify' @streamAll.emit.apply @streamAll, args - notifyRoom: (room, args...) -> + notifyRoom: (room, eventName, args...) -> console.log 'notifyRoom', arguments if @debug is true - args.unshift room + args.unshift "#{room}/#{eventName}" @streamRoom.emit.apply @streamRoom, args notifyUser: (userId, args...) ->