Content updater refactor complete for posts
This commit is contained in:
parent
50e67524c1
commit
a904204f46
4 changed files with 18 additions and 21 deletions
|
|
@ -3,11 +3,12 @@
|
||||||
* the COPYRIGHT file.
|
* the COPYRIGHT file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var ContentUpdates = {
|
var ContentUpdater = {
|
||||||
addPostToStream: function(postId, html) {
|
addPostToStream: function(html) {
|
||||||
if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) {
|
var streamElement = $(html);
|
||||||
var streamElement = $(html);
|
var postId = streamElement.attr("data-guid");
|
||||||
|
|
||||||
|
if($(".stream_element[data-guid='" + postId + "']").length === 0) {
|
||||||
if($("#no_posts").length) {
|
if($("#no_posts").length) {
|
||||||
$("#no_posts").detach();
|
$("#no_posts").detach();
|
||||||
}
|
}
|
||||||
|
|
@ -16,9 +17,7 @@ var ContentUpdates = {
|
||||||
streamElement.find("label").inFieldLabels();
|
streamElement.find("label").inFieldLabels();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Diaspora.widgets.publish("stream/postAdded", [postId]);
|
Diaspora.widgets.publish("stream/postAdded", [postId]);
|
||||||
|
|
||||||
Diaspora.widgets.timeago.updateTimeAgo();
|
Diaspora.widgets.timeago.updateTimeAgo();
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
}
|
}
|
||||||
|
|
@ -128,14 +128,10 @@ var WebSocketReceiver = {
|
||||||
|
|
||||||
processPost: function(className, postId, html, aspectIds) {
|
processPost: function(className, postId, html, aspectIds) {
|
||||||
if(WebSocketReceiver.onPageForAspects(aspectIds)) {
|
if(WebSocketReceiver.onPageForAspects(aspectIds)) {
|
||||||
WebSocketReceiver.addPostToStream(postId, html);
|
ContentUpdater.addPostToStream(postId, html);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addPostToStream: function(postId, html) {
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
onPageForClass: function(className) {
|
onPageForClass: function(className) {
|
||||||
return (location.href.indexOf(className) != -1 );
|
return (location.href.indexOf(className) != -1 );
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -2,30 +2,32 @@
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
describe("ContentUpdates", function() {
|
|
||||||
|
describe("ContentUpdater", function() {
|
||||||
describe("addPostToStream", function() {
|
describe("addPostToStream", function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
$("#jasmine_content").empty();
|
$("#jasmine_content").empty();
|
||||||
spec.loadFixture("aspects_index_with_posts");
|
spec.loadFixture("aspects_index");
|
||||||
});
|
});
|
||||||
|
|
||||||
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;
|
||||||
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($(".stream_element").length).toBeGreaterThan(originalPostCount);
|
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not add duplicate posts", function() {
|
it("does not add duplicate posts", function() {
|
||||||
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
|
||||||
var originalPostCount = $(".stream_element").length;
|
var originalPostCount = $(".stream_element").length;
|
||||||
ContentUpdates.addPostToStream("guid", spec.fixtureHtml("status_message_in_stream"));
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
expect($(".stream_element").length).toEqual(originalPostCount);
|
expect($(".stream_element").length).toEqual(originalPostCount + 1);
|
||||||
|
ContentUpdater.addPostToStream(spec.fixtureHtml("status_message_in_stream"));
|
||||||
|
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() {
|
||||||
spec.loadFixture("aspects_index");
|
|
||||||
expect($("#no_posts").length).toEqual(1);
|
expect($("#no_posts").length).toEqual(1);
|
||||||
ContentUpdates.addPostToStream("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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -40,7 +40,7 @@ src_files:
|
||||||
- public/javascripts/validation.js
|
- public/javascripts/validation.js
|
||||||
- public/javascripts/rails.js
|
- public/javascripts/rails.js
|
||||||
- public/javascripts/aspect-filters.js
|
- public/javascripts/aspect-filters.js
|
||||||
- public/javascripts/content-updates.js
|
- public/javascripts/content-updater.js
|
||||||
# stylesheets
|
# stylesheets
|
||||||
#
|
#
|
||||||
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue