mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 12:41:25 +08:00
BUGFIX: likes would cause whole post to re-render
This commit is contained in:
@ -400,7 +400,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
|||||||
if (data.type === "revised" || data.type === "acted"){
|
if (data.type === "revised" || data.type === "acted"){
|
||||||
// TODO we could update less data for "acted"
|
// TODO we could update less data for "acted"
|
||||||
// (only post actions)
|
// (only post actions)
|
||||||
postStream.triggerChangedPost(data.id, data.updated_at);
|
postStream.triggerChangedPost(data.id, data.updated_at, data.type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,9 +284,30 @@ Discourse.Post = Discourse.Model.extend({
|
|||||||
var post = this;
|
var post = this;
|
||||||
Object.keys(otherPost).forEach(function (key) {
|
Object.keys(otherPost).forEach(function (key) {
|
||||||
var value = otherPost[key];
|
var value = otherPost[key];
|
||||||
if (typeof value !== "function") {
|
var oldValue = post.get(key);
|
||||||
post.set(key, value);
|
|
||||||
|
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; }
|
if (!postId) { return; }
|
||||||
|
|
||||||
var postIdentityMap = this.get('postIdentityMap'),
|
var postIdentityMap = this.get('postIdentityMap'),
|
||||||
|
@ -218,6 +218,8 @@ class PostsController < ApplicationController
|
|||||||
def render_post_json(post)
|
def render_post_json(post)
|
||||||
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
|
||||||
post_serializer.add_raw = true
|
post_serializer.add_raw = true
|
||||||
|
post_serializer.topic_slug = post.topic.slug if post.topic.present?
|
||||||
|
|
||||||
counts = PostAction.counts_for([post], current_user)
|
counts = PostAction.counts_for([post], current_user)
|
||||||
if counts && counts = counts[post.id]
|
if counts && counts = counts[post.id]
|
||||||
post_serializer.post_actions = counts
|
post_serializer.post_actions = counts
|
||||||
|
@ -41,6 +41,7 @@ class User < ActiveRecord::Base
|
|||||||
has_one :user_stat, dependent: :destroy
|
has_one :user_stat, dependent: :destroy
|
||||||
has_one :single_sign_on_record, dependent: :destroy
|
has_one :single_sign_on_record, dependent: :destroy
|
||||||
belongs_to :approved_by, class_name: 'User'
|
belongs_to :approved_by, class_name: 'User'
|
||||||
|
belongs_to :primary_group, class_name: 'Group'
|
||||||
|
|
||||||
has_many :group_users, dependent: :destroy
|
has_many :group_users, dependent: :destroy
|
||||||
has_many :groups, through: :group_users
|
has_many :groups, through: :group_users
|
||||||
|
@ -78,8 +78,13 @@ class PostSerializer < BasicPostSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def primary_group_name
|
def primary_group_name
|
||||||
return nil unless object.user && @topic_view
|
return nil unless object.user && object.user.primary_group_id
|
||||||
return @topic_view.primary_group_names[object.user.primary_group_id] if 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
|
end
|
||||||
|
|
||||||
def link_counts
|
def link_counts
|
||||||
|
@ -62,6 +62,17 @@ describe PostsController do
|
|||||||
let(:action) { :show }
|
let(:action) { :show }
|
||||||
let(:params) { {id: post.id} }
|
let(:params) { {id: post.id} }
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe 'by_number' do
|
describe 'by_number' do
|
||||||
|
Reference in New Issue
Block a user