diff --git a/Changelog.md b/Changelog.md index a7add57e1..a827350e5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -12,6 +12,7 @@ Note: Although this is a minor release, the configuration file changed because t * Load jQuery in the head on mobile [#7086](https://github.com/diaspora/diaspora/pull/7086) * Use translation for NodeInfo services [#7102](https://github.com/diaspora/diaspora/pull/7102) * Adopt new Mapbox tile URIs [#7066](https://github.com/diaspora/diaspora/pull/7066) +* Refactored post interactions on the single post view [#7089](https://github.com/diaspora/diaspora/pull/7089) ## Bug fixes * Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) diff --git a/app/assets/javascripts/app/views/comment_stream_view.js b/app/assets/javascripts/app/views/comment_stream_view.js index 24f05ee93..0119b3329 100644 --- a/app/assets/javascripts/app/views/comment_stream_view.js +++ b/app/assets/javascripts/app/views/comment_stream_view.js @@ -13,9 +13,8 @@ app.views.CommentStream = app.views.Base.extend({ "click .toggle_post_comments": "expandComments" }, - initialize: function(options) { - this.commentTemplate = options.commentTemplate; - + initialize: function() { + this.CommentView = app.views.Comment; this.setupBindings(); }, @@ -84,7 +83,7 @@ app.views.CommentStream = app.views.Base.extend({ // on post ownership in the Comment view. comment.set({parent : this.model.toJSON()}); - var commentHtml = new app.views.Comment({model: comment}).render().el; + var commentHtml = new this.CommentView({model: comment}).render().el; var commentBlocks = this.$(".comments div.comment.media"); this._moveInsertPoint(comment.get("created_at"), commentBlocks); if (this._insertPoint >= commentBlocks.length) { diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js index 63ef065f6..49ddf11db 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_comment_stream.js @@ -4,7 +4,10 @@ app.views.SinglePostCommentStream = app.views.CommentStream.extend({ tooltipSelector: "time, .control-icons a", initialize: function(){ + this.CommentView = app.views.ExpandedComment; $(window).on('hashchange',this.highlightPermalinkComment); + this.setupBindings(); + this.model.comments.on("reset", this.render, this); }, highlightPermalinkComment: function() { @@ -24,16 +27,6 @@ app.views.SinglePostCommentStream = app.views.CommentStream.extend({ _.defer(this.highlightPermalinkComment); }, - appendComment: function(comment) { - // Set the post as the comment's parent, so we can check - // on post ownership in the Comment view. - comment.set({parent : this.model.toJSON()}); - - this.$(".comments").append(new app.views.ExpandedComment({ - model: comment - }).render().el); - }, - presenter: function(){ return _.extend(this.defaultPresenter(), { moreCommentsCount : 0, diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_interaction_counts.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_interaction_counts.js new file mode 100644 index 000000000..42348627c --- /dev/null +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_interaction_counts.js @@ -0,0 +1,22 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +app.views.SinglePostInteractionCounts = app.views.Base.extend({ + templateName: "single-post-viewer/single-post-interaction-counts", + tooltipSelector: ".avatar.micro", + + initialize: function() { + this.model.interactions.on("change", this.render, this); + }, + + presenter: function() { + var interactions = this.model.interactions; + return { + likes: interactions.likes.toJSON(), + reshares: interactions.reshares.toJSON(), + commentsCount: interactions.commentsCount(), + likesCount: interactions.likesCount(), + resharesCount: interactions.resharesCount() + }; + } +}); +// @license-end diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js index 9549a74a5..ec9ea8f2f 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_interactions.js @@ -2,28 +2,19 @@ app.views.SinglePostInteractions = app.views.Base.extend({ templateName: "single-post-viewer/single-post-interactions", - tooltipSelector: ".avatar.micro", className: "framed-content", subviews: { - '#comments': 'commentStreamView' + "#comments": "commentStreamView", + "#interaction-counts": "interactionCountsView" }, - initialize : function() { - this.model.interactions.on('change', this.render, this); - this.commentStreamView = new app.views.SinglePostCommentStream({model: this.model}); + commentStreamView: function() { + return new app.views.SinglePostCommentStream({model: this.model}); }, - presenter : function(){ - var interactions = this.model.interactions; - return { - likes : interactions.likes.toJSON(), - comments : interactions.comments.toJSON(), - reshares : interactions.reshares.toJSON(), - commentsCount : interactions.commentsCount(), - likesCount : interactions.likesCount(), - resharesCount : interactions.resharesCount(), - }; - }, + interactionCountsView: function() { + return new app.views.SinglePostInteractionCounts({model: this.model}); + } }); // @license-end diff --git a/app/assets/templates/single-post-viewer/single-post-interaction-counts_tpl.jst.hbs b/app/assets/templates/single-post-viewer/single-post-interaction-counts_tpl.jst.hbs new file mode 100644 index 000000000..221274487 --- /dev/null +++ b/app/assets/templates/single-post-viewer/single-post-interaction-counts_tpl.jst.hbs @@ -0,0 +1,42 @@ +{{#if resharesCount}} +
+{{/if}} +{{#if likesCount}} +
{{t "comments.no_comments" }}
+