diff --git a/app/assets/javascripts/discourse/components/post-menu.js.es6 b/app/assets/javascripts/discourse/components/post-menu.js.es6 index a6933a39fc4..89417192edd 100644 --- a/app/assets/javascripts/discourse/components/post-menu.js.es6 +++ b/app/assets/javascripts/discourse/components/post-menu.js.es6 @@ -56,8 +56,8 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { rerenderTriggers: [ 'post.deleted_at', - 'likeAction.count', - 'likeAction.users.length', + 'post.likeAction.count', + 'post.likeAction.users.length', 'post.reply_count', 'post.showRepliesBelow', 'post.can_delete', @@ -69,10 +69,6 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { 'post.post_type', 'collapsed'], - likeAction: function() { - return this.get('post.actionByName.like'); - }.property('post.actionByName.like'), - _collapsedByDefault: function() { this.set('collapsed', true); }.on('init'), @@ -167,7 +163,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { }, clickLikeCount() { - const likeAction = this.get('post.actionByName.like'); + const likeAction = this.get('post.likeAction'); if (likeAction) { const users = likeAction.get('users'); if (users && users.length) { @@ -233,11 +229,11 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { // Like button buttonForLike() { - const likeAction = this.get('likeAction'); + const likeAction = this.get('post.likeAction'); if (!likeAction) { return; } const className = likeAction.get('acted') ? 'has-like fade-out' : 'like'; - var opts = {className: className}; + const opts = {className: className}; if (likeAction.get('canToggle')) { const descKey = likeAction.get('acted') ? 'post.controls.undo_like' : 'post.controls.like'; @@ -249,16 +245,16 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { }, buttonForLikeCount() { - var likeCount = this.get('post.like_count') || 0; + const likeCount = this.get('post.likeAction.count') || 0; if (likeCount > 0) { - const likedPost = !!this.get('likeAction.acted'); + const likedPost = !!this.get('post.likeAction.acted'); const label = likedPost ? 'post.has_likes_title_you' : 'post.has_likes_title'; return new Button('like-count', label, undefined, { - className: 'like-count highlight-action', - innerHTML: I18n.t("post.has_likes", { count: likeCount }), - labelOptions: {count: likedPost ? (likeCount-1) : likeCount} + className: 'like-count highlight-action', + innerHTML: I18n.t("post.has_likes", { count: likeCount }), + labelOptions: {count: likedPost ? (likeCount-1) : likeCount} }); } }, @@ -266,7 +262,7 @@ const PostMenuComponent = Ember.Component.extend(StringBuffer, { clickLike(post) { const $heart = this.$('.fa-heart'), $likeButton = this.$('button[data-action=like]'), - acted = post.get('actionByName.like.acted'), + acted = post.get('likeAction.acted'), self = this; if (acted) { diff --git a/app/assets/javascripts/discourse/components/who-liked.js.es6 b/app/assets/javascripts/discourse/components/who-liked.js.es6 index c101f59ae4e..34ba672236f 100644 --- a/app/assets/javascripts/discourse/components/who-liked.js.es6 +++ b/app/assets/javascripts/discourse/components/who-liked.js.es6 @@ -1,7 +1,7 @@ import StringBuffer from 'discourse/mixins/string-buffer'; export default Ember.Component.extend(StringBuffer, { - likedUsers: Ember.computed.alias('post.actionByName.like.users'), + likedUsers: Ember.computed.alias('post.likeAction.users'), rerenderTriggers: ['likedUsers.length'], renderString(buffer) { diff --git a/app/assets/javascripts/discourse/controllers/flag.js.es6 b/app/assets/javascripts/discourse/controllers/flag.js.es6 index 1942934e111..6a80da273b7 100644 --- a/app/assets/javascripts/discourse/controllers/flag.js.es6 +++ b/app/assets/javascripts/discourse/controllers/flag.js.es6 @@ -76,11 +76,13 @@ export default ObjectController.extend(ModalFunctionality, { createFlag(opts) { const self = this; let postAction; // an instance of ActionSummary + if (!this.get('flagTopic')) { - postAction = this.get('model.actionByName.' + this.get('selected.name_key')); + postAction = this.get('model.actions_summary').findProperty('id', this.get('selected.id')); } else { postAction = this.get('topicActionByName.' + this.get('selected.name_key')); } + let params = this.get('selected.is_custom_flag') ? {message: this.get('message')} : {}; if (opts) { params = $.extend(params, opts); } diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index a7484cba8e2..76acf375976 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -153,7 +153,7 @@ export default ObjectController.extend(SelectedPostsCount, BufferedContent, { }, toggleLike(post) { - const likeAction = post.get('actionByName.like'); + const likeAction = post.get('likeAction'); if (likeAction && likeAction.get('canToggle')) { likeAction.toggle(post); } diff --git a/app/assets/javascripts/discourse/models/action-summary.js.es6 b/app/assets/javascripts/discourse/models/action-summary.js.es6 index 12a2c60ec98..15a6d9bcfaa 100644 --- a/app/assets/javascripts/discourse/models/action-summary.js.es6 +++ b/app/assets/javascripts/discourse/models/action-summary.js.es6 @@ -25,10 +25,7 @@ export default RestModel.extend({ }.property('can_undo', 'can_act'), // Remove it - removeAction: function(post) { - - const action = this.get('actionType.name_key'); - + removeAction: function() { this.setProperties({ acted: false, count: this.get('count') - 1, @@ -36,11 +33,6 @@ export default RestModel.extend({ can_undo: false }); - - if (action === 'like' && post) { - post.set('like_count', this.get('count')); - } - if (this.get('usersExpanded')) { this.get('users').removeObject(Discourse.User.current()); } @@ -69,11 +61,7 @@ export default RestModel.extend({ can_undo: true }); - if (action === 'like') { - post.set('like_count', this.get('count')); - } - - if(action === 'notify_moderators' || action === 'notify_user') { + if (action === 'notify_moderators' || action === 'notify_user') { this.set('can_undo',false); this.set('can_defer_flags',false); } diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index 04fe4d02a12..a6785730771 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -367,6 +367,10 @@ Post.reopenClass({ a.count = a.count || 0; const actionSummary = ActionSummary.create(a); lookup[a.actionType.name_key] = actionSummary; + + if (a.actionType.name_key === "like") { + json.likeAction = actionSummary; + } return actionSummary; }); diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index c1998a2e212..daf5d6fafe5 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -18,7 +18,6 @@ class PostSerializer < BasicPostSerializer attributes :post_number, :post_type, :updated_at, - :like_count, :reply_count, :reply_to_post_number, :quote_count, diff --git a/spec/serializers/post_serializer_spec.rb b/spec/serializers/post_serializer_spec.rb index b024be3f0eb..20643968f8a 100644 --- a/spec/serializers/post_serializer_spec.rb +++ b/spec/serializers/post_serializer_spec.rb @@ -19,7 +19,7 @@ describe PostSerializer do serializer.post_actions = PostAction.counts_for([post], actor)[post.id] if user.try(:id) == actor.id actions = serializer.as_json[:actions_summary] lookup = PostActionType.types.invert - actions.keep_if{|a| a[:count] > 0}.map{|a| lookup[a[:id]]} + actions.keep_if{|a| (a[:count] || 0) > 0}.map{|a| lookup[a[:id]]} end before do @@ -39,7 +39,7 @@ describe PostSerializer do it "can't flag your own post to notify yourself" do serializer = PostSerializer.new(post, scope: Guardian.new(post.user), root: false) notify_user_action = serializer.actions_summary.find { |a| a[:id] == PostActionType.types[:notify_user] } - expect(notify_user_action[:can_act]).to eq(false) + expect(notify_user_action).to be_blank end end diff --git a/test/javascripts/components/post-menu-test.js.es6 b/test/javascripts/components/post-menu-test.js.es6 index e94dc749b29..a027bb660fa 100644 --- a/test/javascripts/components/post-menu-test.js.es6 +++ b/test/javascripts/components/post-menu-test.js.es6 @@ -15,7 +15,7 @@ function setup(store) { }); this.on('toggleLike', function() { - post.toggleProperty('actionByName.like.acted'); + post.toggleProperty('likeAction.acted'); }); this.set('post', post);