Fix channels last view (#2894)

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

View File

@ -50,7 +50,7 @@
export let focusIndex = -1
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()))
const dispatch = createEventDispatcher()
@ -70,7 +70,7 @@
function getProvider (
item: AttachedData<Channel>,
map: Map<Ref<ChannelProvider>, 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>[] | Channel | null, lastViews: LastView) {
async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView | undefined) {
if (value == null) {
displayItems = []
return

View File

@ -31,7 +31,7 @@
export let reverse: boolean = false
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()))
interface Item {
@ -48,7 +48,7 @@
function getProvider (
item: AttachedData<Channel>,
map: Map<Ref<ChannelProvider>, 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>[] | Channel | null, lastViews: LastView) {
async function update (value: AttachedData<Channel>[] | Channel | null, lastViews: LastView | undefined) {
if (value === null) {
displayItems = []
return