diff --git a/src/client/webapp/dedup-awaiter.ts b/src/client/webapp/dedup-awaiter.ts index b386f16..2f0e6a3 100644 --- a/src/client/webapp/dedup-awaiter.ts +++ b/src/client/webapp/dedup-awaiter.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); + // lets you wait until it is uncorked by someone before running export default class DedupAwaiter { private promise: Promise | null = null; diff --git a/src/client/webapp/elements/require/guild-subscriptions.ts b/src/client/webapp/elements/require/guild-subscriptions.ts index 3846fa1..c232a2f 100644 --- a/src/client/webapp/elements/require/guild-subscriptions.ts +++ b/src/client/webapp/elements/require/guild-subscriptions.ts @@ -6,7 +6,7 @@ const LOG = Logger.create(__filename, electronConsole); import { Changes, GuildMetadata, Member, Message, Resource } from "../../data-types"; import CombinedGuild from "../../guild-combined"; -import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react'; +import { Dispatch, SetStateAction, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { AutoVerifierChangesType } from "../../auto-verifier"; import { Conflictable, Connectable } from "../../guild-types"; import { EventEmitter } from 'tsee'; @@ -67,18 +67,6 @@ interface MultipleEventMappingParams< conflictEventArgsMap: (...args: Arguments) => Changes; sortFunc: (a: T, b: T) => number; // Friendly reminder that v8 uses timsort so this is O(n) for pre-sorted stuff -} - -export default class GuildSubscriptions { - - - - - - - - - } function useGuildSubscriptionEffect( @@ -88,16 +76,20 @@ function useGuildSubscriptionEffect( const { guild, onFetch, onFetchError, bindEventsFunc, unbindEventsFunc } = subscriptionParams; const isMounted = useIsMountedRef(); + const guildRef = useRef(guild); const fetchManagerFunc = useCallback(async () => { if (!isMounted.current) return; + if (guildRef.current !== guild) return; try { const value = await fetchFunc(); if (!isMounted.current) return; + if (guildRef.current !== guild) return; // Don't call onFetch if we changed guilds onFetch(value); } catch (e: unknown) { LOG.error('error fetching for subscription', e); if (!isMounted.current) return; + if (guildRef.current !== guild) return; onFetchError(e); } }, [ fetchFunc ]); @@ -105,6 +97,7 @@ function useGuildSubscriptionEffect( useEffect(() => { // Bind guild events to make sure we have the most up to date information guild.on('connect', fetchManagerFunc); + guild.on('disconnect', fetchManagerFunc); bindEventsFunc(); // Fetch the data once @@ -113,6 +106,7 @@ function useGuildSubscriptionEffect( return () => { // Unbind the events so that we don't have any memory leaks guild.off('connect', fetchManagerFunc); + guild.off('disconnect', fetchManagerFunc); unbindEventsFunc(); } }, [ fetchManagerFunc ]); diff --git a/src/client/webapp/guild-combined.ts b/src/client/webapp/guild-combined.ts index 988c1b2..6a8e205 100644 --- a/src/client/webapp/guild-combined.ts +++ b/src/client/webapp/guild-combined.ts @@ -49,11 +49,13 @@ export default class CombinedGuild extends EventEmitter { LOG.info(`g#${this.id} connected`); + diskSocket.unverify(); + ramDiskSocket.unverify(); this.emit('connect'); }); this.socketGuild.on('disconnect', async () => { LOG.info(`g#${this.id} disconnected`); - this.unverify(); + diskSocket.unverify(); await personalDB.clearAllMembersStatus(this.id); this.emit('disconnect'); }); @@ -186,7 +188,7 @@ export default class CombinedGuild extends EventEmitter) => { - LOG.info(`g#${this.id} members conflict`); + LOG.info(`g#${this.id} members conflict`); // This should be pretty common since we manually update the status to "unknown" which will cause a conflict this.emit('conflict-members', changesType, changes); }); ramDiskSocket.on('conflict-channels', (changesType: AutoVerifierChangesType, changes: Changes) => { @@ -256,10 +258,6 @@ export default class CombinedGuild extends EventEmitter implements As if (!this.verifier.isVerified) { throw new Error(`attempted to make query before verified @${endpoint} / [${args.map(arg => LOG.inspect(arg)).join(', ')}]`); } + LOG.silly(`query@${endpoint} / [${args.map(arg => LOG.inspect(arg)).join(', ')}]`); return await new Promise((resolve, reject) => { Util.socketEmitTimeout(this.socket, timeout, endpoint, ...args, (errMsg: string | null, serverData: any) => { if (errMsg) { diff --git a/src/client/webapp/personal-db.ts b/src/client/webapp/personal-db.ts index 1d68109..1444077 100644 --- a/src/client/webapp/personal-db.ts +++ b/src/client/webapp/personal-db.ts @@ -518,7 +518,7 @@ export default class PersonalDB { ) AS "r" ORDER BY "r"."order" `, { ':guild_id': guildId, ':channel_id': channelId, ':number': number }); if (messages.length === 0) return null; - LOG.debug(`return ${messages.length}/${number} recent messages`); + //LOG.debug(`return ${messages.length}/${number} recent messages`); return messages.map(dataMessage => Message.fromDBData(dataMessage)); } diff --git a/src/client/webapp/socket-verifier.ts b/src/client/webapp/socket-verifier.ts index dd5f806..4a9d9f4 100644 --- a/src/client/webapp/socket-verifier.ts +++ b/src/client/webapp/socket-verifier.ts @@ -28,6 +28,7 @@ export default class SocketVerifier extends EventEmitter<{ 'verified': () => voi socket.on('disconnect', () => { this.isVerified = false; this.memberId = null; + LOG.debug('disconnected and marked as not verified'); }); }