Fix channels last view ()

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-05 15:11:24 +06:00 committed by GitHub
parent 442fcace43
commit a212a850ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions
plugins/contact-resources/src/components

View File

@ -50,7 +50,7 @@
export let focusIndex = -1 export let focusIndex = -1
export let restricted: Ref<ChannelProvider>[] = [] export let restricted: Ref<ChannelProvider>[] = []
let lastViews: Writable<LastView> = writable() let lastViews: Writable<LastView | undefined> = writable()
getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews())) getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews()))
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -70,7 +70,7 @@
function getProvider ( function getProvider (
item: AttachedData<Channel>, item: AttachedData<Channel>,
map: Map<Ref<ChannelProvider>, ChannelProvider>, map: Map<Ref<ChannelProvider>, ChannelProvider>,
lastViews: LastView lastViews: LastView | undefined
): Item | undefined { ): Item | undefined {
const provider = map.get(item.provider) const provider = map.get(item.provider)
if (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 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 return lastView ? lastView < item.lastMessage : (item.items ?? 0) > 0
} }
async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView) { async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView | undefined) {
if (value == null) { if (value == null) {
displayItems = [] displayItems = []
return return

View File

@ -31,7 +31,7 @@
export let reverse: boolean = false export let reverse: boolean = false
export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>() export let integrations: Set<Ref<Doc>> = new Set<Ref<Doc>>()
let lastViews: Writable<LastView> = writable() let lastViews: Writable<LastView | undefined> = writable()
getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews())) getResource(notification.function.GetNotificationClient).then((res) => (lastViews = res().getLastViews()))
interface Item { interface Item {
@ -48,7 +48,7 @@
function getProvider ( function getProvider (
item: AttachedData<Channel>, item: AttachedData<Channel>,
map: Map<Ref<ChannelProvider>, ChannelProvider>, map: Map<Ref<ChannelProvider>, ChannelProvider>,
lastViews: LastView lastViews: LastView | undefined
): any | undefined { ): any | undefined {
const provider = map.get(item.provider) const provider = map.get(item.provider)
if (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 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 return lastView ? lastView < item.lastMessage : (item.items ?? 0) > 0
} }
async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView) { async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView | undefined) {
if (value === null) { if (value === null) {
displayItems = [] displayItems = []
return return