Datastore cleanup (#1892)

* Start Store cleanup

* wip store cleanup

* fix iterables initiating datastores

* handle the possibility of a datastore with no holds and no its own 'create' method

* more cleanup (instances that need more than just client/data)

* missed RoleStore extras

* not sure how eslint didn't catch that tab...

* avoid re-getting the channel we already have...

* cleanup resolvers and refactor them into DataStores

* ^

* and remove

* fix some bugs

* fix lint

* fix documentation maybe?

* formatting

* fix presences

* really fix presences this time

* bad fix was bad... let;s see how bad this one is..

* forgot to save a file

* make presence resolving take userresolveables too

* fix tabs in jsdocs

* fix bad fix from last night that caused issues, with better fix...

* oops
This commit is contained in:
bdistin
2017-09-08 16:06:10 -05:00
committed by Crawl
parent 0607720ec8
commit dd085ceaee
34 changed files with 560 additions and 435 deletions

View File

@@ -2,13 +2,46 @@ const DataStore = require('./DataStore');
const { Presence } = require('../structures/Presence');
class PresenceStore extends DataStore {
create(data) {
if (this.has(data.user.id)) {
this.get(data.user.id).patch(data);
} else {
this.set(data.user.id, new Presence(this.client, data));
}
return this.get(data.user.id);
constructor(client, iterable) {
super(client, iterable, Presence);
}
create(data, cache) {
const existing = this.get(data.user.id);
return existing ? existing.patch(data) : super.create(data, cache, { id: data.user.id });
}
/**
* Data that can be resolved to a Presence object. This can be:
* * A Presence
* * A UserResolveable
* * A Snowflake
* @typedef {Presence|UserResolveable|Snowflake} PresenceResolvable
*/
/**
* Resolves a PresenceResolvable to a Presence object.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?Presence}
*/
resolve(presence) {
const presenceResolveable = super.resolve(presence);
if (presenceResolveable) return presenceResolveable;
const UserResolveable = this.client.users.resolveID(presence);
return super.resolve(UserResolveable) || null;
}
/**
* Resolves a PresenceResolvable to a Presence ID string.
* @param {PresenceResolvable} presence The presence resolvable to resolve
* @returns {?string}
*/
resolveID(presence) {
const presenceResolveable = super.resolveID(presence);
if (presenceResolveable) return presenceResolveable;
const userResolveable = this.client.users.resolveID(presence);
return this.has(userResolveable) ? userResolveable : null;
}
}