From a212a850edb20871cec534a80739ee947477695b Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Wed, 5 Apr 2023 15:11:24 +0600 Subject: [PATCH] Fix channels last view (#2894) Signed-off-by: Denis Bykhov --- .../src/components/ChannelsDropdown.svelte | 11 ++++++----- .../src/components/ChannelsView.svelte | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/contact-resources/src/components/ChannelsDropdown.svelte b/plugins/contact-resources/src/components/ChannelsDropdown.svelte index 6c4e799bb4..f92300b16d 100644 --- a/plugins/contact-resources/src/components/ChannelsDropdown.svelte +++ b/plugins/contact-resources/src/components/ChannelsDropdown.svelte @@ -50,7 +50,7 @@ export let focusIndex = -1 export let restricted: Ref[] = [] - let lastViews: Writable = writable() + let lastViews: Writable = writable() getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews())) const dispatch = createEventDispatcher() @@ -70,7 +70,7 @@ function getProvider ( item: AttachedData, map: Map, ChannelProvider>, - lastViews: LastView + lastViews: LastView | undefined ): Item | undefined { const provider = map.get(item.provider) if (provider) { @@ -92,13 +92,14 @@ } } - function isNew (item: Channel, lastViews: LastView): boolean { + function isNew (item: Channel, lastViews: LastView | undefined): boolean { if (item.lastMessage === undefined) return false - const lastView = (item as Channel)._id !== undefined ? lastViews[(item as Channel)._id] : undefined + const lastView = + (item as Channel)._id !== undefined && lastViews !== undefined ? lastViews[(item as Channel)._id] : undefined return lastView ? lastView < item.lastMessage : (item.items ?? 0) > 0 } - async function update (value: AttachedData[] | Channel | null, lastViews: LastView) { + async function update (value: AttachedData[] | Channel | null, lastViews: LastView | undefined) { if (value == null) { displayItems = [] return diff --git a/plugins/contact-resources/src/components/ChannelsView.svelte b/plugins/contact-resources/src/components/ChannelsView.svelte index 93d2dcc038..ac03c61cd1 100644 --- a/plugins/contact-resources/src/components/ChannelsView.svelte +++ b/plugins/contact-resources/src/components/ChannelsView.svelte @@ -31,7 +31,7 @@ export let reverse: boolean = false export let integrations: Set> = new Set>() - let lastViews: Writable = writable() + let lastViews: Writable = writable() getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews())) interface Item { @@ -48,7 +48,7 @@ function getProvider ( item: AttachedData, map: Map, ChannelProvider>, - lastViews: LastView + lastViews: LastView | undefined ): any | undefined { const provider = map.get(item.provider) if (provider) { @@ -66,13 +66,14 @@ } } - function isNew (item: Channel, lastViews: LastView): boolean { + function isNew (item: Channel, lastViews: LastView | undefined): boolean { if (item.lastMessage === undefined) return false - const lastView = (item as Channel)._id !== undefined ? lastViews[(item as Channel)._id] : undefined + const lastView = + (item as Channel)._id !== undefined && lastViews !== undefined ? lastViews[(item as Channel)._id] : undefined return lastView ? lastView < item.lastMessage : (item.items ?? 0) > 0 } - async function update (value: AttachedData[] | Channel | null, lastViews: LastView) { + async function update (value: AttachedData[] | Channel | null, lastViews: LastView | undefined) { if (value === null) { displayItems = [] return