import { AsyncFetchable, AsyncLackable } from "./guild-types"; import { Channel, GuildMetadata, Member, Message, Resource, Token } from "./data-types"; import PersonalDB from "./personal-db"; export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable { constructor( private readonly db: PersonalDB, private readonly guildId: number, private readonly memberId: string, // would be used if we want to cache-update the status/display name of members ) {} // Fetched Methods async fetchMetadata(): Promise { // TODO return null; } async fetchMembers(): Promise { return await this.db.fetchMembers(this.guildId); } async fetchChannels(): Promise { return await this.db.fetchChannels(this.guildId); } async fetchMessagesRecent(channelId: string, number: number): Promise { return await this.db.fetchMessagesRecent(this.guildId, channelId, number); } async fetchMessagesBefore(channelId: string, messageId: string, number: number): Promise { return await this.db.fetchMessagesBefore(this.guildId, channelId, messageId, number); } async fetchMessagesAfter(channelId: string, messageId: string, number: number): Promise { return await this.db.fetchMessagesAfter(this.guildId, channelId, messageId, number); } async fetchResource(resourceId: string): Promise { return await this.db.fetchResource(this.guildId, resourceId); } async fetchTokens(): Promise { return null; // personal db currently does not handle tokens } // Lacking Methods (resolving differences) async handleMetadataChanged(changedMetaData: GuildMetadata): Promise { (async () => { await this.db.updateGuildName(this.guildId, changedMetaData.name); })(); (async () => { await this.db.updateGuildIcon(this.guildId, changedMetaData.iconResourceId); })(); } async handleMembersAdded(addedMembers: Member[]): Promise { await this.db.addMembers(this.guildId, addedMembers); } async handleMembersChanged(changedMembers: Member[]): Promise { await this.db.updateMembers(this.guildId, changedMembers); } async handleMembersDeleted(deletedMembers: Member[]): Promise { await this.db.deleteMembers(this.guildId, deletedMembers); } async handleChannelsAdded(addedChannels: Channel[]): Promise { await this.db.addChannels(this.guildId, addedChannels); } async handleChannelsChanged(changedChannels: Channel[]): Promise { await this.db.updateChannels(this.guildId, changedChannels); } async handleChannelsDeleted(deletedChannels: Channel[]): Promise { await this.db.deleteChannels(this.guildId, deletedChannels); } async handleMessagesAdded(addedMessages: Message[]): Promise { await this.db.addMessages(this.guildId, addedMessages); } async handleMessagesChanged(changedMessages: Message[]): Promise { await this.db.updateMessages(this.guildId, changedMessages); } async handleMessagesDeleted(deletedMessages: Message[]): Promise { await this.db.deleteMessages(this.guildId, deletedMessages); } async handleResourceAdded(addedResource: Resource): Promise { await this.db.addResources(this.guildId, [ addedResource ]); } async handleResourceChanged(changedResource: Resource): Promise { await this.db.updateResources(this.guildId, [ changedResource ]); } async handleResourceDeleted(deletedResource: Resource): Promise { await this.db.deleteResources(this.guildId, [ deletedResource ]); } async handleTokensAdded(addedTokens: Token[]): Promise { return; // cache currently does not handle tokens } async handleTokensChanged(changedTokens: Token[]): Promise { return; // cache currently does not handle tokens } async handleTokensDeleted(deletedTokens: Token[]): Promise { return; // cache currently does not handle tokens } }