Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1093 #1116

Merged
merged 2 commits into from
Aug 16, 2017
Merged

1093 #1116

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/factory/botFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import Bot, {LOCATION, IMAGE, NOTE} from '../model/Bot';

import Utils from '../store/xmpp/utils';
import * as log from '../utils/log';
import Bots from '../model/Bots';

@autobind
class BotFactory {
@observable bots: {string: Bot} = {};
bots: {string: Bot} = {};

constructor() {
log.log('CREATE BOTFACTORY', {level: log.levels.DEBUG});
}

load(bots: Bots) {
for (let i = 0; i < bots._list.length; i++) {
this.bots[bots._list[i].id] = bots._list[i];
}
}

remove(bot) {
log.log('REMOVE BOT FROM FACTORY', bot.id, {level: log.levels.DEBUG});
delete this.bots[bot.id];
Expand Down
2 changes: 2 additions & 0 deletions src/model/EventBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Profile from './Profile';
import moment from 'moment';
import autobind from 'autobind-decorator';
import factory from '../factory/botFactory';
import model from '../model/model';

// http://momentjs.com/docs/#/customization/relative-time/
moment.updateLocale('en', {
Expand Down Expand Up @@ -69,6 +70,7 @@ export default class EventBot extends Event {
this._id = id;
if (botId && server) {
this.bot = factory.create({id: botId, server});
model.eventBots.add(this.bot);
}
if (time) {
this.time = time;
Expand Down
9 changes: 8 additions & 1 deletion src/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class Model {
@observable chats: Chats = new Chats();
@observable followingBots: Bots = new Bots();
@observable ownBots: Bots = new Bots();
@observable geoBots = new Bots();
@observable geoBots: Bots = new Bots();
// event bots is list of bots used by Home Stream. We will persist it to avoid reloading of all bots
@observable eventBots: Bots = new Bots();
@observable friends: FriendList = new FriendList();
@observable profile: Profile;
@observable user: ?string;
Expand Down Expand Up @@ -53,6 +55,7 @@ export class Model {
this.friends.clear();
this.ownBots.clear();
this.followingBots.clear();
this.eventBots.clear();
this.geoBots.clear();
this.password = undefined;
this.user = undefined;
Expand All @@ -72,6 +75,9 @@ export class Model {
if (d.messages) {
messageFactory.load(d.messages);
}
botFactory.load(d.eventBots);
botFactory.load(d.ownBots);
botFactory.load(d.followingBots);
for (const key of Object.keys(d)) {
this[key] = d[key];
}
Expand Down Expand Up @@ -111,6 +117,7 @@ createModelSchema(Model, {
messages: list(child(Message)),
followingBots: child(Bots),
ownBots: child(Bots),
eventBots: child(Bots),
chats: child(Chats),
profile: child(Profile),
events: child(EventList),
Expand Down
10 changes: 5 additions & 5 deletions src/store/eventStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ export class EventStore {
const data = await home.items();

runInAction(() => {
// @NOTE: don't clear the list...use the cache!
// if (data.items.length) {
// model.events.clear();
// console.log('& clear', model.events);
// }
// need to clear events to avoid overloading of memory/disk for many events
if (data.items.length) {
model.events.clear();
model.eventBots.clear();
}
if (data.count <= model.events.list.length) {
model.events.finished = true;
}
Expand Down