Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

Commit

Permalink
Push "Unread Messages Count"
Browse files Browse the repository at this point in the history
  • Loading branch information
dipth committed Dec 12, 2011
1 parent 43f3bb6 commit 558fbc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/assets/javascripts/messages.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
$ ->
window.broadcast_channel.bind 'total_messages_changed', (event) ->
$('#total_messages').html(event.value)

if window.private_channel
window.private_channel.bind 'unread_messages_changed', (event) ->
$('.unreadMessages').html(event.value).addClass('important')
1 change: 1 addition & 0 deletions app/models/message_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class MessageObserver < ActiveRecord::Observer

def after_create(message)
Pusher['broadcast'].trigger!('total_messages_changed', {:value => pluralize(Message.count, 'message', 'messages')})
Pusher["private-user_#{message.recipient.id}"].trigger('unread_messages_changed', {:value => message.recipient.received_messages.unread.count})
end
end

0 comments on commit 558fbc3

Please sign in to comment.