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

Commit

Permalink
Push "New Message Notification"
Browse files Browse the repository at this point in the history
  • Loading branch information
dipth committed Dec 12, 2011
1 parent 558fbc3 commit 92e844d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/messages.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<blockquote>' + event.excerpt + '</blockquote><a href="' + event.url + '" class="btn success small">Read</a>'
sticky: true
6 changes: 6 additions & 0 deletions app/models/message_observer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 92e844d

Please sign in to comment.