From 579050e8674e43a2f465b96a14416cec34a25e0e Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Mon, 27 Dec 2021 22:28:50 -0600 Subject: [PATCH] remove unused old guild root element --- src/client/webapp/actions.ts | 23 ----- .../webapp/elements/guild-list-guild.tsx | 18 ---- src/client/webapp/elements/sections/guild.tsx | 1 + src/client/webapp/guild-personal-db.ts | 18 ++-- src/client/webapp/index.html | 18 ---- src/client/webapp/preload.ts | 44 +-------- src/client/webapp/styles/channel-list.scss | 5 - src/client/webapp/styles/guild.scss | 5 - src/client/webapp/ui.ts | 93 +------------------ 9 files changed, 15 insertions(+), 210 deletions(-) delete mode 100644 src/client/webapp/actions.ts diff --git a/src/client/webapp/actions.ts b/src/client/webapp/actions.ts deleted file mode 100644 index f2cc076..0000000 --- a/src/client/webapp/actions.ts +++ /dev/null @@ -1,23 +0,0 @@ -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 Util from './util'; - -import UI from './ui'; -import CombinedGuild from './guild-combined'; -import Q from './q-module'; - -export default class Actions { - static async fetchAndUpdateConnection(ui: UI, guild: CombinedGuild) { - // Explicitly not using withPotentialError to make this simpler - try { - const connection = await guild.fetchConnectionInfo(); - ui.setActiveConnection(guild, connection); - } catch (e) { - LOG.error('Error updating current connection', e); - ui.setActiveConnection(guild, { id: null, avatarResourceId: null, displayName: 'Error', status: 'Error', privileges: [], roleName: null, roleColor: null, rolePriority: null }); - } - } -} diff --git a/src/client/webapp/elements/guild-list-guild.tsx b/src/client/webapp/elements/guild-list-guild.tsx index 4ade26f..0d8d10d 100644 --- a/src/client/webapp/elements/guild-list-guild.tsx +++ b/src/client/webapp/elements/guild-list-guild.tsx @@ -9,7 +9,6 @@ import ElementsUtil from './require/elements-util'; import { GuildMetadata } from '../data-types'; import Q from '../q-module'; import UI from '../ui'; -import Actions from '../actions'; import createGuildContextMenu from './context-menu-guild'; import GuildsManager from '../guilds-manager'; import CombinedGuild from '../guild-combined'; @@ -78,23 +77,6 @@ export default function createGuildListGuild(document: Document, q: Q, ui: UI, g if (element.classList.contains('active')) return; ui.setActiveGuild(guild); - - // Connection information - (async () => { - await Actions.fetchAndUpdateConnection(ui, guild); - })(); - - // Guild Channel Name - (async () => { - // Explicitly not using a withPotentialError to make this simpler - try { - const guildData = await guild.fetchMetadata(); - ui.updateGuildName(guild, guildData.name); - } catch (e) { - LOG.error('Error fetching guild name', e); - ui.updateGuildName(guild, 'ERROR'); - } - })(); }); element.addEventListener('contextmenu', (e) => { diff --git a/src/client/webapp/elements/sections/guild.tsx b/src/client/webapp/elements/sections/guild.tsx index 116ece8..b11b2e9 100644 --- a/src/client/webapp/elements/sections/guild.tsx +++ b/src/client/webapp/elements/sections/guild.tsx @@ -19,6 +19,7 @@ const GuildElement: FC = (props: GuildElementProps) => { // TODO: Handle fetch errors by allowing for retry // TODO: Handle fetch errors in message list + // TODO: React set hasMessagesAbove and hasMessagesBelow when re-verified? const [ selfMember ] = GuildSubscriptions.useSelfMemberSubscription(guild); const [ guildMeta, guildMetaFetchError ] = GuildSubscriptions.useGuildMetadataSubscription(guild); diff --git a/src/client/webapp/guild-personal-db.ts b/src/client/webapp/guild-personal-db.ts index c9db646..6e90512 100644 --- a/src/client/webapp/guild-personal-db.ts +++ b/src/client/webapp/guild-personal-db.ts @@ -57,41 +57,41 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable { } async handleMembersAdded(addedMembers: Member[]): Promise { - LOG.debug(addedMembers.length + ' personal members added'); + //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'); + //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'); + //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'); + //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'); + //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'); + //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'); + //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'); + //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'); + //LOG.debug(deletedMessages.length + ' personal messages deleted'); await this.db.deleteMessages(this.guildId, deletedMessages); } diff --git a/src/client/webapp/index.html b/src/client/webapp/index.html index 8b520ff..cca919b 100644 --- a/src/client/webapp/index.html +++ b/src/client/webapp/index.html @@ -43,24 +43,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/client/webapp/preload.ts b/src/client/webapp/preload.ts index b9b5059..c542bd9 100644 --- a/src/client/webapp/preload.ts +++ b/src/client/webapp/preload.ts @@ -13,8 +13,7 @@ import GuildsManager from './guilds-manager'; import Globals from './globals'; import UI from './ui'; -import Actions from './actions'; -import { Changes, ConnectionInfo, GuildMetadata, Member, Resource, Token } from './data-types'; +import { Changes, GuildMetadata, Member, Resource, Token } from './data-types'; import Q from './q-module'; import bindWindowButtonEvents from './elements/events-window-buttons'; import bindAddGuildEvents from './elements/events-add-guild'; @@ -82,27 +81,10 @@ window.addEventListener('DOMContentLoaded', () => { q.$('#guild-list .guild').click(); } - // Connection Events - - guildsManager.on('verified', async (guild: CombinedGuild) => { - (async () => { // update connection info - await Actions.fetchAndUpdateConnection(ui, guild); - })(); - // TODO: React set hasMessagesAbove and hasMessagesBelow when re-verified? - }); - - guildsManager.on('disconnect', (guild: CombinedGuild) => { - // Update everyone with the 'unknown' status - (async () => { - await Actions.fetchAndUpdateConnection(ui, guild); - })(); - }); - // Change Events guildsManager.on('update-metadata', async (guild: CombinedGuild, guildMeta: GuildMetadata) => { - LOG.debug(`g#${guild.id} metadata updated`) - await ui.updateGuildName(guild, guildMeta.name); + LOG.debug(`g#${guild.id} metadata updated`); // Not using withPotentialError since keeping the old icon is a fine fallback if (guildMeta.iconResourceId) { @@ -117,40 +99,18 @@ window.addEventListener('DOMContentLoaded', () => { } }); - guildsManager.on('update-members', async (guild: CombinedGuild, updatedMembers: Member[]) => { - LOG.debug(updatedMembers.length + ' updated members g#' + guild.id); - if ( - ui.activeConnection !== null && - updatedMembers.find(member => member.id === (ui.activeConnection as ConnectionInfo).id) - ) { - await Actions.fetchAndUpdateConnection(ui, guild); - } - }); - // TODO: React jump messages to bottom when the current user sent a message // Conflict Events guildsManager.on('conflict-metadata', async (guild: CombinedGuild, changesType: AutoVerifierChangesType, oldGuildMeta: GuildMetadata, newGuildMeta: GuildMetadata) => { LOG.debug('metadata conflict', { newGuildMeta: newGuildMeta }); - (async () => { await ui.updateGuildName(guild, newGuildMeta.name); })(); (async () => { const icon = await guild.fetchResource(newGuildMeta.iconResourceId); await ui.updateGuildIcon(guild, icon.data); })(); }); - guildsManager.on('conflict-members', async (guild: CombinedGuild, changesType: AutoVerifierChangesType, changes: Changes) => { - //LOG.debug('members conflict', { changes }); - if (changes.updated.length > 0) { - (async () => { - LOG.debug('updating conflict members connection...'); - // Likely getting called before the ram is updated - await Actions.fetchAndUpdateConnection(ui, guild); - })(); - } - }); - guildsManager.on('conflict-tokens', async (guild: CombinedGuild, changesType: AutoVerifierChangesType, changes: Changes) => { LOG.debug('tokens conflict', { changes }); // TODO diff --git a/src/client/webapp/styles/channel-list.scss b/src/client/webapp/styles/channel-list.scss index 47f16ea..9ee39bc 100644 --- a/src/client/webapp/styles/channel-list.scss +++ b/src/client/webapp/styles/channel-list.scss @@ -49,8 +49,3 @@ } } } - -#guild.privilege-modify_channels .channel:hover .modify, -#guild.privilege-modify_channels .channel.active .modify { - display: unset; -} diff --git a/src/client/webapp/styles/guild.scss b/src/client/webapp/styles/guild.scss index 21e47bc..7a8663b 100644 --- a/src/client/webapp/styles/guild.scss +++ b/src/client/webapp/styles/guild.scss @@ -1,10 +1,5 @@ @import "theme.scss"; -// TODO: Remove #guild -#guild { - display: none; -} - .guild-react { flex: 1; display: flex; diff --git a/src/client/webapp/ui.ts b/src/client/webapp/ui.ts index 0965b0e..a42fb2e 100644 --- a/src/client/webapp/ui.ts +++ b/src/client/webapp/ui.ts @@ -8,11 +8,11 @@ import ConcurrentQueue from '../../concurrent-queue/concurrent-queue'; import ElementsUtil from './elements/require/elements-util'; import CombinedGuild from './guild-combined'; -import { Message, Channel, ConnectionInfo, ShouldNeverHappenError } from './data-types'; +import { ShouldNeverHappenError } from './data-types'; import Q from './q-module'; import createGuildListGuild from './elements/guild-list-guild'; import GuildsManager from './guilds-manager'; -import { mountGuildChannelComponents, mountGuildComponents } from './elements/mounts'; +import { mountGuildComponents } from './elements/mounts'; interface SetMessageProps { atTop: boolean; @@ -21,15 +21,6 @@ interface SetMessageProps { export default class UI { public activeGuild: CombinedGuild | null = null; - public activeChannel: Channel | null = null; - public activeConnection: ConnectionInfo | null = null; - - public messagesAtTop = false; - public messagesAtBottom = false; - - public messagePairsGuild: CombinedGuild | null = null; - public messagePairsChannel: Channel | { id: string } | null = null; - public messagePairs = new Map(); // messageId -> { message: Message, element: HTMLElement } private document: Document; private q: Q; @@ -39,61 +30,10 @@ export default class UI { this.q = q; } - public isMessagePairsGuild(guild: CombinedGuild): boolean { - return this.messagePairsGuild !== null && guild.id === this.messagePairsGuild.id; - } - - public isMessagePairsChannel(channel: Channel): boolean { - return this.messagePairsChannel !== null && channel.id === this.messagePairsChannel.id; - } - // Use non-concurrent queues to prevent concurrent updates to parts of the view // This is effectively a javascript version of a 'lock' // These 'locks' should be called from working code rather than the updating functions themselves to work properly private _guildsLock = new ConcurrentQueue(1); - private _guildNameLock = new ConcurrentQueue(1); - private _connectionLock = new ConcurrentQueue(1); - private _channelsLock = new ConcurrentQueue(1); - private _membersLock = new ConcurrentQueue(1); - private _messagesLock = new ConcurrentQueue(1); - - private async _lockWithGuild(guild: CombinedGuild, task: (() => Promise | void), lock: ConcurrentQueue): Promise { - if (this.activeGuild === null || this.activeGuild.id !== guild.id) return; - await lock.push(async () => { - if (this.activeGuild === null || this.activeGuild.id !== guild.id) return; - await task(); - }); - } - - private async _lockWithGuildChannel(guild: CombinedGuild, channel: Channel | { id: string }, task: (() => Promise | void), lock: ConcurrentQueue): Promise { - if (this.activeGuild === null || this.activeGuild.id !== guild.id) return; - if (this.activeChannel === null || this.activeChannel.id !== channel.id) return; - await lock.push(async () => { - if (this.activeGuild === null || this.activeGuild.id !== guild.id) return; - if (this.activeChannel === null || this.activeChannel.id !== channel.id) return; - await task(); - }); - } - - public async lockGuildName(guild: CombinedGuild, task: (() => Promise | void)): Promise { - await this._lockWithGuild(guild, task, this._guildNameLock); - } - - public async lockConnection(guild: CombinedGuild, task: (() => Promise | void)): Promise { - await this._lockWithGuild(guild, task, this._connectionLock); - } - - public async lockChannels(guild: CombinedGuild, task: (() => Promise | void)): Promise { - await this._lockWithGuild(guild, task, this._channelsLock); - } - - public async lockMembers(guild: CombinedGuild, task: (() => Promise | void)): Promise { - await this._lockWithGuild(guild, task, this._membersLock); - } - - public async lockMessages(guild: CombinedGuild, channel: Channel | { id: string }, task: (() => Promise | void)): Promise { - await this._lockWithGuildChannel(guild, channel, task, this._messagesLock); - } public setActiveGuild(guild: CombinedGuild): void { if (this.activeGuild !== null) { @@ -104,29 +44,9 @@ export default class UI { } const next = this.q.$('#guild-list .guild[data-id="' + guild.id + '"]'); next.classList.add('active'); - this.q.$('#guild').setAttribute('data-id', guild.id + ''); - - mountGuildComponents(this.q, this, guild); this.activeGuild = guild; - } - - public async setActiveChannel(guild: CombinedGuild, channel: Channel): Promise { - await this.lockChannels(guild, () => { - this.activeChannel = channel; - mountGuildChannelComponents(this.q, guild, channel); - }); - } - - public async setActiveConnection(guild: CombinedGuild, connection: ConnectionInfo): Promise { - await this.lockConnection(guild, () => { - this.activeConnection = connection; - - this.q.$('#guild').className = ''; - for (const privilege of connection.privileges) { - this.q.$('#guild').classList.add('privilege-' + privilege); - } - }); + mountGuildComponents(this.q, this, guild); } public async setGuilds(guildsManager: GuildsManager, guilds: CombinedGuild[]): Promise { @@ -162,11 +82,4 @@ export default class UI { iconElement.src = await ElementsUtil.getImageBufferSrc(iconBuff); }); } - - public async updateGuildName(guild: CombinedGuild, name: string): Promise{ - await this.lockGuildName(guild, () => { - const baseElement = this.q.$('#guild-list .guild[data-id="' + guild.id + '"]'); - baseElement.setAttribute('meta-name', name); - }); - } }