never double load the stream.

This commit is contained in:
Sam 2013-07-05 21:23:01 +10:00
parent a1f1849392
commit 363e1010c4

View File

@ -17,6 +17,10 @@ Discourse.UserStream = Discourse.Model.extend({
}.observes('filter'),
findItems: function() {
var me = this;
if(this.get("loading")) { return; }
this.set("loading",true);
var url = Discourse.getURL("/user_actions.json?offset=") + this.get('itemsLoaded') + "&username=" + (this.get('user.username_lower'));
if (this.get('filter')) {
url += "&filter=" + (this.get('filter'));
@ -24,6 +28,7 @@ Discourse.UserStream = Discourse.Model.extend({
var stream = this;
return Discourse.ajax(url, {cache: 'false'}).then( function(result) {
me.set("loading",false);
if (result && result.user_actions) {
var copy = Em.A();
_.each(result.user_actions,function(action) {
@ -33,7 +38,7 @@ Discourse.UserStream = Discourse.Model.extend({
stream.get('content').pushObjects(copy);
stream.set('itemsLoaded', stream.get('itemsLoaded') + result.user_actions.length);
}
});
}, function(){ me.set("loading", false); });
}
});