FIX: New action arriving in stream via message bus

This commit is contained in:
Robin Ward 2014-06-16 14:49:39 -04:00
parent 1147b9d2e5
commit d53ac36818
5 changed files with 20 additions and 17 deletions

View file

@ -21,16 +21,16 @@ export default Discourse.ObjectController.extend({
if( this.get('newUsername') && this.get('newUsername').length < 3 ) {
this.set('errorMessage', I18n.t('user.name.too_short'));
} else {
var preferencesUsernameController = this;
var self = this;
this.set('taken', false);
this.set('errorMessage', null);
if (this.blank('newUsername')) return;
if (this.get('unchanged')) return;
Discourse.User.checkUsername(this.get('newUsername'), undefined, this.get('content.id')).then(function(result) {
if (result.errors) {
preferencesUsernameController.set('errorMessage', result.errors.join(' '));
self.set('errorMessage', result.errors.join(' '));
} else if (result.available === false) {
preferencesUsernameController.set('taken', true);
self.set('taken', true);
}
});
}
@ -43,16 +43,16 @@ export default Discourse.ObjectController.extend({
actions: {
changeUsername: function() {
var preferencesUsernameController = this;
var self = this;
return bootbox.confirm(I18n.t("user.change_username.confirm"), I18n.t("no_value"), I18n.t("yes_value"), function(result) {
if (result) {
preferencesUsernameController.set('saving', true);
preferencesUsernameController.get('content').changeUsername(preferencesUsernameController.get('newUsername')).then(function() {
Discourse.URL.redirectTo("/users/" + preferencesUsernameController.get('newUsername').toLowerCase() + "/preferences");
self.set('saving', true);
self.get('content').changeUsername(self.get('newUsername')).then(function() {
Discourse.URL.redirectTo("/users/" + self.get('newUsername').toLowerCase() + "/preferences");
}, function() {
// error
preferencesUsernameController.set('error', true);
preferencesUsernameController.set('saving', false);
self.set('error', true);
self.set('saving', false);
});
}
});

View file

@ -257,8 +257,8 @@ Discourse.User = Discourse.Model.extend({
if (result) {
if ((user.get('streamFilter') || result.action_type) !== result.action_type) return;
var action = Discourse.UserAction.collapseStream([Discourse.UserAction.create(result)]);
stream.set('itemsLoaded', user.get('itemsLoaded') + 1);
stream.insertAt(0, action[0]);
stream.set('itemsLoaded', stream.get('itemsLoaded') + 1);
stream.get('content').insertAt(0, action[0]);
}
});
},

View file

@ -71,10 +71,6 @@ Discourse.UserStream = Discourse.Model.extend({
url += "&filter=" + this.get('filterParam');
}
var loadingFinished = function() {
userStream.set('loading', false);
};
return Discourse.ajax(url, {cache: 'false'}).then( function(result) {
if (result && result.user_actions) {
var copy = Em.A();
@ -88,8 +84,9 @@ Discourse.UserStream = Discourse.Model.extend({
itemsLoaded: userStream.get('itemsLoaded') + result.user_actions.length
});
}
loadingFinished();
}, loadingFinished);
}).finally(function() {
userStream.set('loading', false);
});
}
});

View file

@ -21,6 +21,8 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.LoadMore, {
stream.findItems().then(function() {
self.set('loading', false);
self.get('eyeline').flushRest();
}).catch(function() {
// If we were already loading...
});
}
}

View file

@ -39,6 +39,10 @@ class UserAction < ActiveRecord::Base
# having strings where you would expect bools
class UserActionRow < OpenStruct
include ActiveModel::SerializerSupport
def as_json(options = nil)
@table.as_json(options)
end
end
def self.last_action_in_topic(user_id, topic_id)