forked from coracle/flotilla
Improve loading and notifications
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import {derived} from "svelte/store"
|
import {derived} from "svelte/store"
|
||||||
import {synced, throttled} from "@welshman/store"
|
import {synced, throttled} from "@welshman/store"
|
||||||
import {pubkey} from "@welshman/app"
|
import {pubkey} from "@welshman/app"
|
||||||
import {prop, identity, now} from "@welshman/lib"
|
import {prop, spec, identity, now, groupBy} from "@welshman/lib"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
import {MESSAGE} from "@welshman/util"
|
import {MESSAGE, COMMENT, getTagValue} from "@welshman/util"
|
||||||
import {makeSpacePath, makeChatPath, makeThreadPath, makeRoomPath} from "@app/routes"
|
import {makeSpacePath, makeChatPath, makeThreadPath, makeRoomPath} from "@app/routes"
|
||||||
import {
|
import {
|
||||||
THREAD_FILTER,
|
THREAD_FILTER,
|
||||||
@@ -63,13 +63,26 @@ export const notifications = derived(
|
|||||||
for (const [url, rooms] of $userRoomsByUrl.entries()) {
|
for (const [url, rooms] of $userRoomsByUrl.entries()) {
|
||||||
const spacePath = makeSpacePath(url)
|
const spacePath = makeSpacePath(url)
|
||||||
const threadPath = makeThreadPath(url)
|
const threadPath = makeThreadPath(url)
|
||||||
const latestEvent = allThreadEvents.find(e => $getUrlsForEvent(e.id).includes(url))
|
const threadEvents = allThreadEvents.filter(e => $getUrlsForEvent(e.id).includes(url))
|
||||||
|
|
||||||
if (hasNotification(threadPath, latestEvent)) {
|
if (hasNotification(threadPath, threadEvents[0])) {
|
||||||
paths.add(spacePath)
|
paths.add(spacePath)
|
||||||
paths.add(threadPath)
|
paths.add(threadPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const commentsByThreadId = groupBy(
|
||||||
|
e => getTagValue("E", e.tags),
|
||||||
|
threadEvents.filter(spec({kind: COMMENT})),
|
||||||
|
)
|
||||||
|
|
||||||
|
for (const [threadId, [comment]] of commentsByThreadId.entries()) {
|
||||||
|
const threadItemPath = makeThreadPath(url, threadId)
|
||||||
|
|
||||||
|
if (hasNotification(threadItemPath, comment)) {
|
||||||
|
paths.add(threadItemPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const room of rooms) {
|
for (const room of rooms) {
|
||||||
const roomPath = makeRoomPath(url, room)
|
const roomPath = makeRoomPath(url, room)
|
||||||
const latestEvent = allMessageEvents.find(
|
const latestEvent = allMessageEvents.find(
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ export const listenForNotifications = () => {
|
|||||||
filters: [
|
filters: [
|
||||||
{kinds: [THREAD], since: now()},
|
{kinds: [THREAD], since: now()},
|
||||||
{kinds: [COMMENT], "#K": [String(THREAD)], since: now()},
|
{kinds: [COMMENT], "#K": [String(THREAD)], since: now()},
|
||||||
{kinds: [MESSAGE], "#h": Array.from(rooms), since: now()},
|
...Array.from(rooms).map(room => ({kinds: [MESSAGE], "#h": [room], since: now()})),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -64,8 +64,8 @@
|
|||||||
// Load recent messages for user rooms to help with a quick page transition
|
// Load recent messages for user rooms to help with a quick page transition
|
||||||
pullConservatively({relays, filters: rooms.map(r => ({kinds: [MESSAGE], "#h": [r], since}))})
|
pullConservatively({relays, filters: rooms.map(r => ({kinds: [MESSAGE], "#h": [r], since}))})
|
||||||
|
|
||||||
// Listen for deletes that would apply to messages we already have
|
// Listen for deletes that would apply to messages we already have, and new groups
|
||||||
const sub = subscribe({relays, filters: [{kinds: [DELETE], since}]})
|
const sub = subscribe({relays, filters: [{kinds: [DELETE, GROUPS], since}]})
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
sub.close()
|
sub.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user