-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Expand file tree
/
Copy pathNotifications.coffee
More file actions
66 lines (43 loc) · 1.78 KB
/
Notifications.coffee
File metadata and controls
66 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
RocketChat.Notifications = new class
constructor: ->
self = @
@debug = false
@streamAll = new Meteor.Stream 'notify-all'
@streamRoom = new Meteor.Stream 'notify-room'
@streamUser = new Meteor.Stream 'notify-user'
@streamAll.permissions.write -> return false
@streamAll.permissions.read -> return @userId?
@streamRoom.permissions.write -> return false
@streamRoom.permissions.read (eventName) ->
if not @userId? then return false
roomId = eventName.split('/')[0]
user = Meteor.users.findOne @userId, {fields: {username: 1}}
return RocketChat.models.Rooms.findOneByIdContainigUsername(roomId, user.username, {fields: {_id: 1}})?
@streamUser.permissions.write -> return @userId?
@streamUser.permissions.read (eventName) ->
userId = eventName.split('/')[0]
return @userId? and @userId is userId
notifyAll: (eventName, args...) ->
console.log 'notifyAll', arguments if @debug is true
args.unshift eventName
@streamAll.emit.apply @streamAll, args
notifyRoom: (room, eventName, args...) ->
console.log 'notifyRoom', arguments if @debug is true
args.unshift "#{room}/#{eventName}"
@streamRoom.emit.apply @streamRoom, args
notifyUser: (userId, eventName, args...) ->
console.log 'notifyUser', arguments if @debug is true
args.unshift "#{userId}/#{eventName}"
@streamUser.emit.apply @streamUser, args
## Permissions for client
# Enable emit for event typing for rooms and add username to event data
func = (eventName, username, typing) ->
console.log arguments
[room, e] = eventName.split('/')
if e isnt 'typing'
return false
user = Meteor.users.findOne(@userId, {fields: {username: 1}})
if not user? or user.username isnt username
return false
return true
RocketChat.Notifications.streamRoom.permissions.write func, false # Prevent Cache