FIX: User stream was cached and not reloading
This commit is contained in:
parent
e52ed66069
commit
f87fc98411
|
@ -1,23 +1,14 @@
|
||||||
/**
|
import RestModel from 'discourse/models/rest';
|
||||||
Represents a user's stream
|
|
||||||
|
|
||||||
@class UserStream
|
export default RestModel.extend({
|
||||||
@extends Discourse.Model
|
|
||||||
@namespace Discourse
|
|
||||||
@module Discourse
|
|
||||||
**/
|
|
||||||
Discourse.UserStream = Discourse.Model.extend({
|
|
||||||
loaded: false,
|
loaded: false,
|
||||||
|
|
||||||
_initialize: function() {
|
_initialize: function() {
|
||||||
this.setProperties({
|
this.setProperties({ itemsLoaded: 0, content: [] });
|
||||||
itemsLoaded: 0,
|
|
||||||
content: []
|
|
||||||
});
|
|
||||||
}.on("init"),
|
}.on("init"),
|
||||||
|
|
||||||
filterParam: function() {
|
filterParam: function() {
|
||||||
var filter = this.get('filter');
|
const filter = this.get('filter');
|
||||||
if (filter === Discourse.UserAction.TYPES.replies) {
|
if (filter === Discourse.UserAction.TYPES.replies) {
|
||||||
return [Discourse.UserAction.TYPES.replies,
|
return [Discourse.UserAction.TYPES.replies,
|
||||||
Discourse.UserAction.TYPES.quotes].join(",");
|
Discourse.UserAction.TYPES.quotes].join(",");
|
||||||
|
@ -33,23 +24,16 @@ Discourse.UserStream = Discourse.Model.extend({
|
||||||
|
|
||||||
baseUrl: Discourse.computed.url('itemsLoaded', 'user.username_lower', '/user_actions.json?offset=%@&username=%@'),
|
baseUrl: Discourse.computed.url('itemsLoaded', 'user.username_lower', '/user_actions.json?offset=%@&username=%@'),
|
||||||
|
|
||||||
filterBy: function(filter) {
|
filterBy(filter) {
|
||||||
if (this.get('loaded') && (this.get('filter') === filter)) { return Ember.RSVP.resolve(); }
|
this.setProperties({ filter, itemsLoaded: 0, content: [] });
|
||||||
|
|
||||||
this.setProperties({
|
|
||||||
filter: filter,
|
|
||||||
itemsLoaded: 0,
|
|
||||||
content: []
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.findItems();
|
return this.findItems();
|
||||||
},
|
},
|
||||||
|
|
||||||
remove: function(userAction) {
|
remove(userAction) {
|
||||||
// 1) remove the user action from the child groups
|
// 1) remove the user action from the child groups
|
||||||
this.get("content").forEach(function (ua) {
|
this.get("content").forEach(function (ua) {
|
||||||
["likes", "stars", "edits", "bookmarks"].forEach(function (group) {
|
["likes", "stars", "edits", "bookmarks"].forEach(function (group) {
|
||||||
var items = ua.get("childGroups." + group + ".items");
|
const items = ua.get("childGroups." + group + ".items");
|
||||||
if (items) {
|
if (items) {
|
||||||
items.removeObject(userAction);
|
items.removeObject(userAction);
|
||||||
}
|
}
|
||||||
|
@ -57,35 +41,32 @@ Discourse.UserStream = Discourse.Model.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2) remove the parents that have no children
|
// 2) remove the parents that have no children
|
||||||
var content = this.get("content").filter(function (ua) {
|
const content = this.get("content").filter(function (ua) {
|
||||||
return ["likes", "stars", "edits", "bookmarks"].any(function (group) {
|
return ["likes", "stars", "edits", "bookmarks"].any(function (group) {
|
||||||
return ua.get("childGroups." + group + ".items.length") > 0;
|
return ua.get("childGroups." + group + ".items.length") > 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.setProperties({
|
this.setProperties({ content, itemsLoaded: content.length });
|
||||||
content: content,
|
|
||||||
itemsLoaded: content.length
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
findItems: function() {
|
findItems() {
|
||||||
var self = this;
|
const self = this;
|
||||||
|
|
||||||
var url = this.get('baseUrl');
|
let url = this.get('baseUrl');
|
||||||
if (this.get('filterParam')) {
|
if (this.get('filterParam')) {
|
||||||
url += "&filter=" + this.get('filterParam');
|
url += "&filter=" + this.get('filterParam');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't load the same stream twice. We're probably at the end.
|
// Don't load the same stream twice. We're probably at the end.
|
||||||
var lastLoadedUrl = this.get('lastLoadedUrl');
|
const lastLoadedUrl = this.get('lastLoadedUrl');
|
||||||
if (lastLoadedUrl === url) { return Ember.RSVP.resolve(); }
|
if (lastLoadedUrl === url) { return Ember.RSVP.resolve(); }
|
||||||
|
|
||||||
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
if (this.get('loading')) { return Ember.RSVP.resolve(); }
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
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();
|
const copy = Em.A();
|
||||||
result.user_actions.forEach(function(action) {
|
result.user_actions.forEach(function(action) {
|
||||||
copy.pushObject(Discourse.UserAction.create(action));
|
copy.pushObject(Discourse.UserAction.create(action));
|
||||||
});
|
});
|
|
@ -7,9 +7,9 @@ export default Discourse.Route.extend({
|
||||||
this.controllerFor('user-activity').set('model', user);
|
this.controllerFor('user-activity').set('model', user);
|
||||||
|
|
||||||
// Bring up a draft
|
// Bring up a draft
|
||||||
var composerController = this.controllerFor('composer');
|
const composerController = this.controllerFor('composer');
|
||||||
controller.set('model', user);
|
controller.set('model', user);
|
||||||
if (Discourse.User.current()) {
|
if (this.currentUser) {
|
||||||
Discourse.Draft.get('new_private_message').then(function(data) {
|
Discourse.Draft.get('new_private_message').then(function(data) {
|
||||||
if (data.draft) {
|
if (data.draft) {
|
||||||
composerController.open({
|
composerController.open({
|
||||||
|
|
Loading…
Reference in New Issue