forked from coracle/flotilla
Re-work thread sorting and loading, fix some display bugs with reaction tooltips, fix thunk status loading indicator
This commit is contained in:
@@ -109,7 +109,7 @@
|
|||||||
{#if !isHead}
|
{#if !isHead}
|
||||||
<ReplySummary relays={[url]} {event} on:click={onClick} />
|
<ReplySummary relays={[url]} {event} on:click={onClick} />
|
||||||
{/if}
|
{/if}
|
||||||
<ReactionSummary relays={[url]} {event} {onReactionClick} />
|
<ReactionSummary relays={[url]} {event} {onReactionClick} reactionClass="tooltip-right" />
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
class="join absolute right-1 top-1 border border-solid border-neutral text-xs opacity-0 transition-all"
|
class="join absolute right-1 top-1 border border-solid border-neutral text-xs opacity-0 transition-all"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
export let showPubkey = false
|
export let showPubkey = false
|
||||||
|
|
||||||
const thunk = $thunks[event.id]
|
const thunk = $thunks[event.id]
|
||||||
|
const isOwn = event.pubkey === $pubkey
|
||||||
const profile = deriveProfile(event.pubkey)
|
const profile = deriveProfile(event.pubkey)
|
||||||
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
const profileDisplay = deriveProfileDisplay(event.pubkey)
|
||||||
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
const [_, colorValue] = colors[parseInt(hash(event.pubkey)) % colors.length]
|
||||||
@@ -62,9 +63,9 @@
|
|||||||
<div
|
<div
|
||||||
data-event={event.id}
|
data-event={event.id}
|
||||||
class="group chat flex items-center justify-end gap-1 px-2"
|
class="group chat flex items-center justify-end gap-1 px-2"
|
||||||
class:chat-start={event.pubkey !== $pubkey}
|
class:chat-start={!isOwn}
|
||||||
class:flex-row-reverse={event.pubkey !== $pubkey}
|
class:flex-row-reverse={!isOwn}
|
||||||
class:chat-end={event.pubkey === $pubkey}>
|
class:chat-end={isOwn}>
|
||||||
<Tippy
|
<Tippy
|
||||||
bind:popover
|
bind:popover
|
||||||
component={ChatMessageMenu}
|
component={ChatMessageMenu}
|
||||||
@@ -87,27 +88,29 @@
|
|||||||
<Icon icon="menu-dots" size={4} />
|
<Icon icon="menu-dots" size={4} />
|
||||||
</button>
|
</button>
|
||||||
</Tippy>
|
</Tippy>
|
||||||
<div class="flex min-w-0 flex-col" class:items-end={event.pubkey === $pubkey}>
|
<div class="flex min-w-0 flex-col" class:items-end={isOwn}>
|
||||||
<LongPress
|
<LongPress
|
||||||
class="bg-alt chat-bubble mx-1 flex cursor-auto flex-col gap-1 text-left lg:max-w-2xl"
|
class="bg-alt chat-bubble mx-1 flex cursor-auto flex-col gap-1 text-left lg:max-w-2xl"
|
||||||
onLongPress={showMobileMenu}>
|
onLongPress={showMobileMenu}>
|
||||||
{#if showPubkey && event.pubkey !== $pubkey}
|
{#if showPubkey}
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<Link external href={pubkeyLink(event.pubkey)} class="flex items-center gap-1">
|
{#if !isOwn}
|
||||||
<Avatar
|
<Link external href={pubkeyLink(event.pubkey)} class="flex items-center gap-1">
|
||||||
src={$profile?.picture}
|
<Avatar
|
||||||
class="border border-solid border-base-content"
|
src={$profile?.picture}
|
||||||
size={4} />
|
class="border border-solid border-base-content"
|
||||||
<div class="flex items-center gap-2">
|
size={4} />
|
||||||
<Link
|
<div class="flex items-center gap-2">
|
||||||
external
|
<Link
|
||||||
href={pubkeyLink(event.pubkey)}
|
external
|
||||||
class="text-sm font-bold"
|
href={pubkeyLink(event.pubkey)}
|
||||||
style="color: {colorValue}">
|
class="text-sm font-bold"
|
||||||
{$profileDisplay}
|
style="color: {colorValue}">
|
||||||
</Link>
|
{$profileDisplay}
|
||||||
</div>
|
</Link>
|
||||||
</Link>
|
</div>
|
||||||
|
</Link>
|
||||||
|
{/if}
|
||||||
<span class="text-xs opacity-50">{formatTimestampAsTime(event.created_at)}</span>
|
<span class="text-xs opacity-50">{formatTimestampAsTime(event.created_at)}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -117,7 +120,7 @@
|
|||||||
</LongPress>
|
</LongPress>
|
||||||
<div class="row-2 z-feature -mt-1 ml-4">
|
<div class="row-2 z-feature -mt-1 ml-4">
|
||||||
<ReplySummary {event} />
|
<ReplySummary {event} />
|
||||||
<ReactionSummary {event} {onReactionClick} />
|
<ReactionSummary {event} {onReactionClick} noTooltip />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,11 +5,14 @@
|
|||||||
import {deriveEvents} from "@welshman/store"
|
import {deriveEvents} from "@welshman/store"
|
||||||
import {pubkey, repository, load, displayProfileByPubkey} from "@welshman/app"
|
import {pubkey, repository, load, displayProfileByPubkey} from "@welshman/app"
|
||||||
import {displayList} from "@lib/util"
|
import {displayList} from "@lib/util"
|
||||||
|
import {isMobile} from "@lib/html"
|
||||||
import {displayReaction} from "@app/state"
|
import {displayReaction} from "@app/state"
|
||||||
|
|
||||||
export let event
|
export let event
|
||||||
export let onReactionClick
|
export let onReactionClick
|
||||||
export let relays: string[] = []
|
export let relays: string[] = []
|
||||||
|
export let reactionClass = ""
|
||||||
|
export let noTooltip = false
|
||||||
|
|
||||||
const filters = [{kinds: [REACTION], "#e": [event.id]}]
|
const filters = [{kinds: [REACTION], "#e": [event.id]}]
|
||||||
const reactions = deriveEvents(repository, {filters})
|
const reactions = deriveEvents(repository, {filters})
|
||||||
@@ -35,7 +38,8 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-tip={tooltip}
|
data-tip={tooltip}
|
||||||
class="flex-inline btn btn-neutral btn-xs tooltip tooltip-right gap-1 rounded-full"
|
class="flex-inline btn btn-neutral btn-xs gap-1 rounded-full {reactionClass}"
|
||||||
|
class:tooltip={!noTooltip && !isMobile}
|
||||||
class:border={isOwn}
|
class:border={isOwn}
|
||||||
class:border-solid={isOwn}
|
class:border-solid={isOwn}
|
||||||
class:border-primary={isOwn}
|
class:border-primary={isOwn}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||||
<div class="flex flex-grow flex-wrap justify-end gap-2">
|
<div class="flex flex-grow flex-wrap justify-end gap-2">
|
||||||
<ReactionSummary relays={[url]} {event} {onReactionClick} />
|
<ReactionSummary relays={[url]} {event} {onReactionClick} reactionClass="tooltip-left" />
|
||||||
{#if $deleted}
|
{#if $deleted}
|
||||||
<div class="btn btn-error btn-xs rounded-full">Deleted</div>
|
<div class="btn btn-error btn-xs rounded-full">Deleted</div>
|
||||||
{:else if thunk}
|
{:else if thunk}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
in:fly
|
in:fly
|
||||||
out:slideAndFade
|
out:slideAndFade
|
||||||
on:submit|preventDefault={submit}
|
on:submit|preventDefault={submit}
|
||||||
class="card2 sticky bottom-2 z-feature mx-2 mt-2 bg-neutral">
|
class="card2 sticky bottom-2 z-feature mx-2 mt-4 bg-neutral">
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<div class="note-editor flex-grow overflow-hidden">
|
<div class="note-editor flex-grow overflow-hidden">
|
||||||
<EditorContent editor={$editor} />
|
<EditorContent editor={$editor} />
|
||||||
|
|||||||
@@ -30,8 +30,10 @@
|
|||||||
$: isFailure = !canCancel && ps.every(s => [Failure, Timeout].includes(s.status))
|
$: isFailure = !canCancel && ps.every(s => [Failure, Timeout].includes(s.status))
|
||||||
$: failure = Object.entries($status).find(([url, s]) => [Failure, Timeout].includes(s.status))
|
$: failure = Object.entries($status).find(([url, s]) => [Failure, Timeout].includes(s.status))
|
||||||
|
|
||||||
|
// Delay updating isPending so users can see that the message is sent
|
||||||
$: {
|
$: {
|
||||||
// Delay updating isPending so users can see that the message is sent
|
isPending = isPending || ps.some(s => s.status == Pending)
|
||||||
|
|
||||||
if (!ps.some(s => s.status == Pending)) {
|
if (!ps.some(s => s.status == Pending)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isPending = false
|
isPending = false
|
||||||
@@ -44,11 +46,11 @@
|
|||||||
{#if isFailure && failure}
|
{#if isFailure && failure}
|
||||||
{@const [url, {message, status}] = failure}
|
{@const [url, {message, status}] = failure}
|
||||||
<Tippy
|
<Tippy
|
||||||
class={$$props.class}
|
class="flex items-center {$$props.class}"
|
||||||
component={ThunkStatusDetail}
|
component={ThunkStatusDetail}
|
||||||
props={{url, message, status, retry}}
|
props={{url, message, status, retry}}
|
||||||
params={{interactive: true}}>
|
params={{interactive: true}}>
|
||||||
<span class="tooltip flex cursor-pointer items-center gap-1">
|
<span class="flex cursor-pointer items-center gap-1">
|
||||||
<Icon icon="danger" size={3} />
|
<Icon icon="danger" size={3} />
|
||||||
<span class="opacity-50">Failed to send!</span>
|
<span class="opacity-50">Failed to send!</span>
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="card2 bg-alt col-2">
|
<div class="card2 bg-alt col-2 shadow-2xl">
|
||||||
<p>
|
<p>
|
||||||
Failed to publish to {displayRelayUrl(url)}: {message}.
|
Failed to publish to {displayRelayUrl(url)}: {message}.
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
@@ -193,10 +193,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Listen for space data, populate space-based notifications
|
// Listen for space data, populate space-based notifications
|
||||||
let unsubRooms: any
|
let unsubSpaces: any
|
||||||
|
|
||||||
userMembership.subscribe($membership => {
|
userMembership.subscribe($membership => {
|
||||||
unsubRooms?.()
|
unsubSpaces?.()
|
||||||
|
|
||||||
const since = ago(30)
|
const since = ago(30)
|
||||||
const rooms = uniq(getMembershipRooms($membership).map(m => m.room)).concat(GENERAL)
|
const rooms = uniq(getMembershipRooms($membership).map(m => m.room)).concat(GENERAL)
|
||||||
@@ -213,7 +213,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Listen for new notifications/memberships
|
// Listen for new notifications/memberships
|
||||||
unsubRooms = subscribePersistent({
|
unsubSpaces = subscribePersistent({
|
||||||
relays,
|
relays,
|
||||||
filters: [
|
filters: [
|
||||||
{kinds: [THREAD], since},
|
{kinds: [THREAD], since},
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {onMount} from "svelte"
|
import {onMount} from "svelte"
|
||||||
|
import {derived} from "svelte/store"
|
||||||
import {page} from "$app/stores"
|
import {page} from "$app/stores"
|
||||||
import {sortBy, sleep, uniqBy, now} from "@welshman/lib"
|
import {sortBy, min, nthEq, sleep} from "@welshman/lib"
|
||||||
import {getListTags, getPubkeyTagValues, LOCAL_RELAY_URL} from "@welshman/util"
|
import {getListTags, getPubkeyTagValues} from "@welshman/util"
|
||||||
import type {TrustedEvent} from "@welshman/util"
|
import {throttled} from "@welshman/store"
|
||||||
import {feedsFromFilters, makeIntersectionFeed, makeRelayFeed} from "@welshman/feeds"
|
import {feedsFromFilters, makeIntersectionFeed, makeRelayFeed} from "@welshman/feeds"
|
||||||
import {nthEq} from "@welshman/lib"
|
|
||||||
import {createFeedController, userMutes} from "@welshman/app"
|
import {createFeedController, userMutes} from "@welshman/app"
|
||||||
import {createScroller, type Scroller} from "@lib/html"
|
import {createScroller, type Scroller} from "@lib/html"
|
||||||
import {fly} from "@lib/transition"
|
import {fly} from "@lib/transition"
|
||||||
@@ -16,40 +16,50 @@
|
|||||||
import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte"
|
import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte"
|
||||||
import ThreadItem from "@app/components/ThreadItem.svelte"
|
import ThreadItem from "@app/components/ThreadItem.svelte"
|
||||||
import ThreadCreate from "@app/components/ThreadCreate.svelte"
|
import ThreadCreate from "@app/components/ThreadCreate.svelte"
|
||||||
import {THREAD, COMMENT, decodeRelay, getEventsForUrl} from "@app/state"
|
import {THREAD, COMMENT, decodeRelay, deriveEventsForUrl} from "@app/state"
|
||||||
import {subscribePersistent} from "@app/commands"
|
|
||||||
import {THREAD_FILTERS, setChecked} from "@app/notifications"
|
import {THREAD_FILTERS, setChecked} from "@app/notifications"
|
||||||
import {pushModal} from "@app/modal"
|
import {pushModal} from "@app/modal"
|
||||||
|
|
||||||
const url = decodeRelay($page.params.relay)
|
const url = decodeRelay($page.params.relay)
|
||||||
|
const threads = deriveEventsForUrl(url, [{kinds: [THREAD]}])
|
||||||
|
const comments = deriveEventsForUrl(url, [{kinds: [COMMENT], "#K": [String(THREAD)]}])
|
||||||
const mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
|
const mutedPubkeys = getPubkeyTagValues(getListTags($userMutes))
|
||||||
|
|
||||||
|
const events = throttled(
|
||||||
|
800,
|
||||||
|
derived([threads, comments], ([$threads, $comments]) => {
|
||||||
|
const scores = new Map<string, number>()
|
||||||
|
|
||||||
|
for (const comment of $comments) {
|
||||||
|
const id = comment.tags.find(nthEq(0, "E"))?.[1]
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
scores.set(id, min([scores.get(id), -comment.created_at]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sortBy(
|
||||||
|
e => min([scores.get(e.id), -e.created_at]),
|
||||||
|
$threads.filter(e => !mutedPubkeys.includes(e.pubkey)),
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
const createThread = () => pushModal(ThreadCreate, {url})
|
const createThread = () => pushModal(ThreadCreate, {url})
|
||||||
|
|
||||||
const ctrl = createFeedController({
|
const ctrl = createFeedController({
|
||||||
useWindowing: true,
|
useWindowing: true,
|
||||||
feed: makeIntersectionFeed(makeRelayFeed(url), feedsFromFilters(THREAD_FILTERS)),
|
feed: makeIntersectionFeed(makeRelayFeed(url), feedsFromFilters(THREAD_FILTERS)),
|
||||||
onEvent: (event: TrustedEvent) => {
|
|
||||||
if (
|
|
||||||
event.kind === THREAD &&
|
|
||||||
!event.tags.some(nthEq(0, "e")) &&
|
|
||||||
!mutedPubkeys.includes(event.pubkey)
|
|
||||||
) {
|
|
||||||
buffer.push(event)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onExhausted: () => {
|
onExhausted: () => {
|
||||||
loading = false
|
loading = false
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let limit = 10
|
||||||
let loading = true
|
let loading = true
|
||||||
let unmounted = false
|
let unmounted = false
|
||||||
let element: Element
|
let element: Element
|
||||||
let scroller: Scroller
|
let scroller: Scroller
|
||||||
let buffer: TrustedEvent[] = []
|
|
||||||
let events: TrustedEvent[] = sortBy(e => -e.created_at, getEventsForUrl(url, [{kinds: [THREAD]}]))
|
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Element is frequently not defined. I don't know why
|
// Element is frequently not defined. I don't know why
|
||||||
@@ -60,10 +70,9 @@
|
|||||||
delay: 300,
|
delay: 300,
|
||||||
threshold: 3000,
|
threshold: 3000,
|
||||||
onScroll: () => {
|
onScroll: () => {
|
||||||
buffer = sortBy(e => -e.created_at, buffer)
|
limit += 10
|
||||||
events = uniqBy(e => e.id, [...events, ...buffer.splice(0, 5)])
|
|
||||||
|
|
||||||
if (buffer.length < 50) {
|
if ($events.length - limit < 10) {
|
||||||
ctrl.load(50)
|
ctrl.load(50)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -71,26 +80,7 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const unsub = subscribePersistent({
|
|
||||||
relays: [url, LOCAL_RELAY_URL],
|
|
||||||
filters: [
|
|
||||||
{kinds: [THREAD], since: now()},
|
|
||||||
{kinds: [COMMENT], "#K": [String(THREAD)], since: now()},
|
|
||||||
],
|
|
||||||
onEvent: (event: TrustedEvent) => {
|
|
||||||
if (event.kind === THREAD) {
|
|
||||||
const index = Math.max(
|
|
||||||
0,
|
|
||||||
events.findIndex(e => e.created_at < event.created_at),
|
|
||||||
)
|
|
||||||
|
|
||||||
events = [...events.slice(0, index), event, ...events.slice(index)]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
unsub()
|
|
||||||
unmounted = true
|
unmounted = true
|
||||||
scroller?.stop()
|
scroller?.stop()
|
||||||
setChecked($page.url.pathname)
|
setChecked($page.url.pathname)
|
||||||
@@ -113,17 +103,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</PageBar>
|
</PageBar>
|
||||||
<div class="flex flex-grow flex-col gap-2 overflow-auto p-2">
|
<div class="flex flex-grow flex-col gap-2 overflow-auto p-2">
|
||||||
{#each events as event (event.id)}
|
{#each $events as event (event.id)}
|
||||||
<div in:fly>
|
<div in:fly>
|
||||||
<ThreadItem {url} {event} />
|
<ThreadItem {url} {event} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{#if loading || events.length === 0}
|
{#if loading || $events.length === 0}
|
||||||
<p class="flex h-10 items-center justify-center py-20" out:fly>
|
<p class="flex h-10 items-center justify-center py-20" out:fly>
|
||||||
<Spinner {loading}>
|
<Spinner {loading}>
|
||||||
{#if loading}
|
{#if loading}
|
||||||
Looking for threads...
|
Looking for threads...
|
||||||
{:else if events.length === 0}
|
{:else if $events.length === 0}
|
||||||
No threads found.
|
No threads found.
|
||||||
{/if}
|
{/if}
|
||||||
</Spinner>
|
</Spinner>
|
||||||
|
|||||||
Reference in New Issue
Block a user