import * as electronRemote from '@electron/remote'; const electronConsole = electronRemote.getGlobal('console') as Console; import Logger from '../../logger/logger'; const LOG = Logger.create(__filename, electronConsole); 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 { return this.db.fetchGuild(this.guildId); } 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 { LOG.debug(addedMembers.length + ' personal members added'); await this.db.addMembers(this.guildId, addedMembers); } async handleMembersChanged(changedMembers: Member[]): Promise { LOG.debug(changedMembers.length + ' personal members changed'); await this.db.updateMembers(this.guildId, changedMembers); } async handleMembersDeleted(deletedMembers: Member[]): Promise { LOG.debug(deletedMembers.length + ' personal members deleted'); await this.db.deleteMembers(this.guildId, deletedMembers); } async handleChannelsAdded(addedChannels: Channel[]): Promise { LOG.debug(addedChannels.length + ' personal channels added'); await this.db.addChannels(this.guildId, addedChannels); } async handleChannelsChanged(changedChannels: Channel[]): Promise { LOG.debug(changedChannels.length + ' personal channels changed'); await this.db.updateChannels(this.guildId, changedChannels); } async handleChannelsDeleted(deletedChannels: Channel[]): Promise { LOG.debug(deletedChannels.length + ' personal channels deleted'); await this.db.deleteChannels(this.guildId, deletedChannels); } async handleMessagesAdded(addedMessages: Message[]): Promise { LOG.debug(addedMessages.length + ' personal messages added'); await this.db.addMessages(this.guildId, addedMessages); } async handleMessagesChanged(changedMessages: Message[]): Promise { LOG.debug(changedMessages.length + ' personal messages changed'); await this.db.updateMessages(this.guildId, changedMessages); } async handleMessagesDeleted(deletedMessages: Message[]): Promise { LOG.debug(deletedMessages.length + ' personal messages deleted'); await this.db.deleteMessages(this.guildId, deletedMessages); } async handleResourceAdded(addedResource: Resource): Promise { //LOG.debug('personal resoprces added', { addedResource }); await this.db.addResources(this.guildId, [ addedResource ]); } async handleResourceChanged(changedResource: Resource): Promise { //LOG.debug('personal resoprces changed', { changedResource }); await this.db.updateResources(this.guildId, [ changedResource ]); } async handleResourceDeleted(deletedResource: Resource): Promise { //LOG.debug('personal resoprces deleted', { deletedResource }); 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 } }