mirror of
https://github.com/coracle-social/coracle.git
synced 2024-09-29 08:21:20 +00:00
Clean up nip 04 channel syncing
This commit is contained in:
parent
8700e2efe1
commit
ca3a7b073e
@ -40,7 +40,7 @@
|
||||
{/if}
|
||||
</NavItem>
|
||||
{#if $canUseGiftWrap}
|
||||
<NavItem href="/channels">
|
||||
<NavItem disabled={!$canSign} href="/channels">
|
||||
<i class="fa fa-envelope mr-2" /> Messages
|
||||
{#if $hasNewNip24Messages || $hasNewNip04Messages}
|
||||
<div
|
||||
|
@ -32,43 +32,51 @@ projections.addHandler(EventKind.AppData, async e => {
|
||||
const nip04 = getNip04(session)
|
||||
|
||||
if (d === appDataKeys.NIP04_LAST_CHECKED) {
|
||||
channels.mapStore.updateAsync(async $channels => {
|
||||
await tryJson(async () => {
|
||||
const payload = JSON.parse(await nip04.decryptAsUser(e.content, e.pubkey))
|
||||
const payload = tryJson(async () => JSON.parse(await nip04.decryptAsUser(e.content, e.pubkey)))
|
||||
|
||||
for (const [id, ts] of Object.entries(payload) as [string, number][]) {
|
||||
// Ignore weird old stuff
|
||||
if (id === "undefined" || id.includes("/")) {
|
||||
continue
|
||||
}
|
||||
if (payload) {
|
||||
const updates = {}
|
||||
|
||||
const channel =
|
||||
$channels.get(id) ||
|
||||
({
|
||||
id,
|
||||
type: "nip04",
|
||||
relays: getEventHints(e),
|
||||
messages: [],
|
||||
} as Channel)
|
||||
|
||||
$channels.set(id, {
|
||||
...channel,
|
||||
last_checked: Math.max(ts, channel.last_checked || 0),
|
||||
})
|
||||
|
||||
// No need to lock up the UI decrypting a bunch of stuff
|
||||
await sleep(16)
|
||||
for (const [id, ts] of Object.entries(payload) as [string, number][]) {
|
||||
// Ignore weird old stuff
|
||||
if (id === "undefined" || id.includes("/")) {
|
||||
continue
|
||||
}
|
||||
})
|
||||
|
||||
return $channels
|
||||
})
|
||||
const channel =
|
||||
channels.key(id).get() ||
|
||||
({
|
||||
id,
|
||||
type: "nip04",
|
||||
relays: getEventHints(e),
|
||||
messages: [],
|
||||
} as Channel)
|
||||
|
||||
updates[id] = {
|
||||
...channel,
|
||||
last_checked: Math.max(ts, channel.last_checked || 0),
|
||||
}
|
||||
|
||||
// No need to lock up the UI decrypting a bunch of stuff
|
||||
await sleep(16)
|
||||
}
|
||||
|
||||
channels.mapStore.update($channels => {
|
||||
for (const [k, v] of Object.entries(updates)) {
|
||||
$channels.set(k, v as Channel)
|
||||
}
|
||||
|
||||
return $channels
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (d === appDataKeys.NIP24_LAST_CHECKED) {
|
||||
await tryJson(async () => {
|
||||
const payload = JSON.parse(await nip04.decryptAsUser(e.content, e.pubkey))
|
||||
const payload = await tryJson(async () =>
|
||||
JSON.parse(await nip04.decryptAsUser(e.content, e.pubkey))
|
||||
)
|
||||
|
||||
if (payload) {
|
||||
channels.mapStore.update($channels => {
|
||||
for (const [id, ts] of Object.entries(payload) as [string, number][]) {
|
||||
const channel = $channels.get(id)
|
||||
@ -81,7 +89,7 @@ projections.addHandler(EventKind.AppData, async e => {
|
||||
|
||||
return $channels
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -22,7 +22,7 @@ export const nip59 = derived(
|
||||
([$session, $nip44, $signer]) => new Nip59($session, $nip44, $signer)
|
||||
)
|
||||
|
||||
export const canSign = signer.derived($signer => $signer.canSign())
|
||||
export const canSign = signer.derived($signer => $signer.canSign() && window.crypto.subtle)
|
||||
|
||||
export const canUseGiftWrap = session.derived($session => $session?.method === "privkey")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user