From 0e56a2acc014555817e31df835502345f8c8819b Mon Sep 17 00:00:00 2001 From: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> Date: Sat, 11 Jun 2022 00:36:47 +0600 Subject: [PATCH] Channels Disappear Fix (#2060) Signed-off-by: Denis Bykhov <80476319+BykhovDenis@users.noreply.github.com> --- .../components/EditChannelSettingsTab.svelte | 4 +-- plugins/chunter-resources/src/index.ts | 2 +- .../src/components/Navigator.svelte | 25 ++++++++++++------- plugins/workbench-resources/src/utils.ts | 4 ++- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte b/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte index f9ef16b1c0..05a7f5d654 100644 --- a/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte +++ b/plugins/chunter-resources/src/components/EditChannelSettingsTab.svelte @@ -15,8 +15,8 @@ label={chunter.string.ArchiveChannel} justify={'left'} size={'x-large'} - on:click={() => { - ArchiveChannel(channel, () => dispatch('close')) + on:click={(evt) => { + ArchiveChannel(channel, evt, () => dispatch('close')) }} /> {/if} diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index f38e6963a7..857d763947 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -105,7 +105,7 @@ export async function UnpinMessage (message: ChunterMessage): Promise { ) } -export async function ArchiveChannel (channel: Channel, afterArchive?: () => void): Promise { +export async function ArchiveChannel (channel: Channel, evt: any, afterArchive?: () => void): Promise { showPopup( MessageBox, { diff --git a/plugins/workbench-resources/src/components/Navigator.svelte b/plugins/workbench-resources/src/components/Navigator.svelte index a240d9a6c6..57ef19cb21 100644 --- a/plugins/workbench-resources/src/components/Navigator.svelte +++ b/plugins/workbench-resources/src/components/Navigator.svelte @@ -69,9 +69,15 @@ ) }) + let requestIndex = 0 async function update (model: NavigatorModel, spaces: Space[], preferences: Map, SpacePreference>) { + shownSpaces = spaces.filter( + (sp) => !sp.archived && !preferences.has(sp._id) && (!sp.private || sp.members.includes(myAccId)) + ) + starred = spaces.filter((sp) => preferences.has(sp._id)) if (model.specials !== undefined) { - const sp = await updateSpecials(model.specials, spaces) + const [sp, resIndex] = await updateSpecials(model.specials, spaces, ++requestIndex) + if (resIndex !== requestIndex) return const topSpecials = sp.get('top') ?? [] const bottomSpecials = sp.get('bottom') ?? [] sp.delete('top') @@ -88,17 +94,17 @@ } else { specials = [] } - shownSpaces = spaces.filter( - (sp) => !sp.archived && !preferences.has(sp._id) && (!sp.members.length || sp.members.includes(myAccId)) - ) - starred = spaces.filter((sp) => preferences.has(sp._id)) } $: if (model) update(model, spaces, preferences) - async function updateSpecials (specials: SpecialNavModel[], spaces: Space[]): Promise> { + async function updateSpecials ( + specials: SpecialNavModel[], + spaces: Space[], + requestIndex: number + ): Promise<[Map, number]> { const result = new Map() - for (const sp of specials) { + const promises = specials.map(async (sp) => { const pos = sp.position ?? 'top' let visible = true if (sp.visibleIf !== undefined) { @@ -110,8 +116,9 @@ list.push(sp) result.set(pos, list) } - } - return result + }) + await Promise.all(promises) + return [result, requestIndex] } const dispatch = createEventDispatcher() diff --git a/plugins/workbench-resources/src/utils.ts b/plugins/workbench-resources/src/utils.ts index ef59ec2e6e..21e4d6e5bb 100644 --- a/plugins/workbench-resources/src/utils.ts +++ b/plugins/workbench-resources/src/utils.ts @@ -28,7 +28,9 @@ export function classIcon (client: Client, _class: Ref>): Asset | und } export function getSpecialSpaceClass (model: NavigatorModel): Array>> { const spaceResult = model.spaces.map((x) => x.spaceClass) - const result = (model.specials ?? []).map((it) => it.spaceClass).filter((it) => it !== undefined) + const result = (model.specials ?? []) + .map((it) => it.spaceClass) + .filter((it) => it !== undefined && !spaceResult.includes(it)) return spaceResult.concat(result as Array>>) }