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

Re enable desktop notifications via stream notifications #728

Merged
merged 1 commit into from
Sep 7, 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
25 changes: 16 additions & 9 deletions client/lib/notification.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@
Notification.permission = status

# notificacoes HTML5
showDesktop: (room, msg) ->
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy')
roomName = room.name + ' - ' + RocketChat.settings.get 'Site_Name'
showDesktop: (notification) ->
if not window.document.hasFocus?() and Meteor.user().status isnt 'busy'
if window.Notification && Notification.permission == "granted"
n = new Notification roomName,
icon: '/images/rocket-chat-logo-square.png'
body: _.stripTags(msg)
n = new Notification notification.title,
icon: '/images/logo/1024x1024-circle.png'
body: _.stripTags(notification.text)

n.onclick = ->
$('#chat-window-' + room._id + '.chat-window .chat-title').click()
if notification.payload?.rid?
n.onclick = ->
window.focus()
switch notification.payload.type
when 'd'
FlowRouter.go 'direct', {username: notification.payload.sender.username}
when 'c'
FlowRouter.go 'channel', {name: notification.payload.name}
when 'p'
FlowRouter.go 'group', {name: notification.payload.name}

setTimeout ->
n.close()
, 2000
, 10000

newMessage: ->
unless Session.equals('user_' + Meteor.userId() + '_status', 'busy') or Meteor.user()?.settings?.preferences?.disableNewMessageNotification
Expand Down
3 changes: 3 additions & 0 deletions client/notifications/notification.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Meteor.startup ->
RocketChat.Notifications.onUser 'notification', (data) ->
KonchatNotification.showDesktop data
55 changes: 37 additions & 18 deletions packages/rocketchat-lib/server/sendMessage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,18 @@ RocketChat.sendMessage = (user, message, room, options) ->
$inc:
unread: 1

if Push.enabled is true
userOfMention = Meteor.users.findOne({_id: message.rid.replace(message.u._id, ''), statusConnection: {$ne: 'online'}}, {fields: {username: 1}})
if userOfMention?
userOfMention = Meteor.users.findOne({_id: message.rid.replace(message.u._id, '')}, {fields: {username: 1, statusConnection: 1}})
if userOfMention?
RocketChat.Notifications.notifyUser userOfMention._id, 'notification',
title: "@#{user.username}"
text: message.msg
payload:
rid: message.rid
sender: message.u
type: room.t
name: room.name

if Push.enabled is true and userOfMention.statusConnection isnt 'online'
Push.send
from: 'push'
title: "@#{user.username}"
Expand Down Expand Up @@ -134,23 +143,33 @@ RocketChat.sendMessage = (user, message, room, options) ->
,
multi: true

if Push.enabled is true
query =
statusConnection: {$ne: 'online'}

if mentionIds.indexOf('all') > -1
if room.usernames?.length > 0
query.username =
$in: room.usernames
else
query.username =
$in: []
query =
statusConnection: {$ne: 'online'}

if mentionIds.indexOf('all') > -1
if room.usernames?.length > 0
query.username =
$in: room.usernames
else
query._id =
$in: mentionIds
query.username =
$in: []
else
query._id =
$in: mentionIds

usersOfMentionIds = _.pluck(usersOfMention, '_id');
if usersOfMentionIds.length > 0
for usersOfMentionId in usersOfMentionIds
RocketChat.Notifications.notifyUser usersOfMentionId, 'notification',
title: "@#{user.username} @ ##{room.name}"
text: message.msg
payload:
rid: message.rid
sender: message.u
type: room.t
name: room.name

usersOfMentionIds = _.pluck(usersOfMention, '_id');
if usersOfMentionIds.length > 0
if Push.enabled is true
Push.send
from: 'push'
title: "@#{user.username} @ ##{room.name}"
Expand Down