forked from coracle/flotilla
Update to new version of welshman, including new thunks and wrap manager
This commit is contained in:
+8
-13
@@ -17,7 +17,6 @@ import {
|
||||
getPubkeyTagValues,
|
||||
} from "@welshman/util"
|
||||
import {
|
||||
ensureUnwrapped,
|
||||
makeChatId,
|
||||
entityLink,
|
||||
decodeRelay,
|
||||
@@ -85,20 +84,16 @@ export const getPrimaryNavItemIndex = ($page: Page) => {
|
||||
}
|
||||
|
||||
export const goToEvent = async (event: TrustedEvent, options: Record<string, any> = {}) => {
|
||||
const unwrapped = await ensureUnwrapped(event)
|
||||
const urls = Array.from(tracker.getRelays(event.id))
|
||||
const path = await getEventPath(event, urls)
|
||||
|
||||
if (unwrapped) {
|
||||
const urls = Array.from(tracker.getRelays(unwrapped.id))
|
||||
const path = await getEventPath(unwrapped, urls)
|
||||
if (path.includes("://")) {
|
||||
window.open(path)
|
||||
} else {
|
||||
goto(path, options)
|
||||
|
||||
if (path.includes("://")) {
|
||||
window.open(path)
|
||||
} else {
|
||||
goto(path, options)
|
||||
|
||||
await sleep(300)
|
||||
await scrollToEvent(unwrapped.id)
|
||||
}
|
||||
await sleep(300)
|
||||
await scrollToEvent(event.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-1
@@ -33,7 +33,7 @@ import {
|
||||
verifiedSymbol,
|
||||
} from "@welshman/util"
|
||||
import type {Zapper, TrustedEvent} from "@welshman/util"
|
||||
import type {RepositoryUpdate} from "@welshman/relay"
|
||||
import type {RepositoryUpdate, WrapItem} from "@welshman/net"
|
||||
import type {Handle, Relay} from "@welshman/app"
|
||||
import {
|
||||
plaintext,
|
||||
@@ -44,6 +44,7 @@ import {
|
||||
zappers,
|
||||
onZapper,
|
||||
onHandle,
|
||||
wrapManager,
|
||||
} from "@welshman/app"
|
||||
import {Collection} from "@lib/storage"
|
||||
|
||||
@@ -258,6 +259,28 @@ const syncPlaintext = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
const syncWrapManager = async () => {
|
||||
const collection = new Collection<WrapItem>({
|
||||
table: "wraps",
|
||||
shards: Array.from("0123456789abcdef"),
|
||||
getShard: (item: WrapItem) => last(hash(item.id)),
|
||||
})
|
||||
|
||||
wrapManager.load(await collection.get())
|
||||
|
||||
const addOne = batch(3000, (wrapItems: WrapItem[]) => collection.add(wrapItems))
|
||||
|
||||
const updateAll = throttle(3000, () => collection.set(wrapManager.dump()))
|
||||
|
||||
wrapManager.on("add", addOne)
|
||||
wrapManager.on("remove", updateAll)
|
||||
|
||||
return () => {
|
||||
wrapManager.off("add", addOne)
|
||||
wrapManager.off("remove", updateAll)
|
||||
}
|
||||
}
|
||||
|
||||
export const syncDataStores = () =>
|
||||
Promise.all([
|
||||
syncEvents(),
|
||||
@@ -267,4 +290,5 @@ export const syncDataStores = () =>
|
||||
syncZappers(),
|
||||
syncFreshness(),
|
||||
syncPlaintext(),
|
||||
syncWrapManager(),
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user