diff --git a/client/lib/notification.coffee b/client/lib/notification.coffee index 5b9e7a8a0283..3420c215f67f 100644 --- a/client/lib/notification.coffee +++ b/client/lib/notification.coffee @@ -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 diff --git a/client/notifications/notification.coffee b/client/notifications/notification.coffee new file mode 100644 index 000000000000..2bb8c584fc2a --- /dev/null +++ b/client/notifications/notification.coffee @@ -0,0 +1,3 @@ +Meteor.startup -> + RocketChat.Notifications.onUser 'notification', (data) -> + KonchatNotification.showDesktop data diff --git a/packages/rocketchat-lib/server/sendMessage.coffee b/packages/rocketchat-lib/server/sendMessage.coffee index 790217f59af4..0ead7287a0a7 100644 --- a/packages/rocketchat-lib/server/sendMessage.coffee +++ b/packages/rocketchat-lib/server/sendMessage.coffee @@ -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}" @@ -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}"