diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index b086f3127..50936ef70 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -17,9 +17,7 @@ = @aspects.to_sentence = render 'shared/publisher', :selected_aspects => @aspects, :aspect_ids => aspect_ids, :aspect => @aspect - -- if posts.length == 0 - = render 'aspects/no_posts_message' += render 'aspects/no_posts_message' - if current_user.contacts.size < 2 = render 'aspects/no_contacts_message' diff --git a/app/views/aspects/_no_posts_message.haml b/app/views/aspects/_no_posts_message.haml index 3891b99b4..3c9ca18aa 100644 --- a/app/views/aspects/_no_posts_message.haml +++ b/app/views/aspects/_no_posts_message.haml @@ -2,5 +2,5 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -#no_posts.empty_message +#no_posts.hidden.empty_message = t('.start_talking') diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index e4891b2da..a41607636 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,7 +1,6 @@ -WebSocketReceiver.processComment("<%= @comment.post.guid %>", +ContentUpdater.addCommentToPost("<%= @comment.post.guid %>", "<%= @comment.guid%>", - "<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>", - false); + "<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>"); Diaspora.page .stream diff --git a/app/views/likes/update.js.erb b/app/views/likes/update.js.erb index 439b93ce9..39e6bc854 100644 --- a/app/views/likes/update.js.erb +++ b/app/views/likes/update.js.erb @@ -1,2 +1,2 @@ $(".like_action", "#<%=@like.target.guid%>").first().html("<%= escape_javascript(like_action(@like.target))%>"); -WebSocketReceiver.processLike("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes_count, :target_type => @like.target_type)) %>"); +ContentUpdater.addLikesToPost("<%=@like.target.guid%>", "<%= escape_javascript(render("likes/likes_container", :target_id => @like.target_id, :likes_count => @like.target.likes_count, :target_type => @like.target_type)) %>"); diff --git a/public/javascripts/content-updater.js b/public/javascripts/content-updater.js index 158eb9362..306975035 100644 --- a/public/javascripts/content-updater.js +++ b/public/javascripts/content-updater.js @@ -23,13 +23,32 @@ var ContentUpdater = { } }, - addLikesToPost: function(postGUID, html) { - var post = $("#" + postGUID); + removePostFromStream: function(postGUID) { + $("#" + postGUID).fadeOut(400, function() { + $(this).remove(); + }); - $(".likes_container", post) + if(!$("#main_stream .stream_element").length) { + $("#no_posts").removeClass("hidden"); + } + }, + + addCommentToPost: function(postGUID, commentGUID, html) { + var post = $("#" + postGUID), + comments = $("ul.comments", post); + + if($("#" + commentGUID, post).length) { return; } + + $(html).appendTo(comments).fadeIn("fast"); + + Diaspora.page.timeAgo.updateTimeAgo(); + Diaspora.page.directionDetector.updateBinds(); + }, + + addLikesToPost: function(postGUID, html) { + $(".likes_container", "#" + postGUID) .fadeOut("fast") .html(html) .fadeIn("fast"); } - }; diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index ec00e0926..367be8c3a 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -1,146 +1,41 @@ -var WebSocketReceiver = { +var WSR = WebSocketReceiver = { initialize: function(url) { - var ws = new WebSocket(url); - WSR.socket = ws; + WSR.socket = new WebSocket(url); - //Attach onmessage to websocket - ws.onmessage = WSR.onMessage; - ws.onclose = function() { - if (websocket_enabled) { - /* Diaspora.widgets.notifications.showNotification({ - html: '
" + str); } -}; -var WSR = WebSocketReceiver; - +}; \ No newline at end of file diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index e4d84ef01..6014e0d3a 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2361,10 +2361,6 @@ ul.show_comments, :color #eee :border 1px solid #ccc -.webfinger_form - input[type='search'] - :width 100% - #sort_by :float right :color #777 diff --git a/spec/javascripts/content-updater-spec.js b/spec/javascripts/content-updater-spec.js index 4325056a9..fd548ad68 100644 --- a/spec/javascripts/content-updater-spec.js +++ b/spec/javascripts/content-updater-spec.js @@ -29,4 +29,67 @@ describe("ContentUpdater", function() { expect($("#no_posts").length).toEqual(0); }); }); + + describe("removePostFromStream", function() { + var post, postGUID; + beforeEach(function() { + spec.loadFixture("aspects_index_with_posts"); + post = $(".stream_element:first"), + postGUID = post.attr("id"); + + $.fx.off = true; + }); + + it("removes the post from the stream", function() { + expect($("#" + postGUID).length).toEqual(1); + ContentUpdater.removePostFromStream(postGUID); + expect($("#" + postGUID).length).toEqual(0); + }); + + it("shows the div that says you have no posts if there are no more post", function() { + $("#main_stream .stream_element").slice(1).remove(); + expect($("#no_posts")).toHaveClass("hidden"); + ContentUpdater.removePostFromStream(postGUID); + expect($("#no_posts")).not.toHaveClass("hidden"); + }); + + afterEach(function() { + $.fx.off = false; + }); + }); + + describe("addCommentToPost", function() { + var post, postGUID; + beforeEach(function() { + spec.loadFixture("aspects_index_with_posts"); + post = $(".stream_element:first"), + postGUID = post.attr("id"); + }); + + it("adds a comment to a post only if it doesn't already exist", function() { + var comments = post.find("ul.comments li"); + + expect(comments.length).toEqual(0); + ContentUpdater.addCommentToPost(postGUID, "YEAH", "
1 like
"); + expect(post.find(".likes .likes_container").html()).toEqual("1 like
"); + }); + }); });