User receives notification on new comment on post on any page.
This commit is contained in:
parent
9970ee0e22
commit
bd9aa90278
5 changed files with 68 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,19 +13,24 @@
|
|||
//Attach onmessage to websocket
|
||||
ws.onmessage = function(evt) {
|
||||
var obj = jQuery.parseJSON(evt.data);
|
||||
//console.log(obj);
|
||||
debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']);
|
||||
|
||||
if (obj['class']=="retractions"){
|
||||
processRetraction(obj['post_id']);
|
||||
if(obj['notice']){
|
||||
processNotification(obj['notice']);
|
||||
|
||||
}else if (obj['class']=="comments"){
|
||||
processComment(obj['post_id'], obj['html'])
|
||||
|
||||
}else if (obj['class']=='photos' && onPageForClass('albums')){
|
||||
processPhotoInAlbum(obj['photo_hash'])
|
||||
}else{
|
||||
processPost(obj['class'], obj['html'], obj['aspect_ids'])
|
||||
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'], {'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'])
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
5
app/views/shared/_notification.haml
Normal file
5
app/views/shared/_notification.haml
Normal 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)
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue