User receives notification on new comment on post on any page.

This commit is contained in:
danielvincent 2010-11-05 14:13:28 -07:00
parent 9970ee0e22
commit bd9aa90278
5 changed files with 68 additions and 13 deletions

View file

@ -23,10 +23,21 @@ module SocketsHelper
action_hash[:photo_hash] = object.thumb_hash
end
if object.person && object.person.owner_id == uid
action_hash[:mine?] = true
if object.is_a? Comment
action_hash[:my_post?] = (object.post.person.owner.id == uid)
action_hash[:notification] = notification(object)
end
action_hash[:mine?] = object.person && (object.person.owner.id == uid)
action_hash.to_json
end
def notification(object)
begin
render_to_string(:partial => 'shared/notification', :locals => {:object => object})
rescue Exception => e
Rails.logger.error("web socket notification failed for object #{object.inspect}.")
end
end
end

View file

@ -13,20 +13,25 @@
//Attach onmessage to websocket
ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data);
//console.log(obj);
if(obj['notice']){
processNotification(obj['notice']);
}else{
debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']);
if (obj['class']=="retractions"){
processRetraction(obj['post_id']);
}else if (obj['class']=="comments"){
processComment(obj['post_id'], obj['html'])
processComment(obj['post_id'], obj['html'], {'notification':obj['notification'], 'mine?':obj['mine?'], 'my_post?':obj['my_post?']})
}else if (obj['class']=='photos' && onPageForClass('albums')){
processPhotoInAlbum(obj['photo_hash'])
}else{
processPost(obj['class'], obj['html'], obj['aspect_ids'])
}
}
};
ws.onclose = function() { debug("socket closed"); };
@ -36,6 +41,11 @@
};
});
function processNotification(html){
$('#notification').html(html).fadeIn(200).delay(4000).fadeOut(200, function(){ $(this).html("");});
}
function processRetraction(post_id){
$("*[data-guid='"+post_id+"']").fadeOut(400, function(){$(this).remove()});
if($("#stream")[0].childElementCount == 0){
@ -43,7 +53,7 @@
}
}
function processComment(post_id, html){
function processComment(post_id, html, opts){
post = $("*[data-guid='"+post_id+"']'");
$('.comments li:last', post ).before(
$(html).fadeIn("fast", function(){})
@ -58,6 +68,11 @@
toggler.click();
}
}
if( !opts['mine?'] && opts['my_post?']) {
processNotification(opts['notification']);
}
}
function processPost(className, html, aspectIds){

View file

@ -43,6 +43,9 @@
%header
.container{:style => "position:relative;"}
#notification
#diaspora_text
= link_to "DIASPORA", (current_user ? root_path : new_user_session_path)
%span.sub_text

View file

@ -0,0 +1,5 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
= link_to "New #{object.class.to_s} from #{object.person.real_name}", object_path(object.post)

View file

@ -1472,3 +1472,24 @@ ul.aspects
h3 span.current_gs_step
:color #22C910
#notification
:display none
:position fixed
:bottom 21px
:right 12px
a
:background
:color rgb(30,30,30)
:color rgba(30,30,30,0.9)
:-webkit-box-shadow 0 2px 3px #333
:-webkit-border-radius 5px
:border-radius 5px
:-moz-border-radius 5px
:min-width 200px
:padding 12px
:color #fff