Only load messages on message page, avoid duplicates
This commit is contained in:
parent
48e2fff4f8
commit
89a9d37379
4 changed files with 31 additions and 31 deletions
|
|
@ -70,7 +70,7 @@
|
||||||
class="group relative flex w-full flex-col gap-1 p-2 text-left transition-colors {inert
|
class="group relative flex w-full flex-col gap-1 p-2 text-left transition-colors {inert
|
||||||
? 'hover:bg-base-300'
|
? 'hover:bg-base-300'
|
||||||
: ''}">
|
: ''}">
|
||||||
<div class="flex w-full gap-3">
|
<div class="flex w-full gap-3 overflow-auto">
|
||||||
{#if showPubkey}
|
{#if showPubkey}
|
||||||
<Link external href={pubkeyLink(event.pubkey)} class="flex items-start">
|
<Link external href={pubkeyLink(event.pubkey)} class="flex items-start">
|
||||||
<Avatar src={$profile?.picture} class="border border-solid border-base-content" size={10} />
|
<Avatar src={$profile?.picture} class="border border-solid border-base-content" size={10} />
|
||||||
|
|
|
||||||
|
|
@ -130,12 +130,6 @@
|
||||||
tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}),
|
tracker: storageAdapters.fromTracker(tracker, {throttle: 1000}),
|
||||||
}).then(() => sleep(300))
|
}).then(() => sleep(300))
|
||||||
|
|
||||||
repository.on("update", ({added}) => {
|
|
||||||
for (const event of added) {
|
|
||||||
state.ensureUnwrapped(event)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for (const url of INDEXER_RELAYS) {
|
for (const url of INDEXER_RELAYS) {
|
||||||
loadRelay(url)
|
loadRelay(url)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,32 +3,49 @@
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {WEEK, ctx, ago} from "@welshman/lib"
|
import {WEEK, ctx, ago} from "@welshman/lib"
|
||||||
import {WRAP} from "@welshman/util"
|
import {WRAP} from "@welshman/util"
|
||||||
import {pubkey, subscribe} from "@welshman/app"
|
import type {TrustedEvent} from "@welshman/util"
|
||||||
|
import {pubkey, repository, subscribe} from "@welshman/app"
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Page from "@lib/components/Page.svelte"
|
import Page from "@lib/components/Page.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
|
import Spinner from "@lib/components/Spinner.svelte"
|
||||||
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
import SecondaryNav from "@lib/components/SecondaryNav.svelte"
|
||||||
import SecondaryNavHeader from "@lib/components/SecondaryNavHeader.svelte"
|
import SecondaryNavHeader from "@lib/components/SecondaryNavHeader.svelte"
|
||||||
import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte"
|
import SecondaryNavSection from "@lib/components/SecondaryNavSection.svelte"
|
||||||
import ChatStart from "@app/components/ChatStart.svelte"
|
import ChatStart from "@app/components/ChatStart.svelte"
|
||||||
import ChatItem from "@app/components/ChatItem.svelte"
|
import ChatItem from "@app/components/ChatItem.svelte"
|
||||||
import {chatSearch, pullConservatively} from "@app/state"
|
import {chatSearch, pullConservatively, ensureUnwrapped} from "@app/state"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
|
|
||||||
const startChat = () => pushModal(ChatStart)
|
const startChat = () => pushModal(ChatStart)
|
||||||
|
|
||||||
|
const promise = pullConservatively({
|
||||||
|
filters: [{kinds: [WRAP], "#p": [$pubkey!], until: ago(WEEK)}],
|
||||||
|
relays: ctx.app.router.UserInbox().getUrls(),
|
||||||
|
})
|
||||||
|
|
||||||
|
const onUpdate = ({added}: {added: TrustedEvent[]}) => {
|
||||||
|
for (const event of added) {
|
||||||
|
ensureUnwrapped(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let term = ""
|
let term = ""
|
||||||
|
|
||||||
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
|
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const filter = {kinds: [WRAP], "#p": [$pubkey!]}
|
const sub = subscribe({
|
||||||
const relays = ctx.app.router.UserInbox().getUrls()
|
filters: [{kinds: [WRAP], "#p": [$pubkey!], since: ago(WEEK)}],
|
||||||
const sub = subscribe({filters: [{...filter, since: ago(WEEK)}], relays})
|
relays: ctx.app.router.UserInbox().getUrls(),
|
||||||
|
})
|
||||||
|
|
||||||
pullConservatively({filters: [filter], relays})
|
repository.on("update", onUpdate)
|
||||||
|
|
||||||
return () => sub.close()
|
return () => {
|
||||||
|
sub.close()
|
||||||
|
repository.off("update", onUpdate)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -50,6 +67,11 @@
|
||||||
{#each chats as { id, pubkeys, messages } (id)}
|
{#each chats as { id, pubkeys, messages } (id)}
|
||||||
<ChatItem {id} {pubkeys} {messages} />
|
<ChatItem {id} {pubkeys} {messages} />
|
||||||
{/each}
|
{/each}
|
||||||
|
{#await promise}
|
||||||
|
<div class="border-t border-solid border-base-100 px-6 py-4 text-xs">
|
||||||
|
<Spinner loading>Loading conversations...</Spinner>
|
||||||
|
</div>
|
||||||
|
{/await}
|
||||||
</div>
|
</div>
|
||||||
{/key}
|
{/key}
|
||||||
</SecondaryNav>
|
</SecondaryNav>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onMount} from "svelte"
|
|
||||||
import {ctx, ago} from "@welshman/lib"
|
|
||||||
import {WRAP} from "@welshman/util"
|
|
||||||
import {pubkey, subscribe} from "@welshman/app"
|
|
||||||
import Icon from "@lib/components/Icon.svelte"
|
import Icon from "@lib/components/Icon.svelte"
|
||||||
import Button from "@lib/components/Button.svelte"
|
import Button from "@lib/components/Button.svelte"
|
||||||
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
import ContentSearch from "@lib/components/ContentSearch.svelte"
|
||||||
import ChatItem from "@app/components/ChatItem.svelte"
|
import ChatItem from "@app/components/ChatItem.svelte"
|
||||||
import ChatStart from "@app/components/ChatStart.svelte"
|
import ChatStart from "@app/components/ChatStart.svelte"
|
||||||
import {chatSearch, pullConservatively} from "@app/state"
|
import {chatSearch} from "@app/state"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
|
|
||||||
let term = ""
|
let term = ""
|
||||||
|
|
@ -16,18 +12,6 @@
|
||||||
const startChat = () => pushModal(ChatStart)
|
const startChat = () => pushModal(ChatStart)
|
||||||
|
|
||||||
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
|
$: chats = $chatSearch.searchOptions(term).filter(c => c.pubkeys.length > 1)
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const filter = {kinds: [WRAP], "#p": [$pubkey!]}
|
|
||||||
const sub = subscribe({filters: [{...filter, since: ago(30)}]})
|
|
||||||
|
|
||||||
pullConservatively({
|
|
||||||
filters: [filter],
|
|
||||||
relays: ctx.app.router.UserInbox().getUrls(),
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => sub.close()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="hidden min-h-screen md:hero">
|
<div class="hidden min-h-screen md:hero">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue