FIX: When a moderator made a post, their name wasn't highlighted until refresh

This commit is contained in:
Robin Ward 2013-03-13 13:59:07 -04:00
parent 58004d44cd
commit 45674ef8e7
1 changed files with 41 additions and 40 deletions

View File

@ -339,32 +339,34 @@ Discourse.Composer = Discourse.Model.extend({
// Create a new Post // Create a new Post
createPost: function(opts) { createPost: function(opts) {
var addedToStream, createdPost, diff, lastPost, post, promise, topic, var promise = new RSVP.Promise(),
_this = this; post = this.get('post'),
promise = new RSVP.Promise(); topic = this.get('topic'),
post = this.get('post'); currentUser = Discourse.get('currentUser'),
topic = this.get('topic'); addedToStream = false;
createdPost = Discourse.Post.create({
raw: this.get('reply'), // Build the post object
title: this.get('title'), var createdPost = Discourse.Post.create({
category: this.get('categoryName'), raw: this.get('reply'),
topic_id: this.get('topic.id'), title: this.get('title'),
reply_to_post_number: post ? post.get('post_number') : null, category: this.get('categoryName'),
imageSizes: opts.imageSizes, topic_id: this.get('topic.id'),
post_number: this.get('topic.highest_post_number') + 1, reply_to_post_number: post ? post.get('post_number') : null,
cooked: $('#wmd-preview').html(), imageSizes: opts.imageSizes,
reply_count: 0, post_number: this.get('topic.highest_post_number') + 1,
display_username: Discourse.get('currentUser.name'), cooked: $('#wmd-preview').html(),
username: Discourse.get('currentUser.username'), reply_count: 0,
metaData: this.get('metaData'), display_username: currentUser.get('name'),
archetype: this.get('archetypeId'), username: currentUser.get('username'),
post_type: Discourse.get('site.post_types.regular'), metaData: this.get('metaData'),
target_usernames: this.get('targetUsernames'), archetype: this.get('archetypeId'),
actions_summary: Em.A(), post_type: Discourse.get('site.post_types.regular'),
yours: true, target_usernames: this.get('targetUsernames'),
newPost: true actions_summary: Em.A(),
}); moderator: currentUser.get('moderator'),
addedToStream = false; yours: true,
newPost: true
});
// If we're in a topic, we can append the post instantly. // If we're in a topic, we can append the post instantly.
if (topic) { if (topic) {
@ -385,9 +387,9 @@ Discourse.Composer = Discourse.Model.extend({
createdPost.set('created_at', new Date()); createdPost.set('created_at', new Date());
// If we're near the end of the topic, load new posts // If we're near the end of the topic, load new posts
lastPost = topic.posts.last(); var lastPost = topic.posts.last();
if (lastPost) { if (lastPost) {
diff = topic.get('highest_post_number') - lastPost.get('post_number'); var diff = topic.get('highest_post_number') - lastPost.get('post_number');
// If the new post is within a threshold of the end of the topic, // If the new post is within a threshold of the end of the topic,
// add it and scroll there instead of adding the link. // add it and scroll there instead of adding the link.
@ -401,10 +403,10 @@ Discourse.Composer = Discourse.Model.extend({
} }
// Save callback // Save callback
var composer = this;
createdPost.save(function(result) { createdPost.save(function(result) {
var addedPost, saving; var addedPost = false,
addedPost = false; saving = true;
saving = true;
createdPost.updateFromSave(result); createdPost.updateFromSave(result);
if (topic) { if (topic) {
// It's no longer a new post // It's no longer a new post
@ -412,27 +414,26 @@ Discourse.Composer = Discourse.Model.extend({
topic.set('draft_sequence', result.draft_sequence); topic.set('draft_sequence', result.draft_sequence);
} else { } else {
// We created a new topic, let's show it. // We created a new topic, let's show it.
_this.set('composeState', CLOSED); composer.set('composeState', CLOSED);
saving = false; saving = false;
} }
_this.set('reply', ''); composer.set('reply', '');
_this.set('createdPost', createdPost); composer.set('createdPost', createdPost);
if (addedToStream) { if (addedToStream) {
_this.set('composeState', CLOSED); composer.set('composeState', CLOSED);
} else if (saving) { } else if (saving) {
_this.set('composeState', SAVING); composer.set('composeState', SAVING);
} }
return promise.resolve({ return promise.resolve({ post: result });
post: result
});
}, function(error) { }, function(error) {
// If an error occurs
var errors; var errors;
if (topic) { if (topic) {
topic.posts.removeObject(createdPost); topic.posts.removeObject(createdPost);
} }
errors = $.parseJSON(error.responseText).errors; errors = $.parseJSON(error.responseText).errors;
promise.reject(errors[0]); promise.reject(errors[0]);
return _this.set('composeState', OPEN); composer.set('composeState', OPEN);
}); });
return promise; return promise;
}, },