Migrate most of the Client Data Store to Clien

This commit is contained in:
Amish Shah
2016-08-19 22:21:30 +01:00
parent ad8b4c7698
commit 82ab92ca2a
31 changed files with 75 additions and 55 deletions

View File

@@ -15,11 +15,12 @@ class DMChannel extends Channel {
setup(data) {
super.setup(data);
const recipient = new User(this.client, data.recipients[0]);
/**
* The recipient on the other end of the DM
* @type {User}
*/
this.recipient = this.client.store.add('users', new User(this.client, data.recipients[0]));
this.recipient = this.client.users.set(recipient.id, recipient);
/**
* The ID of the last sent message, if available
* @type {?String}

View File

@@ -283,7 +283,7 @@ class Guild {
if (data.presences) {
for (const presence of data.presences) {
const user = this.client.store.get('users', presence.user.id);
const user = this.client.users.get(presence.user.id);
if (user) {
user.status = presence.status;
user.game = presence.game;

View File

@@ -84,7 +84,7 @@ class Message {
*/
this.id = data.id;
for (const mention of data.mentions) {
let user = this.client.store.get('users', mention.id);
let user = this.client.users.get(mention.id);
if (user) {
this.mentions.push(user);
} else {
@@ -96,7 +96,7 @@ class Message {
patch(data) {
if (data.author) {
this.author = this.client.store.get('users', data.author.id);
this.author = this.client.users.get(data.author.id);
}
if (data.content) {
this.content = data.content;
@@ -124,7 +124,7 @@ class Message {
}
if (data.mentions) {
for (const mention of data.mentions) {
let user = this.client.store.get('users', mention.id);
let user = this.client.users.get(mention.id);
if (user) {
this.mentions.push(user);
} else {

View File

@@ -18,10 +18,6 @@ class ClientDataStore extends AbstractDataStore {
this.user = null;
this.email = null;
this.password = null;
this.register('users');
this.register('guilds');
this.register('channels');
}
get pastReady() {
@@ -29,8 +25,9 @@ class ClientDataStore extends AbstractDataStore {
}
newGuild(data) {
const already = this.get('guilds', data.id);
const guild = this.add('guilds', new Guild(this.client, data));
const already = this.client.guilds.get(data.id);
const guild = new Guild(this.client, data);
this.client.guilds.set(guild.id, guild);
if (this.pastReady && !already) {
this.client.emit(Constants.Events.GUILD_CREATE, guild);
}
@@ -39,12 +36,14 @@ class ClientDataStore extends AbstractDataStore {
}
newUser(data) {
return this.add('users', new User(this.client, data));
const user = new User(this.client, data);
this.client.users.set(user.id, user);
return user;
}
newChannel(data, $guild) {
let guild = $guild;
const already = this.get('channels', data.id);
const already = this.client.channels.get(data.id);
let channel;
if (data.type === Constants.ChannelTypes.DM) {
channel = new DMChannel(this.client, data);
@@ -66,25 +65,25 @@ class ClientDataStore extends AbstractDataStore {
this.client.emit(Constants.Events.CHANNEL_CREATE, channel);
}
return this.add('channels', channel);
return this.client.channels.set(channel.id, channel);
}
return null;
}
killGuild(guild) {
const already = this.get('guilds', guild.id);
this.remove('guilds', guild);
const already = this.client.guilds.get(guild.id);
this.client.guilds.delete(guild.id);
if (already && this.pastReady) {
this.client.emit(Constants.Events.GUILD_DELETE, guild);
}
}
killUser(user) {
this.remove('users', user);
this.users.delete(user.id);
}
killChannel(channel) {
this.remove('channels', channel);
this.client.channels.delete(channel.id);
if (channel instanceof GuildChannel) {
channel.guild.channels.delete(channel.id);
}