fix: improve messages with proper diffing and pageination, fix -1 inbox
This commit is contained in:
6 files changed
+96
-23
No files matched your search
@@ -59,7 +59,7 @@
|
|||||||
label={$t('profile.profile')}
|
label={$t('profile.profile')}
|
||||||
/>
|
/>
|
||||||
<SidebarButton icon={Inbox} href="/inbox" label={$t('profile.inbox')}>
|
<SidebarButton icon={Inbox} href="/inbox" label={$t('profile.inbox')}>
|
||||||
{#if notifications.inbox}
|
{#if notifications.inbox > 0}
|
||||||
<Badge
|
<Badge
|
||||||
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
||||||
color="red-subtle"
|
color="red-subtle"
|
||||||
|
|||||||
@@ -101,12 +101,7 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<CommonList size="md">
|
<CommonList size="md">
|
||||||
{#each data.inbox.value as item}
|
{#each data.inbox.value as item}
|
||||||
<li
|
<li class={[!item.read && 'bg-blue-300/10! dark:bg-blue-500/5!']}>
|
||||||
class={[
|
|
||||||
'lg:px-2.5 lg:py-1.5',
|
|
||||||
!item.read && 'bg-blue-300/10! dark:bg-blue-500/5!',
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<InboxItem {item} />
|
<InboxItem {item} />
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -52,7 +52,13 @@ export async function load({ url, fetch }) {
|
|||||||
const data = [
|
const data = [
|
||||||
...replies.replies.map(generalizeCommentReply),
|
...replies.replies.map(generalizeCommentReply),
|
||||||
...mentions.mentions.map(generalizePersonMention),
|
...mentions.mentions.map(generalizePersonMention),
|
||||||
...privateMessages.private_messages.map(generalizePrivateMessage),
|
...privateMessages.private_messages
|
||||||
|
.filter(
|
||||||
|
(i) =>
|
||||||
|
i.private_message.creator_id !=
|
||||||
|
profile.current.user?.local_user_view.person.id,
|
||||||
|
)
|
||||||
|
.map(generalizePrivateMessage),
|
||||||
].sort(
|
].sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
publishedToDate(b.published).getTime() -
|
publishedToDate(b.published).getTime() -
|
||||||
|
|||||||
@@ -9,9 +9,16 @@
|
|||||||
import PrivateMessage from '$lib/feature/inbox/PrivateMessage.svelte'
|
import PrivateMessage from '$lib/feature/inbox/PrivateMessage.svelte'
|
||||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||||
import { publishedToDate } from '$lib/ui/util/date'
|
import { publishedToDate } from '$lib/ui/util/date'
|
||||||
import { Button, ButtonGroup, Expandable } from 'mono-svelte'
|
import { Button, ButtonGroup, Expandable, Material } from 'mono-svelte'
|
||||||
import RelativeDate from 'mono-svelte/util/RelativeDate.svelte'
|
import RelativeDate from 'mono-svelte/util/RelativeDate.svelte'
|
||||||
import { Eye, EyeSlash } from 'svelte-hero-icons/dist'
|
import {
|
||||||
|
AtSymbol,
|
||||||
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
Eye,
|
||||||
|
EyeSlash,
|
||||||
|
Icon,
|
||||||
|
PaperAirplane,
|
||||||
|
} from 'svelte-hero-icons/dist'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
item: InboxItem
|
item: InboxItem
|
||||||
@@ -92,7 +99,25 @@
|
|||||||
<Expandable open icon={false}>
|
<Expandable open icon={false}>
|
||||||
{#snippet title()}
|
{#snippet title()}
|
||||||
<div class="flex flex-row gap-2 items-center w-full">
|
<div class="flex flex-row gap-2 items-center w-full">
|
||||||
<Avatar url={item.creator.avatar} width={28} alt={item.creator.name} />
|
<div class="relative">
|
||||||
|
<Avatar url={item.creator.avatar} width={28} alt={item.creator.name} />
|
||||||
|
<Material
|
||||||
|
color="uniform"
|
||||||
|
padding="none"
|
||||||
|
class="absolute -bottom-2 -right-2 p-1"
|
||||||
|
rounding="full"
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
src={item.type == 'comment_reply'
|
||||||
|
? ChatBubbleOvalLeftEllipsis
|
||||||
|
: item.type == 'person_mention'
|
||||||
|
? AtSymbol
|
||||||
|
: PaperAirplane}
|
||||||
|
size="12"
|
||||||
|
micro
|
||||||
|
/>
|
||||||
|
</Material>
|
||||||
|
</div>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<div class="text-sm font-normal text-slate-600 dark:text-zinc-400">
|
<div class="text-sm font-normal text-slate-600 dark:text-zinc-400">
|
||||||
{#if item.type == 'comment_reply'}
|
{#if item.type == 'comment_reply'}
|
||||||
|
|||||||
@@ -10,10 +10,12 @@
|
|||||||
import { report } from '$lib/feature/moderation/moderation'
|
import { report } from '$lib/feature/moderation/moderation'
|
||||||
import UserLink from '$lib/feature/user/UserLink.svelte'
|
import UserLink from '$lib/feature/user/UserLink.svelte'
|
||||||
import { Header } from '$lib/ui/layout'
|
import { Header } from '$lib/ui/layout'
|
||||||
|
import { publishedToDate } from '$lib/ui/util/date'
|
||||||
import { Button, Material, TextInput, toast } from 'mono-svelte'
|
import { Button, Material, TextInput, toast } from 'mono-svelte'
|
||||||
import { onDestroy, onMount, tick } from 'svelte'
|
import { onDestroy, onMount, tick } from 'svelte'
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
ArrowLeft,
|
||||||
|
ChevronUp,
|
||||||
Icon,
|
Icon,
|
||||||
Minus,
|
Minus,
|
||||||
PaperAirplane,
|
PaperAirplane,
|
||||||
@@ -87,8 +89,33 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let interval: number = -1
|
let interval: number = -1
|
||||||
|
let page: number = 1
|
||||||
|
|
||||||
onMount(() => {
|
async function loadMore(page: number = 1) {
|
||||||
|
const res = await client().getPrivateMessages({
|
||||||
|
creator_id: Number(data.creator.value.person_view.person.id),
|
||||||
|
limit: 50,
|
||||||
|
page: page,
|
||||||
|
})
|
||||||
|
|
||||||
|
const messageSet = new Set(
|
||||||
|
data.message!.value.private_messages.map((i) => i.private_message.id),
|
||||||
|
)
|
||||||
|
const newMessages = res.private_messages.filter(
|
||||||
|
(i) => !messageSet.has(i.private_message.id),
|
||||||
|
)
|
||||||
|
|
||||||
|
data.message.value.private_messages.push(...newMessages)
|
||||||
|
data.message.value.private_messages.sort(
|
||||||
|
(a, b) =>
|
||||||
|
publishedToDate(b.private_message.published).getTime() -
|
||||||
|
publishedToDate(a.private_message.published).getTime(),
|
||||||
|
)
|
||||||
|
|
||||||
|
markRead()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function markRead() {
|
||||||
data.message.value.private_messages
|
data.message.value.private_messages
|
||||||
.filter(
|
.filter(
|
||||||
(i) =>
|
(i) =>
|
||||||
@@ -102,15 +129,11 @@
|
|||||||
read: true,
|
read: true,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
interval = setInterval(async () => {
|
onMount(() => {
|
||||||
const res = await client().getPrivateMessages({
|
markRead()
|
||||||
creator_id: Number(data.creator.value.person_view.person.id),
|
interval = setInterval(loadMore, 10 * 1000) as unknown as number
|
||||||
limit: 50,
|
|
||||||
page: 1,
|
|
||||||
})
|
|
||||||
data.message.value = res
|
|
||||||
}, 15 * 1000) as unknown as number
|
|
||||||
|
|
||||||
return () => clearInterval(interval)
|
return () => clearInterval(interval)
|
||||||
})
|
})
|
||||||
@@ -120,6 +143,14 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>
|
||||||
|
{$t('routes.inbox.messages.indicator', {
|
||||||
|
user: data.creator.value.person_view.person.name,
|
||||||
|
})}
|
||||||
|
</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<Header pageHeader>
|
<Header pageHeader>
|
||||||
{$t('filter.inbox.messages')}
|
{$t('filter.inbox.messages')}
|
||||||
{#snippet extended()}
|
{#snippet extended()}
|
||||||
@@ -134,6 +165,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
<Material
|
<Material
|
||||||
color="transparent"
|
color="transparent"
|
||||||
rounding="2xl"
|
rounding="2xl"
|
||||||
@@ -141,7 +173,7 @@
|
|||||||
class="bg-white dark:bg-zinc-950 dark:border-t-zinc-900 w-full overflow-auto relative flex-1 min-h-0 max-h-[66vh] md:max-h-[64vh]"
|
class="bg-white dark:bg-zinc-950 dark:border-t-zinc-900 w-full overflow-auto relative flex-1 min-h-0 max-h-[66vh] md:max-h-[64vh]"
|
||||||
>
|
>
|
||||||
<div class="h-full overflow-auto max-w-full" bind:this={chatWindow}>
|
<div class="h-full overflow-auto max-w-full" bind:this={chatWindow}>
|
||||||
<ul id="chat-window" class=" flex flex-col gap-1 flex-1 px-4 py-4 min-h-0">
|
<ul id="chat-window" class="flex flex-col gap-1 flex-1 px-4 py-4 min-h-0">
|
||||||
<div class="mt-auto"></div>
|
<div class="mt-auto"></div>
|
||||||
<p class="mx-auto mt-auto text-slate-400 dark:text-zinc-600 text-center">
|
<p class="mx-auto mt-auto text-slate-400 dark:text-zinc-600 text-center">
|
||||||
{$t('routes.inbox.messages.conversation', {
|
{$t('routes.inbox.messages.conversation', {
|
||||||
@@ -151,6 +183,16 @@
|
|||||||
new URL(data.creator.value.person_view.person.actor_id).hostname,
|
new URL(data.creator.value.person_view.person.actor_id).hostname,
|
||||||
})}
|
})}
|
||||||
</p>
|
</p>
|
||||||
|
{#if data.message.value.private_messages.length % data.limit == 0}
|
||||||
|
<Button
|
||||||
|
onclick={() => loadMore(++page)}
|
||||||
|
color="ghost"
|
||||||
|
size="square-md"
|
||||||
|
title={$t('common.next')}
|
||||||
|
icon={ChevronUp}
|
||||||
|
class="mx-auto"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
{#each data.message.value.private_messages.toReversed() as private_message, index (private_message.private_message.id)}
|
{#each data.message.value.private_messages.toReversed() as private_message, index (private_message.private_message.id)}
|
||||||
{@const messages = data.message.value.private_messages.toReversed()}
|
{@const messages = data.message.value.private_messages.toReversed()}
|
||||||
{@const showTimestamp =
|
{@const showTimestamp =
|
||||||
@@ -167,7 +209,10 @@
|
|||||||
in:fly|global={{
|
in:fly|global={{
|
||||||
duration: 700,
|
duration: 700,
|
||||||
easing: backOut,
|
easing: backOut,
|
||||||
delay: data.message.value.private_messages.length * 50 - index * 50,
|
delay:
|
||||||
|
index < messages.length - 15
|
||||||
|
? 0
|
||||||
|
: data.message.value.private_messages.length * 50 - index * 50,
|
||||||
y: -12,
|
y: -12,
|
||||||
}}
|
}}
|
||||||
animate:flip={{ duration: 500, easing: expoOut }}
|
animate:flip={{ duration: 500, easing: expoOut }}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ReactiveState } from '$lib/app/util.svelte'
|
|||||||
|
|
||||||
export async function load({ fetch, params }) {
|
export async function load({ fetch, params }) {
|
||||||
const creator = Number(params.user_id)
|
const creator = Number(params.user_id)
|
||||||
|
const LIMIT = 50
|
||||||
|
|
||||||
const userPromise = client({ func: fetch }).getPersonDetails({
|
const userPromise = client({ func: fetch }).getPersonDetails({
|
||||||
person_id: creator,
|
person_id: creator,
|
||||||
@@ -11,7 +12,7 @@ export async function load({ fetch, params }) {
|
|||||||
|
|
||||||
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
const messagePromise = client({ func: fetch }).getPrivateMessages({
|
||||||
creator_id: Number(params.user_id),
|
creator_id: Number(params.user_id),
|
||||||
limit: 50,
|
limit: LIMIT,
|
||||||
page: 1,
|
page: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -20,5 +21,6 @@ export async function load({ fetch, params }) {
|
|||||||
return {
|
return {
|
||||||
message: new ReactiveState(message),
|
message: new ReactiveState(message),
|
||||||
creator: new ReactiveState(user),
|
creator: new ReactiveState(user),
|
||||||
|
limit: LIMIT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user