Init join of stream destination and event type

pull/725/head
Rodrigo Nascimento 11 years ago
parent 5e3d683285
commit ec14b659d1
  1. 8
      client/lib/RoomManager.coffee
  2. 4
      client/lib/msgTyping.coffee
  3. 12
      packages/rocketchat-lib/client/Notifications.coffee
  4. 14
      packages/rocketchat-lib/server/Notifications.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()

@ -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

@ -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

@ -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...) ->

Loading…
Cancel
Save