diff --git a/client/webapp/auto-verifier.ts b/client/webapp/auto-verifier.ts index 8ead160..541817a 100644 --- a/client/webapp/auto-verifier.ts +++ b/client/webapp/auto-verifier.ts @@ -56,7 +56,9 @@ export class AutoVerifier { for (let trustedElement of trustedResult) { let primaryElement = primaryResult.find(primaryElement => primaryElement.id === trustedElement.id); if (primaryElement) { - changes.updated.push({ oldDataPoint: primaryElement, newDataPoint: trustedElement }); + if (!primaryElement.equals(trustedElement)) { + changes.updated.push({ oldDataPoint: primaryElement, newDataPoint: trustedElement }); + } } else { changes.added.push(trustedElement); } @@ -133,10 +135,10 @@ export class AutoVerifier { // You CAN safely call this while another fetch is going on! How convenient unverify(): void { if (this.primaryPromise) { - this.primaryPromise.catch((e) => { console.warn('caught unverified promise', e); }); + this.primaryPromise.catch((e) => { console.warn('caught unverified primary promise', e); }); } if (this.trustedPromise) { - this.trustedPromise.catch((e) => { console.warn('caught unverified promise', e); }); + this.trustedPromise.catch((e) => { console.warn('caught unverified trusted promise', e); }); } this.primaryPromise = null; this.trustedPromise = null; @@ -150,9 +152,6 @@ export class AutoVerifier { return await new Promise(async (resolve: (result: T | null) => void, reject: (error: Error) => void) => { let resolved = false; try { - let origTrustedStatus = this.trustedStatus; - let origTrustedPromise = this.trustedPromise; - if (this.primaryPromise === null) { this.primaryPromise = this.primaryFunc(); } diff --git a/client/webapp/data-types.ts b/client/webapp/data-types.ts index 8e3ff44..856bb85 100644 --- a/client/webapp/data-types.ts +++ b/client/webapp/data-types.ts @@ -151,8 +151,8 @@ export class Message implements WithEquals { return new Message( dataMessage.id, - { id: dataMessage.member_id }, { id: dataMessage.channel_id }, + { id: dataMessage.member_id }, new Date(dataMessage.sent_dtg), dataMessage.text ?? null, dataMessage.resource_id ?? null, @@ -179,7 +179,7 @@ export class Message implements WithEquals { this.id === other.id && this.member.id === other.member.id && this.channel.id === other.channel.id && - this.sent === other.sent && + this.sent.getTime() === other.sent.getTime() && this.resourceId === other.resourceId && this.resourceName === other.resourceName && this.resourceWidth === other.resourceWidth && diff --git a/client/webapp/fetchable-pair-verifier.ts b/client/webapp/fetchable-pair-verifier.ts index 2fd3b25..a1fe833 100644 --- a/client/webapp/fetchable-pair-verifier.ts +++ b/client/webapp/fetchable-pair-verifier.ts @@ -1,3 +1,8 @@ +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 { Changes, Channel, GuildMetadata, Member, Message, Resource, Token } from './data-types'; import { AsyncFetchable, Fetchable, Lackable, Conflictable } from './guild-types'; import { AutoVerifier, AutoVerifierChangesType } from './auto-verifier'; diff --git a/client/webapp/guild-combined.ts b/client/webapp/guild-combined.ts index 2f5a2c2..895b51d 100644 --- a/client/webapp/guild-combined.ts +++ b/client/webapp/guild-combined.ts @@ -278,13 +278,31 @@ export default class CombinedGuild extends EventEmitter { - return await this.fetchable.fetchMessagesRecent(channelId, number); + let members = await this.grabRAMMembersMap(); + let channels = await this.grabRAMChannelsMap(); + let messages = await this.fetchable.fetchMessagesRecent(channelId, number); + for (let message of messages) { + message.fill(members, channels); + } + return messages; } async fetchMessagesBefore(channelId: string, messageId: string, number: number): Promise { - return await this.fetchable.fetchMessagesBefore(channelId, messageId, number); + let members = await this.grabRAMMembersMap(); + let channels = await this.grabRAMChannelsMap(); + let messages = await this.fetchable.fetchMessagesBefore(channelId, messageId, number); + for (let message of messages) { + message.fill(members, channels); + } + return messages; } async fetchMessagesAfter(channelId: string, messageId: string, number: number): Promise { - return await this.fetchable.fetchMessagesAfter(channelId, messageId, number); + let members = await this.grabRAMMembersMap(); + let channels = await this.grabRAMChannelsMap(); + let messages = await this.fetchable.fetchMessagesAfter(channelId, messageId, number); + for (let message of messages) { + message.fill(members, channels); + } + return messages; } async fetchResource(resourceId: string): Promise { return await this.fetchable.fetchResource(resourceId); diff --git a/client/webapp/guild-personal-db.ts b/client/webapp/guild-personal-db.ts index 454f112..b73dd7e 100644 --- a/client/webapp/guild-personal-db.ts +++ b/client/webapp/guild-personal-db.ts @@ -1,3 +1,8 @@ +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"; @@ -13,8 +18,7 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable { // Fetched Methods async fetchMetadata(): Promise { - // TODO - return null; + return this.db.fetchGuild(this.guildId); } async fetchMembers(): Promise { @@ -48,47 +52,60 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable { // Lacking Methods (resolving differences) async handleMetadataChanged(changedMetaData: GuildMetadata): Promise { + LOG.debug('personal metadata changed', { changedMetaData }); (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 ]); } diff --git a/logger/logger.ts b/logger/logger.ts index 3ae70b4..e8a30a2 100644 --- a/logger/logger.ts +++ b/logger/logger.ts @@ -237,7 +237,7 @@ export default class Logger { // Use the source map to create a typescript version of the stack // This will be printed asynchronously because SourceMapConsumer } else { - let s = util.inspect(data, { colors: true, depth: 2 }); + let s = util.inspect(data, { colors: true, depth: 5 }); s = s.split('\n').map(o => `${prefix}$ ${o}`).join('\n'); out += s; } diff --git a/server/db.ts b/server/db.ts index 4cbe723..44fe42f 100644 --- a/server/db.ts +++ b/server/db.ts @@ -60,8 +60,7 @@ export default class DB { static async getMemberInfo(publicKey: crypto.KeyObject): Promise { let der = publicKey.export({ type: 'spki', format: 'der' }); - let der_start = der.subarray(0, 10); - LOG.silly(`searching for public key (der starts with ${LOG.inspect(der_start)})`); + LOG.silly(`searching for public key (der hash: ${LOG.inspect(crypto.createHash('sha256').update(der).digest().toString('hex'))})`); let result = await db.query('SELECT "id" AS member_id, "guild_id" FROM "members" WHERE "public_key"=$1', [ der ]);