mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: Load order of TopicTrackingState
was off
This commit is contained in:
parent
9f6ce653a9
commit
b49e9fb174
4 changed files with 20 additions and 33 deletions
|
@ -137,13 +137,10 @@ const Category = RestModel.extend({
|
|||
}.property('topics'),
|
||||
|
||||
unreadTopics: function() {
|
||||
// TODO this is somehow null for /categories page anon
|
||||
if (!this.topicTrackingState) { return 0; }
|
||||
return this.topicTrackingState.countUnread(this.get('id'));
|
||||
}.property('topicTrackingState.messageCount'),
|
||||
|
||||
newTopics: function() {
|
||||
if (!this.topicTrackingState) { return 0; }
|
||||
return this.topicTrackingState.countNew(this.get('id'));
|
||||
}.property('topicTrackingState.messageCount'),
|
||||
|
||||
|
|
|
@ -336,32 +336,16 @@ const TopicTrackingState = Discourse.Model.extend({
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
TopicTrackingState.reopenClass({
|
||||
|
||||
createFromStates(data) {
|
||||
// TODO: This should be a model that does injection automatically
|
||||
const container = Discourse.__container__,
|
||||
messageBus = container.lookup('message-bus:main'),
|
||||
currentUser = container.lookup('current-user:main'),
|
||||
instance = TopicTrackingState.create({ messageBus, currentUser });
|
||||
|
||||
instance.loadStates(data);
|
||||
instance.initialStatesLength = data && data.length;
|
||||
instance.establishChannels();
|
||||
return instance;
|
||||
},
|
||||
|
||||
current() {
|
||||
if (!this.tracker) {
|
||||
const data = PreloadStore.get('topicTrackingStates');
|
||||
this.tracker = this.createFromStates(data);
|
||||
PreloadStore.remove('topicTrackingStates');
|
||||
}
|
||||
return this.tracker;
|
||||
}
|
||||
});
|
||||
export function startTracking(tracking) {
|
||||
const data = PreloadStore.get('topicTrackingStates');
|
||||
tracking.loadStates(data);
|
||||
tracking.initialStatesLength = data && data.length;
|
||||
tracking.establishChannels();
|
||||
PreloadStore.remove('topicTrackingStates');
|
||||
}
|
||||
|
||||
export default TopicTrackingState;
|
||||
|
|
|
@ -5,7 +5,7 @@ import Store from 'discourse/models/store';
|
|||
import DiscourseURL from 'discourse/lib/url';
|
||||
import DiscourseLocation from 'discourse/lib/discourse-location';
|
||||
import SearchService from 'discourse/services/search';
|
||||
import TopicTrackingState from 'discourse/models/topic-tracking-state';
|
||||
import { startTracking, default as TopicTrackingState } from 'discourse/models/topic-tracking-state';
|
||||
|
||||
function inject() {
|
||||
const app = arguments[0],
|
||||
|
@ -31,11 +31,15 @@ export default {
|
|||
app.register('store:main', Store);
|
||||
inject(app, 'store', 'route', 'controller');
|
||||
|
||||
app.register('message-bus:main', window.MessageBus, { instantiate: false });
|
||||
const messageBus = window.MessageBus;
|
||||
app.register('message-bus:main', messageBus, { instantiate: false });
|
||||
injectAll(app, 'messageBus');
|
||||
|
||||
app.register('current-user:main', Discourse.User.current(), { instantiate: false });
|
||||
app.register('topic-tracking-state:main', TopicTrackingState.current(), { instantiate: false });
|
||||
const currentUser = Discourse.User.current();
|
||||
app.register('current-user:main', currentUser, { instantiate: false });
|
||||
|
||||
const tracking = TopicTrackingState.create({ messageBus, currentUser });
|
||||
app.register('topic-tracking-state:main', tracking, { instantiate: false });
|
||||
injectAll(app, 'topicTrackingState');
|
||||
|
||||
const site = Discourse.Site.current();
|
||||
|
@ -58,5 +62,7 @@ export default {
|
|||
const keyValueStore = new KeyValueStore("discourse_");
|
||||
app.register('key-value-store:main', keyValueStore, { instantiate: false });
|
||||
injectAll(app, 'keyValueStore');
|
||||
|
||||
startTracking(tracking);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -18,7 +18,7 @@ export default function() {
|
|||
return (this._kvs);
|
||||
}
|
||||
if (type === "topic-tracking-state:main") {
|
||||
this._tracker = this._tracker || TopicTrackingState.current();
|
||||
this._tracker = this._tracker || TopicTrackingState.create();
|
||||
return (this._tracker);
|
||||
}
|
||||
if (type === "site-settings:main") {
|
||||
|
|
Loading…
Reference in a new issue