Skip to content
Snippets Groups Projects
Commit e8413a5c authored by Rodrigo Nascimento's avatar Rodrigo Nascimento
Browse files

Keep notifications if window don't has focus

parent df9e1f59
No related merge requests found
Meteor.startup ->
$(window).on 'focus', ->
if FlowRouter.getRouteName() is 'room'
rid = FlowRouter.getParam '_id'
if rid?
subscription = ChatSubscription.findOne rid: rid
if subscription? and (subscription.alert is true or subscription.unread > 0)
Meteor.call 'readMessages', rid
\ No newline at end of file
......@@ -12,12 +12,19 @@ Meteor.startup ->
unreadCount = 0
unreadAlert = false
subscriptions = ChatSubscription.find({}, { fields: { unread: 1, alert: 1 } })
subscriptions = ChatSubscription.find({}, { fields: { unread: 1, alert: 1, rid: 1 } })
rid = undefined
if FlowRouter.getRouteName() is 'room'
rid = FlowRouter.getParam '_id'
for subscription in subscriptions.fetch()
unreadCount += subscription.unread
if subscription.alert is true
unreadAlert = '•'
if subscription.rid is rid and (subscription.alert or subscription.unread > 0) and document.hasFocus()
Meteor.call 'readMessages', subscription.rid
else
unreadCount += subscription.unread
if subscription.alert is true
unreadAlert = '•'
if unreadCount > 0
if unreadCount > 999
......
Template.chatRoomItem.helpers
alert: ->
return this.alert if (not FlowRouter.getParam('_id')) or FlowRouter.getParam('_id') isnt this.rid
if FlowRouter.getParam('_id') isnt this.rid or not document.hasFocus()
return this.alert
unread: ->
return this.unread if (not FlowRouter.getParam('_id')) or FlowRouter.getParam('_id') isnt this.rid
if (FlowRouter.getParam('_id') isnt this.rid or not document.hasFocus()) and this.unread > 0
return this.unread
isDirectRoom: ->
return this.t is 'd'
......@@ -24,8 +26,6 @@ Template.chatRoomItem.helpers
active: ->
if FlowRouter.getParam('_id')? and FlowRouter.getParam('_id') is this.rid
if this.alert or this.unread > 0
Meteor.call 'readMessages', this.rid
return 'active'
canLeave: ->
......
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