From e14e8f64bcff0959cbb8b22690b742c1d41077cc Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 25 Sep 2014 12:02:41 +1000 Subject: [PATCH] FIX: don't stop youtube when liking a post Also fixes post action create/destroy api not to include post raw. --- app/assets/javascripts/discourse/models/_post.js | 16 ++++++++++++++-- app/controllers/application_controller.rb | 4 ++-- app/controllers/post_actions_controller.rb | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/discourse/models/_post.js b/app/assets/javascripts/discourse/models/_post.js index df214d9cccc..b9064f0bc1d 100644 --- a/app/assets/javascripts/discourse/models/_post.js +++ b/app/assets/javascripts/discourse/models/_post.js @@ -327,12 +327,24 @@ Discourse.Post = Discourse.Model.extend({ updateFromJson: function(obj) { if (!obj) return; + var skip, oldVal; + // Update all the properties var post = this; _.each(obj, function(val,key) { if (key !== 'actions_summary'){ - if (val) { - post.set(key, val); + oldVal = post[key]; + skip = false; + + if (val && val !== oldVal) { + + if (key === "reply_to_user" && val && oldVal) { + skip = val.username === oldVal.username || Em.get(val, "username") === Em.get(oldVal, "username"); + } + + if(!skip) { + post.set(key, val); + } } } }); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 00be872e02b..bb27e8c24df 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -355,9 +355,9 @@ class ApplicationController < ActionController::Base protected - def render_post_json(post) + def render_post_json(post, add_raw=true) post_serializer = PostSerializer.new(post, scope: guardian, root: false) - post_serializer.add_raw = true + post_serializer.add_raw = add_raw post_serializer.topic_slug = post.topic.slug if post.topic.present? counts = PostAction.counts_for([post], current_user) diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index 24412c239ce..5d76ff113b2 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -22,7 +22,7 @@ class PostActionsController < ApplicationController else # We need to reload or otherwise we are showing the old values on the front end @post.reload - render_post_json(@post) + render_post_json(@post, _add_raw = false) end end @@ -43,7 +43,7 @@ class PostActionsController < ApplicationController PostAction.remove_act(current_user, @post, post_action.post_action_type_id) @post.reload - render_post_json(@post) + render_post_json(@post, _add_raw = false) end def defer_flags