remove unused old guild root element
This commit is contained in:
parent
3620c758fd
commit
579050e867
@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
@ -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) => {
|
||||
|
@ -19,6 +19,7 @@ const GuildElement: FC<GuildElementProps> = (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);
|
||||
|
@ -57,41 +57,41 @@ export default class PersonalDBGuild implements AsyncFetchable, AsyncLackable {
|
||||
}
|
||||
|
||||
async handleMembersAdded(addedMembers: Member[]): Promise<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
LOG.debug(deletedMessages.length + ' personal messages deleted');
|
||||
//LOG.debug(deletedMessages.length + ' personal messages deleted');
|
||||
await this.db.deleteMessages(this.guildId, deletedMessages);
|
||||
}
|
||||
|
||||
|
@ -43,24 +43,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="guild-anchor"></div>
|
||||
<div id="guild">
|
||||
<div id="guild-sidebar">
|
||||
<div class="guild-title-anchor"></div>
|
||||
<div class="channel-list-anchor"></div>
|
||||
<div id="channel-list"></div>
|
||||
<div class="connection-anchor"></div>
|
||||
</div>
|
||||
<div id="channel">
|
||||
<div class="channel-title-anchor"></div>
|
||||
<div id="channel-content">
|
||||
<div id="channel-feed-wrapper">
|
||||
<div class="message-list-anchor"></div>
|
||||
<div class="send-message-input-wrapper-anchor"></div>
|
||||
</div>
|
||||
<div class="member-list-anchor"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- it's important that this comes at the end so that these take prescedence over the other absolutely positioned objects-->
|
||||
<div id="react-overlays"></div>
|
||||
|
@ -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<Member>) => {
|
||||
//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<Token>) => {
|
||||
LOG.debug('tokens conflict', { changes });
|
||||
// TODO
|
||||
|
@ -49,8 +49,3 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#guild.privilege-modify_channels .channel:hover .modify,
|
||||
#guild.privilege-modify_channels .channel.active .modify {
|
||||
display: unset;
|
||||
}
|
||||
|
@ -1,10 +1,5 @@
|
||||
@import "theme.scss";
|
||||
|
||||
// TODO: Remove #guild
|
||||
#guild {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.guild-react {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
|
@ -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<string | null, { message: Message, element: Element }>(); // 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<void>(1);
|
||||
private _guildNameLock = new ConcurrentQueue<void>(1);
|
||||
private _connectionLock = new ConcurrentQueue<void>(1);
|
||||
private _channelsLock = new ConcurrentQueue<void>(1);
|
||||
private _membersLock = new ConcurrentQueue<void>(1);
|
||||
private _messagesLock = new ConcurrentQueue<void>(1);
|
||||
|
||||
private async _lockWithGuild(guild: CombinedGuild, task: (() => Promise<void> | void), lock: ConcurrentQueue<void>): Promise<void> {
|
||||
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> | void), lock: ConcurrentQueue<void>): Promise<void> {
|
||||
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> | void)): Promise<void> {
|
||||
await this._lockWithGuild(guild, task, this._guildNameLock);
|
||||
}
|
||||
|
||||
public async lockConnection(guild: CombinedGuild, task: (() => Promise<void> | void)): Promise<void> {
|
||||
await this._lockWithGuild(guild, task, this._connectionLock);
|
||||
}
|
||||
|
||||
public async lockChannels(guild: CombinedGuild, task: (() => Promise<void> | void)): Promise<void> {
|
||||
await this._lockWithGuild(guild, task, this._channelsLock);
|
||||
}
|
||||
|
||||
public async lockMembers(guild: CombinedGuild, task: (() => Promise<void> | void)): Promise<void> {
|
||||
await this._lockWithGuild(guild, task, this._membersLock);
|
||||
}
|
||||
|
||||
public async lockMessages(guild: CombinedGuild, channel: Channel | { id: string }, task: (() => Promise<void> | void)): Promise<void> {
|
||||
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<void> {
|
||||
await this.lockChannels(guild, () => {
|
||||
this.activeChannel = channel;
|
||||
mountGuildChannelComponents(this.q, guild, channel);
|
||||
});
|
||||
}
|
||||
|
||||
public async setActiveConnection(guild: CombinedGuild, connection: ConnectionInfo): Promise<void> {
|
||||
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<void> {
|
||||
@ -162,11 +82,4 @@ export default class UI {
|
||||
iconElement.src = await ElementsUtil.getImageBufferSrc(iconBuff);
|
||||
});
|
||||
}
|
||||
|
||||
public async updateGuildName(guild: CombinedGuild, name: string): Promise<void>{
|
||||
await this.lockGuildName(guild, () => {
|
||||
const baseElement = this.q.$('#guild-list .guild[data-id="' + guild.id + '"]');
|
||||
baseElement.setAttribute('meta-name', name);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user