forked from coracle/flotilla
Account for thunks when figuring out which urls an event is on
This commit is contained in:
Generated
+23
-21
@@ -31,15 +31,15 @@
|
||||
"@types/throttle-debounce": "^5.0.2",
|
||||
"@vite-pwa/assets-generator": "^0.2.6",
|
||||
"@vite-pwa/sveltekit": "^0.6.6",
|
||||
"@welshman/app": "~0.0.31",
|
||||
"@welshman/content": "~0.0.12",
|
||||
"@welshman/app": "~0.0.32",
|
||||
"@welshman/content": "~0.0.13",
|
||||
"@welshman/dvm": "~0.0.10",
|
||||
"@welshman/feeds": "~0.0.26",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"@welshman/net": "~0.0.39",
|
||||
"@welshman/net": "~0.0.40",
|
||||
"@welshman/signer": "~0.0.16",
|
||||
"@welshman/store": "~0.0.12",
|
||||
"@welshman/util": "~0.0.46",
|
||||
"@welshman/util": "~0.0.48",
|
||||
"daisyui": "^4.12.10",
|
||||
"date-picker-svelte": "^2.13.0",
|
||||
"dotenv": "^16.4.5",
|
||||
@@ -4664,18 +4664,18 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@welshman/app": {
|
||||
"version": "0.0.31",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/app/-/app-0.0.31.tgz",
|
||||
"integrity": "sha512-Z6h14hbaJ8OFtmxtD4R+bmVDUFUQnctbBWUWxA3ZpRLeGN8xn8zRXXIp5cfKBbRtoAHiPwvDYRrbArsal6md1w==",
|
||||
"version": "0.0.32",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/app/-/app-0.0.32.tgz",
|
||||
"integrity": "sha512-f3JQq4JgR2fCeAOWbjsq1w+tv3U80NhuhAcq1qMBT+DRfHPw/LdYN6U10u+pL2tZbwBbPNs8cTJ/p7Lqy5GJzw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@welshman/dvm": "~0.0.10",
|
||||
"@welshman/feeds": "~0.0.26",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"@welshman/net": "~0.0.39",
|
||||
"@welshman/net": "~0.0.40",
|
||||
"@welshman/signer": "~0.0.16",
|
||||
"@welshman/store": "~0.0.12",
|
||||
"@welshman/util": "~0.0.46",
|
||||
"@welshman/util": "~0.0.48",
|
||||
"fuse.js": "^7.0.0",
|
||||
"idb": "^8.0.0",
|
||||
"svelte": "^4.2.18",
|
||||
@@ -4683,11 +4683,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@welshman/content": {
|
||||
"version": "0.0.12",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/content/-/content-0.0.12.tgz",
|
||||
"integrity": "sha512-hdrZkHlDKJx8i8FdEJo4NFlBMRJWDkZHBYCBCbx77fcxPN8nJ2yKCl7bmIM51XwEFRrZMOQrmQswvYuOr8h1DQ==",
|
||||
"version": "0.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/content/-/content-0.0.13.tgz",
|
||||
"integrity": "sha512-03usB7VXE5w5Fm2+MfZOf3P1SiHBU8H4pWcv3xX439xWZ3LZlTS7WX9p4GwsfzX4iLCOLPNzEVNzw21JhLYSzA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@braintree/sanitize-url": "^7.0.2",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"nostr-tools": "^2.7.2"
|
||||
}
|
||||
},
|
||||
@@ -4726,13 +4728,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@welshman/net": {
|
||||
"version": "0.0.39",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/net/-/net-0.0.39.tgz",
|
||||
"integrity": "sha512-GSzLrTxLNm9fSLMVJtnrFw/6LVhxXvKmC4or0H7/fn/W3lHxYMLI8VuFg58M3CbDGcJuB8FBhPnOzL4TUSiElw==",
|
||||
"version": "0.0.40",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/net/-/net-0.0.40.tgz",
|
||||
"integrity": "sha512-GdvnxWlzNeARw1v3HfJzFcEGccHj4njFclZFdDfe11qqGZcpNvbDdmJ0gPyY2cCeUnaV+9W7o7DYV9JZwTRUng==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@welshman/lib": "~0.0.27",
|
||||
"@welshman/util": "~0.0.46",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"@welshman/util": "~0.0.48",
|
||||
"isomorphic-ws": "^5.0.0",
|
||||
"ws": "^8.16.0"
|
||||
}
|
||||
@@ -4764,12 +4766,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@welshman/util": {
|
||||
"version": "0.0.46",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/util/-/util-0.0.46.tgz",
|
||||
"integrity": "sha512-kf9pvedUY3osPMUHVsV7rdInKK0JRMMttIYNWXhOgVPmZM7ssGky507fpwrx/6pxoAT1zWsUDuUt/GXJRWt9+w==",
|
||||
"version": "0.0.48",
|
||||
"resolved": "https://registry.npmjs.org/@welshman/util/-/util-0.0.48.tgz",
|
||||
"integrity": "sha512-j+ZnnWvBk19XuhjRWO2YFj16vagUiPxpOQdCWf8TmxZFqCVOBbna9BPsKj89uriVyvDa9KRhv9EY+CMh5kurhQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@welshman/lib": "~0.0.27",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"nostr-tools": "^2.7.2"
|
||||
}
|
||||
},
|
||||
|
||||
+4
-4
@@ -59,15 +59,15 @@
|
||||
"@types/throttle-debounce": "^5.0.2",
|
||||
"@vite-pwa/assets-generator": "^0.2.6",
|
||||
"@vite-pwa/sveltekit": "^0.6.6",
|
||||
"@welshman/app": "~0.0.31",
|
||||
"@welshman/content": "~0.0.12",
|
||||
"@welshman/app": "~0.0.32",
|
||||
"@welshman/content": "~0.0.13",
|
||||
"@welshman/dvm": "~0.0.10",
|
||||
"@welshman/feeds": "~0.0.26",
|
||||
"@welshman/lib": "~0.0.28",
|
||||
"@welshman/net": "~0.0.39",
|
||||
"@welshman/net": "~0.0.40",
|
||||
"@welshman/signer": "~0.0.16",
|
||||
"@welshman/store": "~0.0.12",
|
||||
"@welshman/util": "~0.0.46",
|
||||
"@welshman/util": "~0.0.48",
|
||||
"daisyui": "^4.12.10",
|
||||
"date-picker-svelte": "^2.13.0",
|
||||
"dotenv": "^16.4.5",
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
<LongPress
|
||||
data-event={event.id}
|
||||
onLongPress={inert ? null : onLongPress}
|
||||
class="group relative flex w-full cursor-default flex-col p-2 pb-3 text-left hover:z-feature">
|
||||
class="group relative flex w-full cursor-default flex-col p-2 pb-3 text-left">
|
||||
<div class="flex w-full gap-3 overflow-auto">
|
||||
{#if showPubkey}
|
||||
<Link external href={pubkeyLink(event.pubkey)} class="flex items-start">
|
||||
|
||||
+32
-22
@@ -16,6 +16,7 @@ import {
|
||||
shuffle,
|
||||
parseJson,
|
||||
fromPairs,
|
||||
memoize,
|
||||
} from "@welshman/lib"
|
||||
import {
|
||||
getIdFilters,
|
||||
@@ -57,7 +58,8 @@ import {
|
||||
createSearch,
|
||||
userFollows,
|
||||
ensurePlaintext,
|
||||
thunkWorker,
|
||||
thunks,
|
||||
walkThunks,
|
||||
} from "@welshman/app"
|
||||
import type {AppSyncOpts, Thunk} from "@welshman/app"
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
@@ -247,17 +249,35 @@ export const deriveEvent = (idOrAddress: string, hints: string[] = []) => {
|
||||
)
|
||||
}
|
||||
|
||||
export const getEventsForUrl = (url: string, filters: Filter[]) =>
|
||||
sortBy(
|
||||
e => -e.created_at,
|
||||
repository.query(filters).filter(e => tracker.hasRelay(e.id, url)),
|
||||
)
|
||||
export const getUrlsForEvent = derived([trackerStore, thunks], ([$tracker, $thunks]) => {
|
||||
const getThunksByEventId = memoize(() => {
|
||||
const thunksByEventId = new Map<string, Thunk[]>()
|
||||
|
||||
for (const thunk of walkThunks(Object.values($thunks))) {
|
||||
pushToMapKey(thunksByEventId, thunk.event.id, thunk)
|
||||
}
|
||||
|
||||
return thunksByEventId
|
||||
})
|
||||
|
||||
return (id: string) => {
|
||||
const urls = Array.from($tracker.getRelays(id))
|
||||
|
||||
for (const thunk of getThunksByEventId().get(id) || []) {
|
||||
for (const url of thunk.request.relays) {
|
||||
urls.push(url)
|
||||
}
|
||||
}
|
||||
|
||||
return uniq(urls)
|
||||
}
|
||||
})
|
||||
|
||||
export const deriveEventsForUrl = (url: string, filters: Filter[]) =>
|
||||
derived([deriveEvents(repository, {filters}), trackerStore], ([$events, $tracker]) =>
|
||||
derived([deriveEvents(repository, {filters}), getUrlsForEvent], ([$events, $getUrlsForEvent]) =>
|
||||
sortBy(
|
||||
e => -e.created_at,
|
||||
$events.filter(e => $tracker.hasRelay(e.id, url)),
|
||||
$events.filter(e => $getUrlsForEvent(e.id).includes(url)),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -273,16 +293,6 @@ setContext({
|
||||
}),
|
||||
})
|
||||
|
||||
// Track what urls we're attempting to send messages to so we can associate them with spaces immediately
|
||||
|
||||
thunkWorker.addGlobalHandler((thunk: Thunk) => {
|
||||
if (thunk.event.tags.find(t => t[0] === ROOM)) {
|
||||
for (const url of thunk.request.relays) {
|
||||
tracker.track(thunk.event.id, url)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Settings
|
||||
|
||||
export const canDecrypt = synced("canDecrypt", false)
|
||||
@@ -473,8 +483,8 @@ export const splitChannelId = (id: string) => id.split("|")
|
||||
|
||||
export const channelsById = withGetter(
|
||||
derived(
|
||||
[groupMeta, memberships, messages, trackerStore],
|
||||
([$groupMeta, $memberships, $messages, $tracker]) => {
|
||||
[groupMeta, memberships, messages, getUrlsForEvent],
|
||||
([$groupMeta, $memberships, $messages, $getUrlsForEvent]) => {
|
||||
const eventsByChannelId = new Map<string, TrustedEvent[]>()
|
||||
|
||||
// Add known rooms by membership so we have a full listing even if there are no messages there
|
||||
@@ -489,7 +499,7 @@ export const channelsById = withGetter(
|
||||
const [_, room] = event.tags.find(nthEq(0, ROOM)) || []
|
||||
|
||||
if (room) {
|
||||
for (const url of $tracker.getRelays(event.id)) {
|
||||
for (const url of $getUrlsForEvent(event.id)) {
|
||||
pushToMapKey(eventsByChannelId, makeChannelId(url, room), event)
|
||||
}
|
||||
}
|
||||
@@ -520,7 +530,7 @@ export const channelsById = withGetter(
|
||||
const room = meta.d
|
||||
|
||||
if (room) {
|
||||
for (const url of $tracker.getRelays(event.id)) {
|
||||
for (const url of $getUrlsForEvent(event.id)) {
|
||||
const id = makeChannelId(url, room)
|
||||
const channel: Channel = channelsById.get(id) || {
|
||||
url,
|
||||
|
||||
Reference in New Issue
Block a user