feat: add moderation tools (#33)
* feat: Add post submission removal * feat: add comment submission removal * feat: add report viewing and resolving * misc: add notification dot * misc: add locked thread badge * feat: add thread locking * feat: add initiating message conversations * feat: add post pinning/unpinning * misc: bump version * fix: tweak lock colors * fix: update post data on pin * fix: return if reason is empty
This commit is contained in:
1 parent
53ef843cde
commit
d3aae647a8
29 files changed
+835
-67
No files matched your search
@@ -72,7 +72,14 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#each data.posts.posts as post, index (post.post.id)}
|
||||
<div in:fly={{ y: -8, opacity: 0, delay: index < 4 ? index * 100 : 0 }}>
|
||||
<div
|
||||
in:fly={{
|
||||
y: -8,
|
||||
duration: 500,
|
||||
opacity: 0,
|
||||
delay: index < 4 ? index * 100 : 0,
|
||||
}}
|
||||
>
|
||||
<Post {post} />
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<script lang="ts">
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import { fly } from 'svelte/transition'
|
||||
import Report from './Report.svelte'
|
||||
|
||||
export let data
|
||||
</script>
|
||||
|
||||
{#if data.items}
|
||||
<div class="flex flex-col gap-4">
|
||||
{#each data.items as item}
|
||||
<div in:fly={{ y: -6, opacity: 0, duration: 500 }}>
|
||||
<Card
|
||||
class="p-4 flex flex-col gap-4 text-sm !bg-slate-100 dark:!bg-zinc-950"
|
||||
>
|
||||
<div class="flex flex-col gap-1.5">
|
||||
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
|
||||
Report from
|
||||
</span>
|
||||
<span class="font-bold">
|
||||
<UserLink avatar user={item.creator} />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<Report {item} />
|
||||
</Card>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ url }) {
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const jwt = get(authData)?.token
|
||||
|
||||
if (!jwt) return { page: page }
|
||||
|
||||
// can they like
|
||||
// make a sane, consistent, and simple API for once
|
||||
// 3 separate requests? really?
|
||||
// and this time instead of get() it's list(). Why?!
|
||||
// the interfaces don't even extend each other
|
||||
// meaning I have to make a separate function to get dates
|
||||
// for EACH FREAKING ITEM KAJSHDAWLD auwdi awiody
|
||||
|
||||
const client = getClient()
|
||||
|
||||
const params = {
|
||||
auth: jwt,
|
||||
limit: 20,
|
||||
page: page,
|
||||
}
|
||||
|
||||
const [posts, comments, messages] = await Promise.all([
|
||||
client.listPostReports({
|
||||
...params,
|
||||
}),
|
||||
client.listCommentReports({
|
||||
...params,
|
||||
}),
|
||||
client.listPrivateMessageReports({
|
||||
...params,
|
||||
}),
|
||||
])
|
||||
|
||||
const everything = [
|
||||
...posts.post_reports,
|
||||
...comments.comment_reports,
|
||||
...messages.private_message_reports,
|
||||
].sort(
|
||||
(a, b) => Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
|
||||
)
|
||||
|
||||
return {
|
||||
page: page,
|
||||
items: everything,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { isCommentReport, isPostReport } from '$lib/lemmy/item.js'
|
||||
import type {
|
||||
CommentReportView,
|
||||
PostReportView,
|
||||
PrivateMessageReportView,
|
||||
} from 'lemmy-js-client'
|
||||
import { Check, Icon } from 'svelte-hero-icons'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export let item: PostReportView | CommentReportView | PrivateMessageReportView
|
||||
|
||||
$: resolved = isCommentReport(item)
|
||||
? item.comment_report.resolved
|
||||
: isPostReport(item)
|
||||
? item.post_report.resolved
|
||||
: false
|
||||
|
||||
let resolving = false
|
||||
async function resolve() {
|
||||
if (!$authData || !$user) return
|
||||
resolving = true
|
||||
|
||||
try {
|
||||
if (isCommentReport(item)) {
|
||||
await getClient().resolveCommentReport({
|
||||
auth: $authData.token,
|
||||
report_id: item.comment_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
|
||||
resolved = !resolved
|
||||
|
||||
toast({
|
||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||
type: ToastType.success,
|
||||
})
|
||||
} else if (isPostReport(item)) {
|
||||
await getClient().resolvePostReport({
|
||||
auth: $authData.token,
|
||||
report_id: item.post_report.id,
|
||||
resolved: !resolved,
|
||||
})
|
||||
|
||||
resolved = !resolved
|
||||
toast({
|
||||
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
|
||||
type: ToastType.success,
|
||||
})
|
||||
}
|
||||
|
||||
const reports = await getClient().getReportCount({
|
||||
auth: get(authData)!.token,
|
||||
})
|
||||
|
||||
$user.reports =
|
||||
reports.comment_reports +
|
||||
reports.post_reports +
|
||||
(reports.private_message_reports ?? 0)
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
|
||||
resolving = false
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if isCommentReport(item)}
|
||||
<CommentItem
|
||||
comment={{
|
||||
...item,
|
||||
subscribed: 'NotSubscribed',
|
||||
creator_blocked: false,
|
||||
saved: false,
|
||||
}}
|
||||
/>
|
||||
<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="icon" />
|
||||
</Button>
|
||||
</div>
|
||||
{:else if isPostReport(item)}
|
||||
<Post
|
||||
post={{
|
||||
...item,
|
||||
saved: false,
|
||||
subscribed: 'NotSubscribed',
|
||||
unread_comments: 0,
|
||||
read: false,
|
||||
creator_blocked: false,
|
||||
}}
|
||||
/>
|
||||
<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="icon" />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -103,6 +103,8 @@
|
||||
upvotes={postData.counts.upvotes}
|
||||
downvotes={postData.counts.downvotes}
|
||||
deleted={postData.post.deleted}
|
||||
removed={postData.post.removed}
|
||||
locked={postData.post.locked}
|
||||
featured={postData.post.featured_community || postData.post.featured_local}
|
||||
nsfw={postData.post.nsfw}
|
||||
published={new Date(postData.post.published)}
|
||||
@@ -182,6 +184,7 @@
|
||||
comment.detail.comment_view,
|
||||
...comments.comments,
|
||||
])}
|
||||
locked={postData.post.locked}
|
||||
/>
|
||||
{/if}
|
||||
{#await buildCommentsTreeAsync(comments.comments, false)}
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
<script lang="ts">
|
||||
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||
import Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||
import Card from '$lib/components/ui/Card.svelte'
|
||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import type {
|
||||
CommentView,
|
||||
GetPersonDetailsResponse,
|
||||
PostView,
|
||||
} from 'lemmy-js-client'
|
||||
import {
|
||||
Calendar,
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
Envelope,
|
||||
Icon,
|
||||
NoSymbol,
|
||||
PencilSquare,
|
||||
@@ -25,11 +18,14 @@
|
||||
import Pageination from '$lib/components/ui/Pageination.svelte'
|
||||
import { page } from '$app/stores'
|
||||
import { goto } from '$app/navigation'
|
||||
import { isComment } from '$lib/components/lemmy/post/helpers.js'
|
||||
import { isComment } from '$lib/lemmy/item.js'
|
||||
import { authData, getClient, user } from '$lib/lemmy.js'
|
||||
import { isBlocked } from '$lib/lemmy/user.js'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js'
|
||||
import Modal from '$lib/components/ui/modal/Modal.svelte'
|
||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -69,12 +65,70 @@
|
||||
}
|
||||
blocking = false
|
||||
}
|
||||
|
||||
let loadingMessage = false
|
||||
let messaging = false
|
||||
let message = ''
|
||||
|
||||
async function sendMessage() {
|
||||
if (!$authData || message == '') return
|
||||
|
||||
loadingMessage = true
|
||||
|
||||
try {
|
||||
await getClient().createPrivateMessage({
|
||||
auth: $authData.token,
|
||||
content: message,
|
||||
recipient_id: data.person_view.person.id,
|
||||
})
|
||||
|
||||
toast({
|
||||
content: 'Successfully sent that person a message.',
|
||||
type: ToastType.success,
|
||||
})
|
||||
|
||||
messaging = false
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
type: ToastType.error,
|
||||
})
|
||||
}
|
||||
|
||||
loadingMessage = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>{data.person_view.person.name}</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if $authData}
|
||||
<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>
|
||||
<TextArea
|
||||
bind:value={message}
|
||||
label="Message"
|
||||
placeholder="your hair looks nice today"
|
||||
rows={3}
|
||||
/>
|
||||
<Button
|
||||
color="primary"
|
||||
size="lg"
|
||||
submit
|
||||
loading={loadingMessage}
|
||||
disabled={loadingMessage}
|
||||
>
|
||||
Send
|
||||
</Button>
|
||||
</form>
|
||||
</Modal>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col-reverse lg:flex-row gap-4 max-w-full w-full">
|
||||
<div class="flex flex-col gap-4 max-w-full w-full">
|
||||
<div class="flex flex-row gap-4 flex-wrap">
|
||||
@@ -144,6 +198,14 @@
|
||||
</div>
|
||||
{#if $user && $authData && data.person_view.person.id != $user.local_user_view.person.id}
|
||||
<div class="flex flex-col gap-2">
|
||||
<Button
|
||||
size="lg"
|
||||
color="secondary"
|
||||
on:click={() => (messaging = true)}
|
||||
>
|
||||
<Icon slot="icon" solid size="16" src={Envelope} />
|
||||
Message
|
||||
</Button>
|
||||
<Button
|
||||
size="lg"
|
||||
color="danger"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { isComment } from '$lib/components/lemmy/post/helpers.js'
|
||||
import { authData, getClient } from '$lib/lemmy.js'
|
||||
import { getItemPublished } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView, SortType } from 'lemmy-js-client'
|
||||
import type { SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ params, url }) {
|
||||
|
||||
Reference in new issue
Block a user