Skip to content
Snippets Groups Projects
Commit 48f6e32c authored by Jens Theeß's avatar Jens Theeß
Browse files

Notifications are more consistent (#1068).

- HTML notifications are shown when the user has selected the room of the message but the chat window does not have the focus.
- HTML notification and new message sound use the same condition.
- The unread count is always updated if the chat window does not have the focus.
parent a56e7b85
No related branches found
No related tags found
No related merge requests found
# Show notifications and play a sound for new messages.
# We trust the server to only send notifications for interesting messages, e.g. direct messages or
# group messages in which the user is mentioned.
Meteor.startup -> Meteor.startup ->
RocketChat.Notifications.onUser 'notification', (data) -> RocketChat.Notifications.onUser 'notification', (notification) ->
KonchatNotification.showDesktop data
openedRoomId = undefined
if FlowRouter.getRouteName() in ['channel', 'group', 'direct']
openedRoomId = Session.get 'openedRoom'
# This logic is duplicated in /client/startup/unread.coffee.
hasFocus = readMessage.isEnable()
messageIsInOpenedRoom = openedRoomId is notification.payload.rid
if !(hasFocus and messageIsInOpenedRoom)
# Play a sound.
KonchatNotification.newMessage()
# Show a notification.
KonchatNotification.showDesktop notification
Meteor.startup ->
ChatSubscription.find({}, { fields: { unread: 1 } }).observeChanges
changed: (id, fields) ->
if fields.unread and fields.unread > 0
KonchatNotification.newMessage()
Meteor.startup -> Meteor.startup ->
Tracker.autorun -> Tracker.autorun ->
...@@ -14,18 +7,26 @@ Meteor.startup -> ...@@ -14,18 +7,26 @@ Meteor.startup ->
subscriptions = ChatSubscription.find({open: true}, { fields: { unread: 1, alert: 1, rid: 1, t: 1, name: 1, ls: 1 } }) subscriptions = ChatSubscription.find({open: true}, { fields: { unread: 1, alert: 1, rid: 1, t: 1, name: 1, ls: 1 } })
rid = undefined openedRoomId = undefined
Tracker.nonreactive -> Tracker.nonreactive ->
if FlowRouter.getRouteName() in ['channel', 'group', 'direct'] if FlowRouter.getRouteName() in ['channel', 'group', 'direct']
rid = Session.get 'openedRoom' openedRoomId = Session.get 'openedRoom'
for subscription in subscriptions.fetch() for subscription in subscriptions.fetch()
if subscription.rid is rid and (subscription.alert or subscription.unread > 0)
readMessage.readNow() if subscription.alert or subscription.unread > 0
else # This logic is duplicated in /client/notifications/notification.coffee.
unreadCount += subscription.unread hasFocus = readMessage.isEnable()
if subscription.alert is true subscriptionIsTheOpenedRoom = openedRoomId is subscription.rid
unreadAlert = '•' if hasFocus and subscriptionIsTheOpenedRoom
# The user has probably read all messages in this room.
# TODO: readNow() should return whether it has actually marked the room as read.
readMessage.readNow()
else
# Increment the total unread count.
unreadCount += subscription.unread
if subscription.alert is true
unreadAlert = '•'
readMessage.refreshUnreadMark(subscription.rid) readMessage.refreshUnreadMark(subscription.rid)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment