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

View File

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

View File

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

View File

@ -21,6 +21,8 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.LoadMore, {
stream.findItems().then(function() { stream.findItems().then(function() {
self.set('loading', false); self.set('loading', false);
self.get('eyeline').flushRest(); 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 # having strings where you would expect bools
class UserActionRow < OpenStruct class UserActionRow < OpenStruct
include ActiveModel::SerializerSupport include ActiveModel::SerializerSupport
def as_json(options = nil)
@table.as_json(options)
end
end end
def self.last_action_in_topic(user_id, topic_id) def self.last_action_in_topic(user_id, topic_id)