fix: repeat preprocessing notifications
removed some logic of a8e0e06d84
before,
re-add it now
zio/stable
parent
333cab0858
commit
8d77f9e9fb
|
@ -17,7 +17,7 @@ const {
|
||||||
virtualScroller?: boolean
|
virtualScroller?: boolean
|
||||||
stream?: Promise<WsEvents>
|
stream?: Promise<WsEvents>
|
||||||
eventType?: 'notification' | 'update'
|
eventType?: 'notification' | 'update'
|
||||||
preprocess?: (items: T[]) => U[]
|
preprocess?: (items: (U | T)[]) => U[]
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineSlots<{
|
defineSlots<{
|
||||||
|
|
|
@ -23,7 +23,7 @@ const groupId = (item: mastodon.v1.Notification): string => {
|
||||||
return JSON.stringify(id)
|
return JSON.stringify(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
function preprocess(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
function groupItems(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
||||||
const results: NotificationSlot[] = []
|
const results: NotificationSlot[] = []
|
||||||
|
|
||||||
let id = 0
|
let id = 0
|
||||||
|
@ -108,6 +108,28 @@ function preprocess(items: mastodon.v1.Notification[]): NotificationSlot[] {
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function preprocess(items: NotificationSlot[]): NotificationSlot[] {
|
||||||
|
const flattenedNotifications: mastodon.v1.Notification[] = []
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.type === 'grouped-reblogs-and-favourites') {
|
||||||
|
const group = item
|
||||||
|
for (const like of group.likes) {
|
||||||
|
if (like.reblog)
|
||||||
|
flattenedNotifications.push(like.reblog)
|
||||||
|
if (like.favourite)
|
||||||
|
flattenedNotifications.push(like.favourite)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (item.type === 'grouped-follow') {
|
||||||
|
flattenedNotifications.push(...item.items)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
flattenedNotifications.push(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groupItems(flattenedNotifications)
|
||||||
|
}
|
||||||
|
|
||||||
const { clearNotifications } = useNotifications()
|
const { clearNotifications } = useNotifications()
|
||||||
const { formatNumber } = useHumanReadableNumber()
|
const { formatNumber } = useHumanReadableNumber()
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -5,7 +5,7 @@ export function usePaginator<T, P, U = T>(
|
||||||
paginator: Paginator<T[], P>,
|
paginator: Paginator<T[], P>,
|
||||||
stream?: Promise<WsEvents>,
|
stream?: Promise<WsEvents>,
|
||||||
eventType: 'notification' | 'update' = 'update',
|
eventType: 'notification' | 'update' = 'update',
|
||||||
preprocess: (items: T[]) => U[] = items => items as unknown as U[],
|
preprocess: (items: (T | U)[]) => U[] = items => items as unknown as U[],
|
||||||
buffer = 10,
|
buffer = 10,
|
||||||
) {
|
) {
|
||||||
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
|
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
|
||||||
|
@ -64,14 +64,14 @@ export function usePaginator<T, P, U = T>(
|
||||||
try {
|
try {
|
||||||
const result = await paginator.next()
|
const result = await paginator.next()
|
||||||
|
|
||||||
if (result.value?.length) {
|
if (!result.done && result.value.length) {
|
||||||
const preprocessedItems = preprocess([...nextItems.value, ...result.value]) as any
|
const preprocessedItems = preprocess([...nextItems.value, ...result.value] as (U | T)[])
|
||||||
const itemsToShowCount
|
const itemsToShowCount
|
||||||
= preprocessedItems.length < buffer
|
= preprocessedItems.length < buffer
|
||||||
? preprocessedItems.length
|
? preprocessedItems.length
|
||||||
: preprocessedItems.length - buffer
|
: preprocessedItems.length - buffer
|
||||||
nextItems.value = preprocessedItems.slice(itemsToShowCount)
|
;(nextItems.value as U[]) = preprocessedItems.slice(itemsToShowCount)
|
||||||
items.value.push(...preprocessedItems.slice(0, itemsToShowCount))
|
;(items.value as U[]).push(...preprocessedItems.slice(0, itemsToShowCount))
|
||||||
state.value = 'idle'
|
state.value = 'idle'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue