Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better push notifications 2 #468

Merged
merged 3 commits into from
Aug 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'