fix unstable comment order

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2017-10-23 15:37:36 +02:00
parent de8a475b0b
commit eb8f1247fe
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
1 changed files with 19 additions and 13 deletions

View File

@ -270,23 +270,30 @@
* @private * @private
*/ */
_onAddModel: function(model, collection, options) { _onAddModel: function(model, collection, options) {
var self = this; // we need to render it immediately, to ensure that the right
// order of comments is kept on opening comments tab
var $comment = $(this.commentTemplate(this._formatItem(model)));
if (!_.isUndefined(options.at) && collection.length > 1) {
this.$container.find('li').eq(options.at).before($comment);
} else {
this.$container.append($comment);
}
this._postRenderItem($comment);
$('#commentsTabView').find('.newCommentForm div.message').text('').prop('disabled', false);
// we need to update the model, because it consists of client data // we need to update the model, because it consists of client data
// only, but the server might add meta data, e.g. about mentions // only, but the server might add meta data, e.g. about mentions
var oldMentions = model.get('mentions');
var self = this;
model.fetch({ model.fetch({
success: function (model) { success: function (model) {
var $el = $(self.commentTemplate(self._formatItem(model))); if(_.isEqual(oldMentions, model.get('mentions'))) {
if (!_.isUndefined(options.at) && collection.length > 1) { // don't attempt to render if unnecessary, avoids flickering
self.$container.find('li').eq(options.at).before($el); return;
} else {
self.$container.append($el);
} }
var $updated = $(self.commentTemplate(self._formatItem(model)));
self._postRenderItem($el); $comment.html($updated.html());
$('#commentsTabView').find('.newCommentForm div.message').text('').prop('disabled', false); self._postRenderItem($comment);
},
error: function () {
self._onSubmitError($('#commentsTabView').find('.newCommentForm'), undefined);
} }
}) })
@ -312,7 +319,6 @@
// ignore noise this is only set after editing a comment and hitting post // ignore noise this is only set after editing a comment and hitting post
return; return;
} }
var self = this; var self = this;
// we need to update the model, because it consists of client data // we need to update the model, because it consists of client data