Skip to content

Commit

Permalink
Merge pull request #445 from RocketChat/better-push-notifications
Browse files Browse the repository at this point in the history
Better push notifications (DO NOT MERGE!)
  • Loading branch information
engelgabriel committed Aug 12, 2015
2 parents c953881 + bc70049 commit 8333165
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions packages/rocketchat-lib/server/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ RocketChat.sendMessage = (user, message, room) ->
if not user or not message or not room._id
return false

console.log '[functions] RocketChat.sendMessage -> '.green, 'arguments:', arguments

unless message.ts?
message.ts = new Date()

Expand Down Expand Up @@ -78,8 +76,10 @@ RocketChat.sendMessage = (user, message, room) ->
if userOfMention?
Push.send
from: 'push'
title: userOfMention.username
text: "#{userOfMention.username}: #{message.msg}"
title: "@#{user.username}"
text: message.msg
apn:
text: "@#{user.username}:\n#{message.msg}"
badge: 1
sound: 'chime'
payload:
Expand Down Expand Up @@ -136,20 +136,22 @@ RocketChat.sendMessage = (user, message, room) ->
query._id =
$in: mentionIds

usersOfMention = Meteor.users.find(query, {fields: {username: 1}}).fetch()
if usersOfMention.length > 0
for userOfMention in usersOfMention
Push.send
from: 'push'
title: userOfMention.username
text: message.msg
badge: 1
sound: 'chime'
payload:
rid: message.rid
sender: message.u
query:
userId: userOfMention._id
usersOfMention = Meteor.users.find(query, {fields: {_id: 1}}).fetch()
usersOfMentionIds = _.pluck(usersOfMention, '_id');
if usersOfMentionIds.length > 0
Push.send
from: 'push'
title: "##{room.name}"
text: message.msg
apn:
text: "##{room.name}:\n#{message.msg}"
badge: 1
sound: 'chime'
payload:
rid: message.rid
sender: message.u
query:
userId: $in: usersOfMentionIds

###
Update all other subscriptions to alert their owners but witout incrementing
Expand Down
2 changes: 1 addition & 1 deletion server/methods/canAccessRoom.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Meteor.methods
if canAccess isnt true
return false
else
return _.pick room, ['_id', 't', 'name']
return _.pick room, ['_id', 't', 'name', 'usernames']
else
throw new Meteor.Error 'invalid-room', '[methods] canAccessRoom -> Room ID is invalid'

0 comments on commit 8333165

Please sign in to comment.