From 72c34f7e638f6b5b97f145486f356a51e1a0571b Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Tue, 25 Oct 2022 23:22:34 -0700 Subject: [PATCH] unverify both on disconnect, neither on connect. --- src/client/webapp/auto-verifier-with-args.ts | 26 ++++++++++---------- src/client/webapp/auto-verifier.ts | 1 - src/client/webapp/data-types.ts | 8 +++--- src/client/webapp/guild-combined.ts | 2 +- src/server/server-controller.ts | 4 +-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/client/webapp/auto-verifier-with-args.ts b/src/client/webapp/auto-verifier-with-args.ts index 49f1bcc..f81f5a6 100644 --- a/src/client/webapp/auto-verifier-with-args.ts +++ b/src/client/webapp/auto-verifier-with-args.ts @@ -27,7 +27,7 @@ export class AutoVerifierWithArg { private primaryFunc: (query: K) => Promise, private trustedFunc: (query: K) => Promise, private verifyFunc: (query: K, primaryResult: T | null, trustedResult: T | null) => Promise, - private name: string | null = null, // for debugging purposes + private name: string | null = null, // for debugging purposes ) {} static createStandardPartialMessageListAutoVerifier & { id: string }>( @@ -38,7 +38,7 @@ export class AutoVerifierWithArg { changesType: AutoVerifierChangesType, changes: Changes, ) => Promise, - name: string | null = null, + name: string | null = null, ) { return new AutoVerifierWithArg( query => `ch#${query.channelId} mo#${query.messageOrderId}->${query.number}`, @@ -46,20 +46,20 @@ export class AutoVerifierWithArg { query => trustedFunc(query), async (query: PartialMessageListQuery, primaryResult: T[] | null, trustedResult: T[] | null) => { // lOG.debug('messages verify: ', { - // query, - // // primaryResult: primaryResult?.map((e: any) => e.sent).sort(), - // // trustedResult: trustedResult?.map((e: any) => e.sent).sort(), - // zipped: primaryResult && trustedResult && primaryResult.length === trustedResult.length && Q.zip( - // primaryResult?.sort((a: any, b: any) => a.sent.getTime() - b.sent.getTime()).map((e: any) => e.text), - // trustedResult?.sort((a: any, b: any) => a.sent.getTime() - b.sent.getTime()).map((e: any) => e.text) - // ) + // query, + // // primaryResult: primaryResult?.map((e: any) => e.sent).sort(), + // // trustedResult: trustedResult?.map((e: any) => e.sent).sort(), + // zipped: primaryResult && trustedResult && primaryResult.length === trustedResult.length && Q.zip( + // primaryResult?.sort((a: any, b: any) => a.sent.getTime() - b.sent.getTime()).map((e: any) => e.text), + // trustedResult?.sort((a: any, b: any) => a.sent.getTime() - b.sent.getTime()).map((e: any) => e.text) + // ) // }); const changes = AutoVerifier.getChanges(primaryResult, trustedResult); //lOG.debug('changes:', { changes }); const changesType = AutoVerifier.getListChangesType(primaryResult, trustedResult, changes); return await changesFunc(query, changesType, changes); }, - name, + name, ); } @@ -72,7 +72,7 @@ export class AutoVerifierWithArg { primaryResult: T | null, trustedResult: T | null, ) => Promise, - name: string | null = null, + name: string | null = null, ) { return new AutoVerifierWithArg( query => `id#${query.id}`, @@ -82,7 +82,7 @@ export class AutoVerifierWithArg { const changesType = AutoVerifier.getSingleChangesType(primaryResult, trustedResult); return await changesFunc(query, changesType, primaryResult, trustedResult); }, - name, + name, ); } @@ -122,7 +122,7 @@ export class AutoVerifierWithArg { async () => await this.trustedFunc(query), async (primaryResult: T | null, trustedResult: T | null) => await this.verifyFunc(query, primaryResult, trustedResult), - `${this.name}::${token.slice(0, 8)}` + `${this.name}::${token.slice(0, 8)}` ); this.tokenAutoVerifiers.set(token, autoVerifier); } diff --git a/src/client/webapp/auto-verifier.ts b/src/client/webapp/auto-verifier.ts index e89b71d..c9636d1 100644 --- a/src/client/webapp/auto-verifier.ts +++ b/src/client/webapp/auto-verifier.ts @@ -158,7 +158,6 @@ export class AutoVerifier { // you CAN safely call this while another fetch is going on! How convenient unverify(): void { - // lOG.debug(`v#${this.verifierId}: unverifying`); if (this.primaryPromise) { this.primaryPromise.catch(e => { console.warn('caught unverified primary promise', e); diff --git a/src/client/webapp/data-types.ts b/src/client/webapp/data-types.ts index 7e5e9eb..83968d3 100644 --- a/src/client/webapp/data-types.ts +++ b/src/client/webapp/data-types.ts @@ -198,14 +198,14 @@ export class Message implements WithEquals { } toString(): string { - const channel = this.channel instanceof Channel ? this.channel.name : `ch#${this.channel.id}`; - const member = this.member instanceof Member ? this.member.displayName : `m#${this.member.id}`; + const channel = this.channel instanceof Channel ? this.channel.name : `ch#${this.channel.id.slice(0, 4)}`; + const member = this.member instanceof Member ? this.member.displayName : `m#${this.member.id.slice(0, 4)}`; if (this.resourceName) { - return `msg#${this.id} ${channel} @${formatDate(this.sent)} ${member}: ${ + return `msg#${this.id.slice(0, 4)} ${channel} @${formatDate(this.sent)} ${member}: ${ this.text ? this.text + ' / ' : '' }${this.resourceName}`; } else { - return `msg#${this.id} ${channel} @${formatDate(this.sent)} ${member}: ${this.text}`; + return `msg#${this.id.slice(0, 4)} ${channel} @${formatDate(this.sent)} ${member}: ${this.text}`; } } diff --git a/src/client/webapp/guild-combined.ts b/src/client/webapp/guild-combined.ts index a4d31b8..f90fb63 100644 --- a/src/client/webapp/guild-combined.ts +++ b/src/client/webapp/guild-combined.ts @@ -67,11 +67,11 @@ export default class CombinedGuild // connect/Disconnect this.socketGuild.on('connect', () => { LOG.info(`g#${this.id} connected`); - ramDiskSocket.unverify(); // make sure to query the disk-socket AutoVerifier again this.emit('connect'); }); this.socketGuild.on('disconnect', async () => { LOG.info(`g#${this.id} disconnected`); + ramDiskSocket.unverify(); diskSocket.unverify(); await personalDB.clearAllMembersStatus(this.id); this.emit('disconnect'); diff --git a/src/server/server-controller.ts b/src/server/server-controller.ts index 23c2f2b..5b742b3 100644 --- a/src/server/server-controller.ts +++ b/src/server/server-controller.ts @@ -558,7 +558,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity const message = await DB.insertMessage(identity.guildId, channelId, identity.memberId, text); LOG.info( - `m#${message.id} ch#${message.channel_id} s@${formatDate(message.sent_dtg)} u#${message.member_id}: ${ + `g#${identity.guildId.slice(0, 4)} m#${message.id.slice(0, 4)} ch#${message.channel_id.slice(0, 4)} s@${formatDate(message.sent_dtg)} u#${message.member_id.slice(0, 4)}: ${ message.text }`, ); @@ -596,7 +596,7 @@ function bindActionEvents(io: socketio.Server, client: socketio.Socket, identity resourceName = resourceName.replace(/[^A-Za-z0-9 .]/g, '_'); // only alphanumerics for file names LOG.info( - `u#${identity.memberId?.slice(0, 4)}: resource message with resource of size: ${resource.length} bytes`, + `u#${identity.memberId.slice(0, 4)}: resource message with resource of size: ${resource.length} bytes`, ); // try to get the dimensions of the resource if it is an image so that we can scale it down for the preview