feat: rewrite report/inbox handling
This commit is contained in:
1 parent
d9ab0db31c
commit
30d5dc9bf2
13 files changed
+468
-429
No files matched your search
@@ -11,9 +11,7 @@
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { isRead } from '$lib/lemmy/inbox.js'
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { fly } from 'svelte/transition'
|
||||
@@ -109,7 +107,7 @@
|
||||
{:else}
|
||||
{#each data.data as item}
|
||||
<div in:fly={{ duration: 500, y: -6, opacity: 0 }}>
|
||||
<InboxItem {item} read={isRead(item)} />
|
||||
<InboxItem {item} />
|
||||
</div>
|
||||
{/each}
|
||||
<Pageination
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getInboxItemPublished } from '$lib/lemmy/inbox.js'
|
||||
import {
|
||||
generalizeCommentReply,
|
||||
generalizePersonMention,
|
||||
generalizePrivateMessage,
|
||||
} from '$lib/lemmy/inbox.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
|
||||
@@ -45,13 +50,13 @@ export async function load({ url, fetch }) {
|
||||
])
|
||||
|
||||
const data = [
|
||||
...replies.replies,
|
||||
...mentions.mentions,
|
||||
...privateMessages.private_messages,
|
||||
...replies.replies.map(generalizeCommentReply),
|
||||
...mentions.mentions.map(generalizePersonMention),
|
||||
...privateMessages.private_messages.map(generalizePrivateMessage),
|
||||
].sort(
|
||||
(a, b) =>
|
||||
Date.parse(getInboxItemPublished(b)) -
|
||||
Date.parse(getInboxItemPublished(a))
|
||||
publishedToDate(b.published).getTime() -
|
||||
publishedToDate(a.published).getTime()
|
||||
)
|
||||
|
||||
return { unreadOnly: unreadOnly, type: type, page: page, data: data }
|
||||
|
||||
@@ -12,26 +12,18 @@
|
||||
} from 'lemmy-js-client'
|
||||
import { ChatBubbleOvalLeft, Check, Icon } from 'svelte-hero-icons'
|
||||
import { page } from '$app/stores'
|
||||
import { Material, toast } from 'mono-svelte'
|
||||
import { Material, Modal, toast } from 'mono-svelte'
|
||||
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import { Button } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import type { InboxItem, InboxItemView } from '$lib/lemmy/inbox.js'
|
||||
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
|
||||
import PrivateMessageModal from '$lib/components/lemmy/modal/PrivateMessageModal.svelte'
|
||||
|
||||
export let item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||
export let read: boolean
|
||||
|
||||
function isPrivateMessage(
|
||||
item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||
): item is PrivateMessageView {
|
||||
return 'private_message' in item
|
||||
}
|
||||
|
||||
const isCommentReply = (
|
||||
item: CommentReplyView | PersonMentionView | PrivateMessageView
|
||||
): item is CommentReplyView => 'comment_reply' in item
|
||||
export let item: InboxItem
|
||||
|
||||
let replying = false
|
||||
let reply = ''
|
||||
@@ -74,132 +66,94 @@
|
||||
|
||||
loading = true
|
||||
|
||||
if ('person_mention' in item) {
|
||||
if (item.type == 'person_mention') {
|
||||
await getClient().markPersonMentionAsRead({
|
||||
auth: $profile?.jwt,
|
||||
person_mention_id: item.person_mention.id,
|
||||
person_mention_id: item.id,
|
||||
read: isRead,
|
||||
})
|
||||
} else if ('comment_reply' in item) {
|
||||
} else if (item.type == 'comment_reply') {
|
||||
await getClient().markCommentReplyAsRead({
|
||||
auth: $profile?.jwt,
|
||||
comment_reply_id: item.comment_reply.id,
|
||||
comment_reply_id: item.id,
|
||||
read: isRead,
|
||||
})
|
||||
}
|
||||
|
||||
read = isRead
|
||||
item.read = isRead
|
||||
if ($profile.user) $profile.user.unreads += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if replying && item.type == 'private_message'}
|
||||
<PrivateMessageModal bind:open={replying} user={item.item.creator} />
|
||||
{/if}
|
||||
|
||||
<Material padding="lg" class="flex flex-col max-w-full gap-2">
|
||||
{#if !isPrivateMessage(item)}
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
{#if isCommentReply(item)}
|
||||
<RelativeDate date={publishedToDate(item.comment_reply.published)} />
|
||||
{:else}
|
||||
<RelativeDate date={publishedToDate(item.person_mention.published)} />
|
||||
{/if}
|
||||
</span>
|
||||
<PostMeta title={item.post.name} id={item.post.id} />
|
||||
</div>
|
||||
<div
|
||||
class="flex flex-col"
|
||||
class:mt-2={$profile?.user &&
|
||||
item.post.creator_id != $profile.user.local_user_view.person.id}
|
||||
>
|
||||
<SectionTitle class="mb-2 text-xs">Reply</SectionTitle>
|
||||
{#if $profile?.user && item.post.creator_id != $profile.user.local_user_view.person.id}
|
||||
<div class="flex flex-row text-xs items-center gap-2">
|
||||
<div
|
||||
class="border-t w-8 rounded-tl h-2 border-l ml-2 border-zinc-700"
|
||||
/>
|
||||
<div>
|
||||
<UserLink
|
||||
avatar
|
||||
avatarSize={16}
|
||||
user={$profile.user.local_user_view.person}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-xs text-slate-600 dark:text-zinc-400">
|
||||
<RelativeDate date={publishedToDate(item.published)} />
|
||||
</span>
|
||||
{#if item.type != 'private_message'}
|
||||
<PostMeta title={item.item.post.name} id={item.item.post.id} />
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-col">
|
||||
<SectionTitle class="mb-2 text-xs">
|
||||
{#if item.type == 'private_message'}
|
||||
Message
|
||||
{:else if item.type == 'person_mention'}
|
||||
Mention
|
||||
{:else if item.type == 'comment_reply'}
|
||||
Reply
|
||||
{/if}
|
||||
</SectionTitle>
|
||||
{#if item.type != 'private_message' && $profile?.user && item.item.post.creator_id != $profile.user.local_user_view.person.id}
|
||||
<div class="flex flex-row text-xs items-center gap-2">
|
||||
<div
|
||||
class="border-t w-8 rounded-tl h-2 border-l ml-2 border-zinc-700"
|
||||
/>
|
||||
<div>
|
||||
<UserLink
|
||||
avatar
|
||||
avatarSize={16}
|
||||
user={$profile.user.local_user_view.person}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{#if item.type == 'private_message'}
|
||||
<PrivateMessage message={item.item} />
|
||||
{:else}
|
||||
<Comment
|
||||
postId={item.post.id}
|
||||
node={{ children: [], comment_view: item, depth: 1 }}
|
||||
postId={item.item.post.id}
|
||||
node={{ children: [], comment_view: item.item, depth: 1 }}
|
||||
replying={false}
|
||||
class="!p-0"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-row ml-auto gap-2">
|
||||
<Button
|
||||
class={read ? '!text-green-500' : ''}
|
||||
size="square-md"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
on:click={() => markAsRead(!read)}
|
||||
>
|
||||
<Icon slot="prefix" src={Check} mini size="16" />
|
||||
</Button>
|
||||
{/if}
|
||||
</div>
|
||||
<div class="flex flex-row ml-auto gap-2 h-8">
|
||||
<Button
|
||||
class={item.read ? '!text-green-500' : ''}
|
||||
size="square-md"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
on:click={() => markAsRead(!item.read)}
|
||||
>
|
||||
<Icon slot="prefix" src={Check} mini size="16" />
|
||||
</Button>
|
||||
|
||||
<Button href="/comment/{item.comment.id}" size="md" class="h-8">
|
||||
{#if item.type == 'private_message'}
|
||||
{#if item.item.creator.id != $profile?.user?.local_user_view.person.id}
|
||||
<Button size="md" on:click={() => (replying = !replying)}>Reply</Button>
|
||||
{/if}
|
||||
{:else}
|
||||
<Button href="/comment/{item.item.comment.id}" size="md" class="h-full">
|
||||
Jump
|
||||
</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-row items-center">
|
||||
<div
|
||||
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
|
||||
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
|
||||
>
|
||||
<span class="font-bold flex items-center">
|
||||
{#if item.creator.id == $profile?.user?.local_user_view.person.id}
|
||||
You
|
||||
{:else}
|
||||
<UserLink avatar user={item.creator} />
|
||||
{/if}
|
||||
</span>
|
||||
<span>messaged</span>
|
||||
<span class="font-bold flex items-center">
|
||||
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
|
||||
You
|
||||
{:else}
|
||||
<UserLink avatar user={item.recipient} />
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="text-sm py-2">
|
||||
<Markdown source={item.private_message.content} />
|
||||
</p>
|
||||
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
|
||||
<div class="flex flex-row gap-2">
|
||||
<Button color="ghost" on:click={() => (replying = !replying)}>
|
||||
<Icon mini src={ChatBubbleOvalLeft} width={16} />
|
||||
Reply
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{#if isPrivateMessage(item)}
|
||||
{#if replying}
|
||||
<div class="mt-2 flex flex-col gap-2">
|
||||
<MarkdownEditor placeholder="Message" bind:value={reply} rows={4} />
|
||||
<div class="ml-auto w-24">
|
||||
<Button
|
||||
disabled={loading}
|
||||
{loading}
|
||||
on:click={() => replyToMessage(item)}
|
||||
color="primary"
|
||||
size="sm"
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</Material>
|
||||
@@ -1,6 +1,11 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import {
|
||||
generalizeCommentReport,
|
||||
generalizePostReport,
|
||||
generalizePrivateMessageReport,
|
||||
} from '$lib/lemmy/report.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
type ReportListType = 'unread' | 'all'
|
||||
@@ -33,18 +38,25 @@ export async function load({ url, fetch }) {
|
||||
unresolved_only: type == 'unread',
|
||||
}
|
||||
|
||||
const [posts, comments] = await Promise.all([
|
||||
const admin = get(profile)?.user ? isAdmin(get(profile)!.user!) : false
|
||||
|
||||
const [posts, comments, messages] = await Promise.all([
|
||||
client.listPostReports({
|
||||
...params,
|
||||
}),
|
||||
client.listCommentReports({
|
||||
...params,
|
||||
}),
|
||||
admin ? client.listPrivateMessageReports({ ...params }) : undefined,
|
||||
])
|
||||
|
||||
const everything = [...posts.post_reports, ...comments.comment_reports].sort(
|
||||
(a, b) => Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
|
||||
)
|
||||
const everything = [
|
||||
...posts.post_reports.map(generalizePostReport),
|
||||
...comments.comment_reports.map(generalizeCommentReport),
|
||||
...(messages?.private_message_reports ?? []).map(
|
||||
generalizePrivateMessageReport
|
||||
),
|
||||
].sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime())
|
||||
|
||||
return {
|
||||
type: type,
|
||||
|
||||
@@ -12,14 +12,10 @@
|
||||
import { Check, Icon } from 'svelte-hero-icons'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import type { ReportView } from '$lib/lemmy/report.js'
|
||||
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
|
||||
|
||||
export let item: PostReportView | CommentReportView | PrivateMessageReportView
|
||||
|
||||
$: resolved = isCommentReport(item)
|
||||
? item.comment_report.resolved
|
||||
: isPostReport(item)
|
||||
? item.post_report.resolved
|
||||
: false
|
||||
export let item: ReportView
|
||||
|
||||
let resolving = false
|
||||
async function resolve() {
|
||||
@@ -27,31 +23,60 @@
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
if (isCommentReport(item)) {
|
||||
await getClient().resolveCommentReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.comment_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
switch (item.type) {
|
||||
case 'comment': {
|
||||
const res = await getClient().resolveCommentReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
|
||||
resolved = !resolved
|
||||
item.resolved = res.comment_report_view.comment_report.resolved
|
||||
|
||||
toast({
|
||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||
type: 'success',
|
||||
})
|
||||
} else if (isPostReport(item)) {
|
||||
await getClient().resolvePostReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.post_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
toast({
|
||||
content: `${
|
||||
item.resolved ? 'Resolved' : 'Unresolved'
|
||||
} that report.`,
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
resolved = !resolved
|
||||
toast({
|
||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||
type: 'success',
|
||||
})
|
||||
break
|
||||
}
|
||||
case 'post': {
|
||||
const res = await getClient().resolvePostReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
|
||||
item.resolved = res.post_report_view.post_report.resolved
|
||||
toast({
|
||||
content: `${
|
||||
item.resolved ? 'Resolved' : 'Unresolved'
|
||||
} that report.`,
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
break
|
||||
}
|
||||
case 'message': {
|
||||
const res = await getClient().resolvePrivateMessageReport({
|
||||
auth: $profile.jwt,
|
||||
report_id: item.id,
|
||||
resolved: !item.resolved,
|
||||
})
|
||||
|
||||
item.resolved =
|
||||
res.private_message_report_view.private_message_report.resolved
|
||||
toast({
|
||||
content: `${
|
||||
item.resolved ? 'Resolved' : 'Unresolved'
|
||||
} that report.`,
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const reports = await getClient().getReportCount({
|
||||
@@ -73,66 +98,39 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if isCommentReport(item)}
|
||||
<CommentItem
|
||||
comment={{
|
||||
...item,
|
||||
subscribed: 'NotSubscribed',
|
||||
creator_blocked: false,
|
||||
saved: false,
|
||||
creator: item.comment_creator,
|
||||
{#if item.type == 'comment'}
|
||||
<CommentItem comment={item.item} />
|
||||
{:else if item.type == 'post'}
|
||||
<Post post={item.item} />
|
||||
{:else if item.type == 'message'}
|
||||
<PrivateMessage
|
||||
message={{
|
||||
creator: item.reportee,
|
||||
private_message: item.item,
|
||||
recipient: item.creator,
|
||||
}}
|
||||
/>
|
||||
<div class="flex flex-row gap-4 items-center">
|
||||
<div>
|
||||
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
|
||||
Reason
|
||||
</span>
|
||||
<p>
|
||||
{item.comment_report.reason}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
on:click={resolve}
|
||||
class="w-8 h-8 !p-1 ml-auto {resolved ? '!text-green-500' : ''}"
|
||||
aria-label="Resolve"
|
||||
title="Resolve"
|
||||
loading={resolving}
|
||||
disabled={resolving}
|
||||
>
|
||||
<Icon src={Check} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{:else if isPostReport(item)}
|
||||
<Post
|
||||
post={{
|
||||
...item,
|
||||
saved: false,
|
||||
subscribed: 'NotSubscribed',
|
||||
unread_comments: 0,
|
||||
read: false,
|
||||
creator_blocked: false,
|
||||
creator: item.post_creator,
|
||||
}}
|
||||
/>
|
||||
<div class="flex flex-row gap-4 items-center">
|
||||
<div>
|
||||
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
|
||||
Reason
|
||||
</span>
|
||||
<p>
|
||||
{item.post_report.reason}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
on:click={resolve}
|
||||
class="w-8 h-8 !p-1 ml-auto {resolved ? '!text-green-500' : ''}"
|
||||
aria-label="Resolve"
|
||||
title="Resolve"
|
||||
loading={resolving}
|
||||
disabled={resolving}
|
||||
>
|
||||
<Icon src={Check} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-row gap-4 items-center">
|
||||
<div>
|
||||
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
|
||||
Reason
|
||||
</span>
|
||||
<p>
|
||||
{item.reason}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
on:click={resolve}
|
||||
class="w-8 h-8 !p-1 ml-auto {item.resolved
|
||||
? '!text-green-600 dark:!text-green-400'
|
||||
: ''}"
|
||||
aria-label="Resolve"
|
||||
title="Resolve"
|
||||
loading={resolving}
|
||||
disabled={resolving}
|
||||
>
|
||||
<Icon src={Check} mini size="16" slot="prefix" />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -35,6 +35,7 @@
|
||||
import { Button, Modal, Select } from 'mono-svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date.js'
|
||||
import PrivateMessageModal from '$lib/components/lemmy/modal/PrivateMessageModal.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -77,37 +78,7 @@
|
||||
blocking = false
|
||||
}
|
||||
|
||||
let loadingMessage = false
|
||||
let messaging = false
|
||||
let message = ''
|
||||
|
||||
async function sendMessage() {
|
||||
if (!$profile?.jwt || message == '') return
|
||||
|
||||
loadingMessage = true
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $profile.jwt,
|
||||
content: message,
|
||||
recipient_id: data.person_view.person.id,
|
||||
})
|
||||
|
||||
toast({
|
||||
content: 'Successfully sent that person a message.',
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
messaging = false
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
loadingMessage = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -115,29 +86,10 @@
|
||||
</svelte:head>
|
||||
|
||||
{#if $profile?.user}
|
||||
<Modal bind:open={messaging}>
|
||||
<h1 class="text-2xl font-bold" slot="title">Message</h1>
|
||||
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
|
||||
<p class="inline-flex flex-row gap-2 items-center">
|
||||
Sending <UserLink avatar user={data.person_view.person} /> a message
|
||||
</p>
|
||||
<MarkdownEditor
|
||||
bind:value={message}
|
||||
label="Message"
|
||||
placeholder="your hair looks nice today"
|
||||
rows={4}
|
||||
/>
|
||||
<Button
|
||||
color="primary"
|
||||
size="lg"
|
||||
submit
|
||||
loading={loadingMessage}
|
||||
disabled={loadingMessage}
|
||||
>
|
||||
Send
|
||||
</Button>
|
||||
</form>
|
||||
</Modal>
|
||||
<PrivateMessageModal
|
||||
bind:user={data.person_view.person}
|
||||
bind:open={messaging}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col-reverse xl:flex-row gap-4 max-w-full w-full">
|
||||
|
||||
Reference in new issue
Block a user