diff --git a/app/assets/javascripts/messages.js.coffee b/app/assets/javascripts/messages.js.coffee index 4098756..dd4a79d 100644 --- a/app/assets/javascripts/messages.js.coffee +++ b/app/assets/javascripts/messages.js.coffee @@ -9,3 +9,9 @@ $ -> if window.private_channel window.private_channel.bind 'unread_messages_changed', (event) -> $('.unreadMessages').html(event.value).addClass('important') + + window.private_channel.bind 'new_message', (event) -> + $.gritter.add + title: "You've received a new message from " + event.sender + text: '
' + event.excerpt + 'Read' + sticky: true diff --git a/app/models/message_observer.rb b/app/models/message_observer.rb index 0946dfa..6919a9e 100644 --- a/app/models/message_observer.rb +++ b/app/models/message_observer.rb @@ -4,5 +4,11 @@ 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}) + Pusher["private-user_#{message.recipient.id}"].trigger('new_message', { + :sender => message.sender.username, + :subject => message.subject, + :excerpt => truncate(message.body, :length => 150), + :url => "/messages/#{message.id}" + }) end end