mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:41:45 +08:00
BUGFIX: likes would cause whole post to re-render
This commit is contained in:
parent
2d123ef1c7
commit
05efc8df16
|
@ -400,7 +400,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||
if (data.type === "revised" || data.type === "acted"){
|
||||
// TODO we could update less data for "acted"
|
||||
// (only post actions)
|
||||
postStream.triggerChangedPost(data.id, data.updated_at);
|
||||
postStream.triggerChangedPost(data.id, data.updated_at, data.type);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -284,9 +284,30 @@ Discourse.Post = Discourse.Model.extend({
|
|||
var post = this;
|
||||
Object.keys(otherPost).forEach(function (key) {
|
||||
var value = otherPost[key];
|
||||
if (typeof value !== "function") {
|
||||
var oldValue = post.get(key);
|
||||
|
||||
if(!value) {
|
||||
value = null;
|
||||
}
|
||||
|
||||
if(!oldValue) {
|
||||
oldValue = null;
|
||||
}
|
||||
|
||||
var skip = false;
|
||||
|
||||
if (typeof value !== "function" && oldValue !== value) {
|
||||
|
||||
// wishing for an identity map
|
||||
if(key === "reply_to_user") {
|
||||
skip = Em.get(value, "username") === Em.get(oldValue, "username");
|
||||
}
|
||||
|
||||
if(!skip) {
|
||||
post.set(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -504,7 +504,7 @@ Discourse.PostStream = Em.Object.extend({
|
|||
}
|
||||
},
|
||||
|
||||
triggerChangedPost: function(postId, updatedAt) {
|
||||
triggerChangedPost: function(postId, updatedAt, type) {
|
||||
if (!postId) { return; }
|
||||
|
||||
var postIdentityMap = this.get('postIdentityMap'),
|
||||
|
|
|
@ -218,6 +218,8 @@ class PostsController < ApplicationController
|
|||
def render_post_json(post)
|
||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
||||
post_serializer.add_raw = true
|
||||
post_serializer.topic_slug = post.topic.slug if post.topic.present?
|
||||
|
||||
counts = PostAction.counts_for([post], current_user)
|
||||
if counts && counts = counts[post.id]
|
||||
post_serializer.post_actions = counts
|
||||
|
|
|
@ -41,6 +41,7 @@ class User < ActiveRecord::Base
|
|||
has_one :user_stat, dependent: :destroy
|
||||
has_one :single_sign_on_record, dependent: :destroy
|
||||
belongs_to :approved_by, class_name: 'User'
|
||||
belongs_to :primary_group, class_name: 'Group'
|
||||
|
||||
has_many :group_users, dependent: :destroy
|
||||
has_many :groups, through: :group_users
|
||||
|
|
|
@ -78,8 +78,13 @@ class PostSerializer < BasicPostSerializer
|
|||
end
|
||||
|
||||
def primary_group_name
|
||||
return nil unless object.user && @topic_view
|
||||
return @topic_view.primary_group_names[object.user.primary_group_id] if object.user.primary_group_id
|
||||
return nil unless object.user && object.user.primary_group_id
|
||||
|
||||
if @topic_view
|
||||
@topic_view.primary_group_names[object.user.primary_group_id]
|
||||
else
|
||||
object.user.primary_group.name if object.user.primary_group
|
||||
end
|
||||
end
|
||||
|
||||
def link_counts
|
||||
|
|
|
@ -62,6 +62,17 @@ describe PostsController do
|
|||
let(:action) { :show }
|
||||
let(:params) { {id: post.id} }
|
||||
end
|
||||
|
||||
it 'gets all the expected fields' do
|
||||
# non fabricated test
|
||||
new_post = create_post
|
||||
xhr :get, :show, {id: new_post.id}
|
||||
parsed = JSON.parse(response.body)
|
||||
parsed["topic_slug"].should == new_post.topic.slug
|
||||
parsed["moderator"].should == false
|
||||
parsed["username"].should == new_post.user.username
|
||||
parsed["cooked"].should == new_post.cooked
|
||||
end
|
||||
end
|
||||
|
||||
describe 'by_number' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user