-# Copyright 2010 Diaspora Inc.
-#
-# This file is part of Diaspora.
-#
-# Diaspora is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# Diaspora is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with Diaspora. If not, see
" + str); }; ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}"); //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']); }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']) } }; ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { ws.send(location.pathname); debug("connected..."); }; }); function processRetraction(post_id){ $('#' + post_id ).fadeOut(500, function(){ $(this).remove; }); } function processComment(post_id, html){ post = $('#' + post_id)[0] $(' .comment_set li:last', post ).before( $(html).fadeIn("fast", function(){}) ); toggler = $('.show_post_comments', post) toggler.html( toggler.html().replace(/\d+/,$('.comment_set', post)[0].childElementCount -1)); if( !$(".comments", post).is(':visible') ){ toggler.click(); } } function processPost(className, html, aspectIds){ if(onPageForAspects(aspectIds)){ $("#stream").prepend( $(html).fadeIn("fast", function(){ $("#stream label:first").inFieldLabels(); }) ); } } function processPhotoInAlbum(photoHash){ if (location.href.indexOf(photoHash['album_id']) == -1){ return ; } html = "