diff --git a/Changelog.md b/Changelog.md index b0422e154..6e5d30680 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,10 +14,11 @@ * Make the session cookies HttpOnly again [#7041](https://github.com/diaspora/diaspora/pull/7041) ## Bug fixes -* Post comments no longer get collapsed when interacting with a post [#7045](https://github.com/diaspora/diaspora/pull/7045) +* Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) ## Features -* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7045](https://github.com/diaspora/diaspora/pull/7045) +* Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045) +* The "subscribe" indicator on a post now gets toggled when you like or rehsare a post [#7040](https://github.com/diaspora/diaspora/pull/7040) # 0.6.0.0 diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js index e837f96bc..28d6f3a57 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post/interactions.js @@ -67,6 +67,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ var self = this; this.likes.create({}, { success: function() { + self.post.set({participation: true}); self.trigger("change"); self.set({"likes_count" : self.get("likes_count") + 1}); }, @@ -94,6 +95,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ this.comments.make(text).fail(function () { app.flashMessages.error(Diaspora.I18n.t("failed_to_comment")); }).done(function() { + self.post.set({participation: true}); self.trigger('change'); //updates after sync }); @@ -109,6 +111,7 @@ app.models.Post.Interactions = Backbone.Model.extend({ .done(function(reshare) { app.flashMessages.success(Diaspora.I18n.t("reshares.successful")); interactions.reshares.add(reshare); + interactions.post.set({participation: true}); if (app.stream && /^\/(?:stream|activity|aspects)/.test(app.stream.basePath())) { app.stream.addNow(reshare); } diff --git a/app/assets/javascripts/app/views/feedback_actions.js b/app/assets/javascripts/app/views/feedback_actions.js deleted file mode 100644 index 861bde76d..000000000 --- a/app/assets/javascripts/app/views/feedback_actions.js +++ /dev/null @@ -1,11 +0,0 @@ -// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later - -//=require "./feedback_view" -app.views.FeedbackActions = app.views.Feedback.extend({ - id : "user-controls", - templateName : "feedback-actions", - events: {}, - initialize: function(){} -}); -// @license-end - diff --git a/app/assets/javascripts/app/views/feedback_view.js b/app/assets/javascripts/app/views/feedback_view.js index 70bf4ca6d..81d8d03e8 100644 --- a/app/assets/javascripts/app/views/feedback_view.js +++ b/app/assets/javascripts/app/views/feedback_view.js @@ -8,10 +8,6 @@ app.views.Feedback = app.views.Base.extend({ events: { "click .like" : "toggleLike", "click .reshare" : "resharePost", - - "click .post_report" : "report", - "click .block_user" : "blockUser", - "click .hide_post" : "hidePost" }, tooltipSelector : ".label", @@ -43,39 +39,6 @@ app.views.Feedback = app.views.Base.extend({ if(evt) { evt.preventDefault(); } if(!window.confirm(Diaspora.I18n.t("reshares.post", {name: this.model.reshareAuthor().name}))) { return } this.model.interactions.reshare(); - }, - - blockUser: function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("ignore_user"))) { return; } - - this.model.blockAuthor() - .done(function() { - // return to stream - document.location.href = "/stream"; - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); - }); - }, - - hidePost : function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("hide_post"))) { return; } - - $.ajax({ - url : "/share_visibilities/42", - type : "PUT", - data : { - post_id : this.model.id - } - }).done(function() { - // return to stream - document.location.href = "/stream"; - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("ignore_post_failed")); - }); } }); // @license-end diff --git a/app/assets/javascripts/app/views/post_controls_view.js b/app/assets/javascripts/app/views/post_controls_view.js new file mode 100644 index 000000000..78c0ee3df --- /dev/null +++ b/app/assets/javascripts/app/views/post_controls_view.js @@ -0,0 +1,81 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +app.views.PostControls = app.views.Base.extend({ + templateName: "post-controls", + className: "control-icons", + + events: { + "click .remove_post": "destroyModel", + "click .hide_post": "hidePost", + "click .post_report": "report", + "click .block_user": "blockUser", + "click .create_participation": "createParticipation", + "click .destroy_participation": "destroyParticipation" + }, + + tooltipSelector: [".post_report", + ".block_user", + ".delete", + ".create_participation", + ".destroy_participation"].join(", "), + + initialize: function(opts) { + this.model.bind("change", this.render, this); + this.post = opts.post; + }, + + presenter: function() { + return _.extend(this.defaultPresenter(), { + authorIsCurrentUser: app.currentUser.isAuthorOf(this.model) + }); + }, + + blockUser: function(evt) { + if (evt) { evt.preventDefault(); } + if (!confirm(Diaspora.I18n.t("ignore_user"))) { return; } + + this.model.blockAuthor().done(function() { + if (this.singlePost) { app._changeLocation(Routes.stream()); } + }.bind(this)).fail(function() { + app.flashMessages.error(Diaspora.I18n.t("ignore_failed")); + }); + }, + + hidePost: function(evt) { + if (evt) { evt.preventDefault(); } + if (!confirm(Diaspora.I18n.t("confirm_dialog"))) { return; } + + $.ajax({ + url: Routes.shareVisibility(42), + type: "PUT", + data: { + /* eslint-disable camelcase */ + post_id: this.model.id + /* eslint-enable camelcase */ + } + }).done(function() { + if (this.singlePost) { + app._changeLocation(Routes.stream()); + } else { + this.post.remove(); + } + }.bind(this)).fail(function() { + app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); + }); + }, + + createParticipation: function(evt) { + if (evt) { evt.preventDefault(); } + $.post(Routes.postParticipation(this.model.get("id")), {}, function() { + this.model.set({participation: true}); + }.bind(this)); + }, + + destroyParticipation: function(evt) { + if (evt) { evt.preventDefault(); } + $.post(Routes.postParticipation(this.model.get("id")), {_method: "delete"}, function() { + this.model.set({participation: false}); + }.bind(this)); + } +}); +// @license-end diff --git a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js index 823783da3..3599da357 100644 --- a/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js +++ b/app/assets/javascripts/app/views/single-post-viewer/single_post_moderation.js @@ -1,31 +1,12 @@ -app.views.SinglePostModeration = app.views.Feedback.extend({ +app.views.SinglePostModeration = app.views.PostControls.extend({ templateName: "single-post-viewer/single-post-moderation", - - className: "control-icons", - - events: function() { - return _.defaults({ - "click .remove_post": "destroyModel", - "click .create_participation": "createParticipation", - "click .destroy_participation": "destroyParticipation" - }, app.views.Feedback.prototype.events); - }, - - presenter: function() { - return _.extend(this.defaultPresenter(), { - authorIsCurrentUser : this.authorIsCurrentUser() - }); - }, + singlePost: true, renderPluginWidgets : function() { app.views.Base.prototype.renderPluginWidgets.apply(this); this.$("a").tooltip({placement: "bottom"}); }, - authorIsCurrentUser: function() { - return app.currentUser.authenticated() && this.model.get("author").id === app.user().id; - }, - destroyModel: function(evt) { if(evt) { evt.preventDefault(); } var url = this.model.urlRoot + "/" + this.model.id; @@ -41,24 +22,4 @@ app.views.SinglePostModeration = app.views.Feedback.extend({ }); } }, - - createParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var self = this; - $.post(Routes.postParticipation(this.model.get("id")), {}, function () { - self.model.set({participation: true}); - self.render(); - }); - }, - - destroyParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var self = this; - $.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () { - self.model.set({participation: false}); - self.render(); - }); - }, - - participation: function(){ return this.model.get("participation"); } }); diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index b298cd0ad..60812f6b9 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -5,38 +5,26 @@ app.views.StreamPost = app.views.Post.extend({ className : "stream_element loaded", subviews : { - ".feedback" : "feedbackView", - ".likes" : "likesInfoView", - ".reshares" : "resharesInfoView", - ".comments" : "commentStreamView", - ".post-content" : "postContentView", - ".oembed" : "oEmbedView", - ".opengraph" : "openGraphView", - ".poll" : "pollView", - ".status-message-location" : "postLocationStreamView" + ".feedback": "feedbackView", + ".comments": "commentStreamView", + ".likes": "likesInfoView", + ".reshares": "resharesInfoView", + ".post-controls": "postControlsView", + ".post-content": "postContentView", + ".oembed": "oEmbedView", + ".opengraph": "openGraphView", + ".poll": "pollView", + ".status-message-location": "postLocationStreamView" }, events: { "click .focus_comment_textarea": "focusCommentTextarea", "click .show_nsfw_post": "removeNsfwShield", - "click .toggle_nsfw_state": "toggleNsfwState", - - "click .remove_post": "destroyModel", - "click .hide_post": "hidePost", - "click .post_report": "report", - "click .block_user": "blockUser", - - "click .create_participation": "createParticipation", - "click .destroy_participation": "destroyParticipation" + "click .toggle_nsfw_state": "toggleNsfwState" }, tooltipSelector : [".timeago", ".post_scope", - ".post_report", - ".block_user", - ".delete", - ".create_participation", - ".destroy_participation", ".permalink"].join(", "), initialize : function(){ @@ -51,6 +39,9 @@ app.views.StreamPost = app.views.Post.extend({ this.pollView = new app.views.Poll({model : this.model}); }, + postControlsView: function() { + return new app.views.PostControls({model: this.model, post: this}); + }, likesInfoView : function(){ return new app.views.LikesInfo({model : this.model}); @@ -87,60 +78,12 @@ app.views.StreamPost = app.views.Post.extend({ app.currentUser.toggleNsfwState(); }, - - blockUser: function(evt){ - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("ignore_user"))) { return } - - this.model.blockAuthor() - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("ignore_failed")); - }); - }, - remove : function() { $(this.el).slideUp(400, _.bind(function(){this.$el.remove()}, this)); app.stream.remove(this.model); return this; }, - hidePost : function(evt) { - if(evt) { evt.preventDefault(); } - if(!confirm(Diaspora.I18n.t("confirm_dialog"))) { return } - - var self = this; - $.ajax({ - url : "/share_visibilities/42", - type : "PUT", - data : { - post_id : this.model.id - } - }).done(function() { - self.remove(); - }) - .fail(function() { - app.flashMessages.error(Diaspora.I18n.t("hide_post_failed")); - }); - }, - - createParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var that = this; - $.post(Routes.postParticipation(this.model.get("id")), {}, function () { - that.model.set({participation: true}); - that.render(); - }); - }, - - destroyParticipation: function (evt) { - if(evt) { evt.preventDefault(); } - var that = this; - $.post(Routes.postParticipation(this.model.get("id")), { _method: "delete" }, function () { - that.model.set({participation: false}); - that.render(); - }); - }, - focusCommentTextarea: function(evt){ evt.preventDefault(); this.$(".new-comment-form-wrapper").removeClass("hidden"); @@ -148,6 +91,5 @@ app.views.StreamPost = app.views.Post.extend({ return this; } - }); // @license-end diff --git a/app/assets/templates/post-controls_tpl.jst.hbs b/app/assets/templates/post-controls_tpl.jst.hbs new file mode 100644 index 000000000..560f366f4 --- /dev/null +++ b/app/assets/templates/post-controls_tpl.jst.hbs @@ -0,0 +1,24 @@ +{{#if authorIsCurrentUser}} + + + +{{else}} + + + + + + + {{#if participation}} + + + + {{else}} + + + + {{/if}} + +{{/if}} diff --git a/app/assets/templates/stream-element_tpl.jst.hbs b/app/assets/templates/stream-element_tpl.jst.hbs index 2520c1e67..2c65c427a 100644 --- a/app/assets/templates/stream-element_tpl.jst.hbs +++ b/app/assets/templates/stream-element_tpl.jst.hbs @@ -7,34 +7,7 @@