Revert "Clean up WSR, add comment processing to ContentUpdater, add comment fixture, update post processing spec"
This reverts commit bd74ab4acc.
This reproducable breaks functionallity (comments). Please do not push WIP/not working stuff to master. To continue work just revert this revert. Thanks
This commit is contained in:
parent
bd74ab4acc
commit
73c96ea8f0
6 changed files with 107 additions and 149 deletions
|
|
@ -63,19 +63,18 @@ module SocketsHelper
|
||||||
Rails.logger.error("event=socket_render status=fail user=#{user.diaspora_handle} object=#{object.id.to_s}")
|
Rails.logger.error("event=socket_render status=fail user=#{user.diaspora_handle} object=#{object.id.to_s}")
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
action_hash = {
|
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||||
:class =>object.class.to_s.underscore.pluralize,
|
|
||||||
:html => v,
|
|
||||||
:post_id => obj_id(object)
|
|
||||||
}
|
|
||||||
action_hash.merge! opts
|
action_hash.merge! opts
|
||||||
|
|
||||||
if object.is_a? Photo
|
if object.is_a? Photo
|
||||||
action_hash[:photo_hash] = object.thumb_hash
|
action_hash[:photo_hash] = object.thumb_hash
|
||||||
end
|
end
|
||||||
|
|
||||||
if object.is_a? Comment
|
if object.is_a? Comment
|
||||||
|
post = object.post
|
||||||
action_hash[:comment_id] = object.id
|
action_hash[:comment_id] = object.id
|
||||||
|
action_hash[:my_post?] = (post.author.owner_id == uid)
|
||||||
|
action_hash[:post_guid] = post.guid
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if object.is_a? Like
|
if object.is_a? Like
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
WebSocketReceiver.processComment({
|
WebSocketReceiver.processComment(<%= @comment.post_id %>,
|
||||||
post_id: <%= @comment.post_id %>,
|
<%= @comment.id %>,
|
||||||
comment_id: <%= @comment.id %>,
|
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>",
|
||||||
html: "<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>",
|
false);
|
||||||
options: false
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,19 @@
|
||||||
/* Copyright (c) 2010, Diaspora Inc. This file is
|
/* Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
* licensed under the Affero General Public License version 3 or later. See
|
* licensed under the Affero General Public License version 3 or later. See
|
||||||
* the COPYRIGHT file.
|
* the COPYRIGHT file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var ContentUpdater = {
|
var ContentUpdater = {
|
||||||
elementWithGuid: function(selector, guid) {
|
addPostToStream: function(html) {
|
||||||
return $(selector + "[data-guid='" + guid + "']");
|
|
||||||
},
|
|
||||||
|
|
||||||
commentDoesNotExist: function(commentId) {
|
|
||||||
return (ContentUpdater.elementWithGuid(".comment", commentId).length === 0);
|
|
||||||
},
|
|
||||||
|
|
||||||
postDoesNotExist: function(postId) {
|
|
||||||
return (ContentUpdater.elementWithGuid(".stream_element", postId).length === 0);
|
|
||||||
},
|
|
||||||
|
|
||||||
addPostToStream: function(postId, html) {
|
|
||||||
var streamElement = $(html);
|
var streamElement = $(html);
|
||||||
|
var postId = streamElement.attr("data-guid");
|
||||||
|
|
||||||
if (ContentUpdater.postDoesNotExist(postId)) {
|
if($(".stream_element[data-guid='" + postId + "']").length === 0) {
|
||||||
if ($("#no_posts").length) {
|
if($("#no_posts").length) {
|
||||||
$("#no_posts").detach();
|
$("#no_posts").detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
streamElement.prependTo("#main_stream").fadeIn("fast", function() {
|
streamElement.prependTo("#main_stream:not('.show')").fadeIn("fast", function() {
|
||||||
streamElement.find("label").inFieldLabels();
|
streamElement.find("label").inFieldLabels();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -31,48 +21,5 @@ var ContentUpdater = {
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
addCommentToPost: function(commentId, postId, html) {
|
|
||||||
if (ContentUpdater.commentDoesNotExist(commentId)) {
|
|
||||||
var post = ContentUpdater.elementWithGuid(".stream_element", postId),
|
|
||||||
newComment = $(html),
|
|
||||||
commentsContainer = $(".comments", post),
|
|
||||||
comments = commentsContainer.find(".comment.posted"),
|
|
||||||
showCommentsToggle = $(".show_post_comments", post);
|
|
||||||
|
|
||||||
if(comments.length === 0) {
|
|
||||||
comments
|
|
||||||
.last()
|
|
||||||
.after(
|
|
||||||
newComment.fadeIn("fast")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
commentsContainer
|
|
||||||
.find("li")
|
|
||||||
.last()
|
|
||||||
.before(
|
|
||||||
newComment.fadeIn("fast")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (showCommentsToggle.length > 0) {
|
|
||||||
showCommentsToggle.html(
|
|
||||||
showCommentsToggle.html().replace(/\d+/, comments.length)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (comments.is(":not(:visible)")) {
|
|
||||||
showCommentsToggle.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
$(".show_comments", post).removeClass('hidden');
|
|
||||||
|
|
||||||
Diaspora.widgets.publish("stream/commentAdded", [postId, commentId]);
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
var WebSocketReceiver = {
|
var WebSocketReceiver = {
|
||||||
initialize: function(url) {
|
initialize: function(url) {
|
||||||
this.debuggable = true;
|
var ws = new WebSocket(url);
|
||||||
this.url = url;
|
WSR.socket = ws;
|
||||||
this.socket = new WebSocket(url);
|
|
||||||
|
|
||||||
this.socket.onmessage = WSR.onMessage;
|
//Attach onmessage to websocket
|
||||||
this.socket.onclose = function() {
|
ws.onmessage = WSR.onMessage;
|
||||||
|
ws.onclose = function() {
|
||||||
Diaspora.widgets.notifications.showNotification({
|
Diaspora.widgets.notifications.showNotification({
|
||||||
html: '<div class="notification">' +
|
html: '<div class="notification">' +
|
||||||
Diaspora.widgets.i18n.t("web_sockets.disconnected") +
|
Diaspora.widgets.i18n.t("web_sockets.disconnected") +
|
||||||
|
|
@ -13,38 +13,43 @@ var WebSocketReceiver = {
|
||||||
incrementCount: false
|
incrementCount: false
|
||||||
});
|
});
|
||||||
|
|
||||||
WSR.debug("Socket closed");
|
WSR.debug("socket closed");
|
||||||
|
};
|
||||||
|
ws.onopen = function() {
|
||||||
|
ws.send(location.pathname);
|
||||||
|
WSR.debug("connected...");
|
||||||
};
|
};
|
||||||
|
|
||||||
this.socket.onopen = $.proxy(function() {
|
|
||||||
this.socket.send(location.pathname);
|
|
||||||
WSR.debug("Connected to " + this.url + "...");
|
|
||||||
}, this);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onMessage: function(evt) {
|
onMessage: function(evt) {
|
||||||
var message = jQuery.parseJSON(evt.data);WSR.debug("WebSocket received " + message.class, message)
|
var obj = jQuery.parseJSON(evt.data);
|
||||||
|
|
||||||
if(message.class.match(/^notifications/)) {
|
if(obj['class'].match(/^notifications/)) {
|
||||||
WebSocketReceiver.processNotification(message);
|
WebSocketReceiver.processNotification(obj);
|
||||||
}
|
} else if (obj['class'] == 'people') {
|
||||||
else if(message.class === "people") {
|
WSR.debug("got a " + obj['class']);
|
||||||
WebSocketReceiver.processPerson(message);
|
WebSocketReceiver.processPerson(obj);
|
||||||
}
|
|
||||||
else {
|
} else {
|
||||||
if(message.class === "retractions") {
|
WSR.debug("got a " + obj['class'] + " for aspects " + obj.aspect_ids);
|
||||||
WebSocketReceiver.processRetraction(message.post_id);
|
|
||||||
|
if (obj['class']=="retractions") {
|
||||||
|
WebSocketReceiver.processRetraction(obj.post_id);
|
||||||
|
|
||||||
|
} else if (obj['class']=="comments") {
|
||||||
|
WebSocketReceiver.processComment(obj.post_id, obj.comment_id, obj.html, {
|
||||||
|
'notification': obj.notification,
|
||||||
|
'mine?': obj['mine?'],
|
||||||
|
'my_post?': obj['my_post?']
|
||||||
|
});
|
||||||
|
|
||||||
|
} else if (obj['class']=="likes") {
|
||||||
|
WebSocketReceiver.processLike(obj.post_id, obj.html);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
WebSocketReceiver.processPost(obj['class'], obj.post_id, obj.html, obj.aspect_ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(message.class === "comments") {
|
|
||||||
WebSocketReceiver.processComment(message);
|
|
||||||
}
|
|
||||||
else if(message.class === "likes") {
|
|
||||||
WebSocketReceiver.processLike(message.post_id, message.html);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
WebSocketReceiver.processPost(message.post_id, message.html, message.aspect_ids);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
processPerson: function(response) {
|
processPerson: function(response) {
|
||||||
|
|
@ -69,8 +74,8 @@ var WebSocketReceiver = {
|
||||||
Diaspora.widgets.notifications.showNotification(notification);
|
Diaspora.widgets.notifications.showNotification(notification);
|
||||||
},
|
},
|
||||||
|
|
||||||
processRetraction: function(postId){
|
processRetraction: function(post_id){
|
||||||
$("*[data-guid='" + postId + "']").fadeOut(400, function() {
|
$("*[data-guid='" + post_id + "']").fadeOut(400, function() {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
});
|
});
|
||||||
if($("#main_stream")[0].childElementCount === 0) {
|
if($("#main_stream")[0].childElementCount === 0) {
|
||||||
|
|
@ -78,8 +83,42 @@ var WebSocketReceiver = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
processComment: function(comment) {
|
processComment: function(postId, commentId, html, opts) {
|
||||||
ContentUpdater.addCommentToPost(comment.comment_id, comment.post_id, comment.html);
|
|
||||||
|
if( $(".comment[data-guid='"+commentId+"']").length === 0 ) {
|
||||||
|
|
||||||
|
var post = $("*[data-guid='"+postId+"']'"),
|
||||||
|
prevComments = $('.comment.posted', post);
|
||||||
|
|
||||||
|
if(prevComments.length > 0) {
|
||||||
|
prevComments.last().after(
|
||||||
|
$(html).fadeIn("fast", function(){})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$('.comments li:last', post).before(
|
||||||
|
$(html).fadeIn("fast", function(){})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var toggler = $('.show_post_comments', post);
|
||||||
|
|
||||||
|
if(toggler.length > 0){
|
||||||
|
toggler.html(
|
||||||
|
toggler.html().replace(/\d+/,$('.comments', post).find('li').length -1)
|
||||||
|
);
|
||||||
|
|
||||||
|
if( !$(".comments", post).is(':visible') ) {
|
||||||
|
toggler.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $(".show_comments", post).hasClass('hidden') ){
|
||||||
|
$(".show_comments", post).removeClass('hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
},
|
},
|
||||||
|
|
||||||
processLike: function(postId, html) {
|
processLike: function(postId, html) {
|
||||||
|
|
@ -87,7 +126,7 @@ var WebSocketReceiver = {
|
||||||
$(".likes_container", post).fadeOut('fast').html(html).fadeIn('fast');
|
$(".likes_container", post).fadeOut('fast').html(html).fadeIn('fast');
|
||||||
},
|
},
|
||||||
|
|
||||||
processPost: function(postId, html, aspectIds) {
|
processPost: function(className, postId, html, aspectIds) {
|
||||||
if(WebSocketReceiver.onPageForAspects(aspectIds)) {
|
if(WebSocketReceiver.onPageForAspects(aspectIds)) {
|
||||||
ContentUpdater.addPostToStream(postId, html);
|
ContentUpdater.addPostToStream(postId, html);
|
||||||
}
|
}
|
||||||
|
|
@ -99,14 +138,14 @@ var WebSocketReceiver = {
|
||||||
|
|
||||||
onPageForAspects: function(aspectIds) {
|
onPageForAspects: function(aspectIds) {
|
||||||
var streamIds = $('#main_stream').attr('data-guids'),
|
var streamIds = $('#main_stream').attr('data-guids'),
|
||||||
found = false;
|
found = false;
|
||||||
|
|
||||||
$.each(aspectIds, function(index, value) {
|
$.each(aspectIds, function(index, value) {
|
||||||
if(WebSocketReceiver.onStreamForAspect(value, streamIds)) {
|
if(WebSocketReceiver.onStreamForAspect(value, streamIds)) {
|
||||||
found = true;
|
found = true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -114,10 +153,12 @@ var WebSocketReceiver = {
|
||||||
return (streamIds.search(aspectId) != -1);
|
return (streamIds.search(aspectId) != -1);
|
||||||
},
|
},
|
||||||
|
|
||||||
debug: function() {
|
onPageOne: function() {
|
||||||
if(this.debuggable && typeof console !== "undefined") {
|
var c = document.location.search.charAt(document.location.search.length-1);
|
||||||
console.log.apply(console, arguments);
|
return ((c === '') || (c === '1'));
|
||||||
}
|
},
|
||||||
|
debug: function(str) {
|
||||||
|
$("#debug").append("<p>" + str);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var WSR = WebSocketReceiver;
|
var WSR = WebSocketReceiver;
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,6 @@ describe AspectsController do
|
||||||
save_fixture(html_for("body"), "aspects_index_with_posts")
|
save_fixture(html_for("body"), "aspects_index_with_posts")
|
||||||
|
|
||||||
save_fixture(html_for(".stream_element:first"), "status_message_in_stream")
|
save_fixture(html_for(".stream_element:first"), "status_message_in_stream")
|
||||||
save_fixture(html_for(".comment.posted:first"), "comment_on_status_message")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with getting_started = true' do
|
context 'with getting_started = true' do
|
||||||
|
|
|
||||||
|
|
@ -5,56 +5,30 @@
|
||||||
|
|
||||||
describe("ContentUpdater", function() {
|
describe("ContentUpdater", function() {
|
||||||
describe("addPostToStream", function() {
|
describe("addPostToStream", function() {
|
||||||
var $post;
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
$("#jasmine_content").empty();
|
$("#jasmine_content").empty();
|
||||||
spec.loadFixture("aspects_index");
|
spec.loadFixture("aspects_index");
|
||||||
$post = $(spec.fixtureHtml("status_message_in_stream"));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds a post to the stream", function() {
|
it("adds a post to the stream", function() {
|
||||||
var originalPostCount = $(".stream_element").length;
|
var originalPostCount = $(".stream_element").length;
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not add duplicate posts", function() {
|
it("does not add duplicate posts", function() {
|
||||||
var originalPostCount = $(".stream_element").length;
|
var originalPostCount = $(".stream_element").length;
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("removes the div that says you have no posts if it exists", function() {
|
it("removes the div that says you have no posts if it exists", function() {
|
||||||
expect($("#no_posts").length).toEqual(1);
|
expect($("#no_posts").length).toEqual(1);
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($("#no_posts").length).toEqual(0);
|
expect($("#no_posts").length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("fires a custom event (stream/postAdded)", function() {
|
|
||||||
var spy = jasmine.createSpy("stub");
|
|
||||||
Diaspora.widgets.subscribe("stream/postAdded", spy);
|
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"));
|
|
||||||
expect(spy).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("addCommentToPost", function() {
|
|
||||||
var $comment, $post;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
spec.loadFixture("aspects_index");
|
|
||||||
$comment = $(spec.fixtureHtml("comment_on_status_message")),
|
|
||||||
$post = $(spec.fixtureHtml("status_message_in_stream"));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("adds a comment to a post only if it doesnt exist", function() {
|
|
||||||
ContentUpdater.addPostToStream($post.data("guid"), spec.fixtureHtml("status_message_in_stream"))
|
|
||||||
var originalCommentCount = $(".comment.posted").length;
|
|
||||||
ContentUpdater.addCommentToPost($comment.data("guid"), $post.data("guid"), spec.fixtureHtml("comment_on_status_message"));
|
|
||||||
expect($(".comment.posted").length).toEqual(originalCommentCount);
|
|
||||||
ContentUpdater.addCommentToPost("9000786", $post.data("guid"), spec.fixtureHtml("comment_on_status_message"));
|
|
||||||
expect($(".comment.posted").length).toBeGreaterThan(originalCommentCount);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue