feat: add post and comment purging, fix #92
This commit is contained in:
1 parent
a134ba11b1
commit
c5afc07b41
8 files changed
+197
-94
No files matched your search
@@ -6,11 +6,11 @@
|
||||
CommunityView,
|
||||
PostView,
|
||||
} from 'lemmy-js-client'
|
||||
import { amMod, ban, remove } from './moderation'
|
||||
import { amMod, ban, isAdmin, remove } from './moderation'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import { Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
|
||||
import { Fire, Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
|
||||
import { Color } from '$lib/ui/colors.js'
|
||||
import { isComment } from '$lib/lemmy/item.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
@@ -18,9 +18,9 @@
|
||||
export let item: PostView | CommentView
|
||||
</script>
|
||||
|
||||
<Menu let:toggleOpen alignment="bottom-center" class="top-0 h-[26px] w-[26px]">
|
||||
<Menu let:toggleOpen alignment="bottom-center" class="top-0 h-[26px] w-[26px] ">
|
||||
<Button
|
||||
class="!p-1 hover:text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
class="!p-1 hover:!text-green-500 dark:text-zinc-400 text-slate-600"
|
||||
size="sm"
|
||||
on:click={toggleOpen}
|
||||
slot="button"
|
||||
@@ -43,30 +43,42 @@
|
||||
/>
|
||||
</svg>
|
||||
</Button>
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Moderation
|
||||
</span>
|
||||
<MenuButton color="success" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user) && item.community.local)}
|
||||
<li class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Moderation
|
||||
</li>
|
||||
<MenuButton color="success" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
User
|
||||
</span>
|
||||
<MenuButton
|
||||
color="dangerSecondary"
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{item.creator_banned_from_community
|
||||
? 'Unban from community'
|
||||
: 'Ban from community'}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
User
|
||||
</span>
|
||||
<MenuButton
|
||||
color="dangerSecondary"
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{item.creator_banned_from_community
|
||||
? 'Unban from community'
|
||||
: 'Ban from community'}
|
||||
{/if}
|
||||
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<li class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Admin
|
||||
</li>
|
||||
<MenuButton color="dangerSecondary" on:click={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini slot="icon" />
|
||||
Purge
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
@@ -17,6 +17,7 @@
|
||||
<RemoveModal
|
||||
bind:open={$modals.removing.open}
|
||||
item={$modals.removing.item}
|
||||
purge={$modals.removing.purge}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { getClient } from '$lib/lemmy'
|
||||
import type { CommentView, Community, PostView } from 'lemmy-js-client'
|
||||
import { amMod, ban, remove } from './moderation'
|
||||
import { amMod, ban, isAdmin, remove } from './moderation'
|
||||
import Menu from '$lib/components/ui/menu/Menu.svelte'
|
||||
import Button from '$lib/components/input/Button.svelte'
|
||||
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||
import {
|
||||
Fire,
|
||||
Icon,
|
||||
InformationCircle,
|
||||
LockClosed,
|
||||
@@ -111,53 +112,64 @@
|
||||
/>
|
||||
</svg>
|
||||
</Button>
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Moderation
|
||||
</span>
|
||||
<MenuButton
|
||||
color="warning"
|
||||
on:click={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="icon"
|
||||
/>
|
||||
{item.post.locked ? 'Unlock' : 'Lock'}
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
color="success"
|
||||
on:click={() => pin(isPost(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
>
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{item.post.featured_community ? 'Unpin' : 'Pin'}
|
||||
</MenuButton>
|
||||
<MenuButton color="dangerSecondary" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
|
||||
{#if ($profile?.user && amMod($profile.user, item.community)) || ($profile?.user && isAdmin($profile.user) && item.community.local)}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
User
|
||||
Moderation
|
||||
</span>
|
||||
<MenuButton
|
||||
color="dangerSecondary"
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
color="warning"
|
||||
on:click={() => lock(!item.post.locked)}
|
||||
loading={locking}
|
||||
disabled={locking}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{item.creator_banned_from_community
|
||||
? 'Unban from community'
|
||||
: 'Ban from community'}
|
||||
<Icon
|
||||
src={item.post.locked ? LockOpen : LockClosed}
|
||||
size="16"
|
||||
mini
|
||||
slot="icon"
|
||||
/>
|
||||
{item.post.locked ? 'Unlock' : 'Lock'}
|
||||
</MenuButton>
|
||||
<MenuButton
|
||||
color="success"
|
||||
on:click={() => pin(isPost(item) ? !item.post.featured_community : false)}
|
||||
loading={pinning}
|
||||
disabled={pinning}
|
||||
>
|
||||
<Icon src={InformationCircle} size="16" mini />
|
||||
{item.post.featured_community ? 'Unpin' : 'Pin'}
|
||||
</MenuButton>
|
||||
<MenuButton color="dangerSecondary" on:click={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isComment(item)}
|
||||
{item.comment.removed ? 'Restore' : 'Remove'}
|
||||
{:else}
|
||||
{item.post.removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if $profile?.user && $profile.user.local_user_view.person.id != item.creator.id}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
User
|
||||
</span>
|
||||
<MenuButton
|
||||
color="dangerSecondary"
|
||||
on:click={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{item.creator_banned_from_community
|
||||
? 'Unban from community'
|
||||
: 'Ban from community'}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if $profile?.user && isAdmin($profile.user)}
|
||||
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
|
||||
Admin
|
||||
</span>
|
||||
<MenuButton color="dangerSecondary" on:click={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini />
|
||||
Purge
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
@@ -11,12 +11,16 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
export let purge: boolean = false
|
||||
|
||||
let reason = ''
|
||||
let commentReason: boolean = false
|
||||
let privateMessage: boolean = false
|
||||
let loading = false
|
||||
|
||||
$: removed = item
|
||||
@@ -25,7 +29,9 @@
|
||||
: item.post.removed
|
||||
: false
|
||||
|
||||
$: replyReason = `Your submission was removed for:\n${reason}`
|
||||
$: replyReason = `Your submission${
|
||||
privateMessage ? `in ${item?.post.name}` : ' '
|
||||
}was removed for:\n${reason}`
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
@@ -34,6 +40,32 @@
|
||||
loading = true
|
||||
|
||||
try {
|
||||
if (purge) {
|
||||
if (isComment(item)) {
|
||||
await getClient(undefined, fetch).purgeComment({
|
||||
auth: $profile.jwt,
|
||||
comment_id: item.comment.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else {
|
||||
await getClient(undefined, fetch).purgePost({
|
||||
auth: $profile.jwt,
|
||||
post_id: item.post.id,
|
||||
reason: reason,
|
||||
})
|
||||
}
|
||||
|
||||
toast({
|
||||
content: 'Successfully purged that submission.',
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
loading = false
|
||||
open = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (commentReason) {
|
||||
if (replyReason == '') {
|
||||
toast({
|
||||
@@ -42,19 +74,36 @@
|
||||
return
|
||||
}
|
||||
|
||||
await getClient()
|
||||
.createComment({
|
||||
auth: $profile.jwt,
|
||||
content: replyReason,
|
||||
post_id: item.post.id,
|
||||
parent_id: isComment(item) ? item.comment.id : undefined,
|
||||
})
|
||||
.catch(() => {
|
||||
toast({
|
||||
content: 'Failed to post reply. Removing anyway...',
|
||||
type: 'warning',
|
||||
if (privateMessage) {
|
||||
await getClient()
|
||||
.createPrivateMessage({
|
||||
auth: $profile.jwt,
|
||||
content: replyReason,
|
||||
recipient_id: isComment(item)
|
||||
? item.comment.creator_id
|
||||
: item.post.creator_id,
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
toast({
|
||||
content: 'Failed to message user. Removing anyway...',
|
||||
type: 'warning',
|
||||
})
|
||||
})
|
||||
} else {
|
||||
await getClient()
|
||||
.createComment({
|
||||
auth: $profile.jwt,
|
||||
content: replyReason,
|
||||
post_id: item.post.id,
|
||||
parent_id: isComment(item) ? item.comment.id : undefined,
|
||||
})
|
||||
.catch(() => {
|
||||
toast({
|
||||
content: 'Failed to post reply. Removing anyway...',
|
||||
type: 'warning',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (isComment(item)) {
|
||||
@@ -108,7 +157,9 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<span slot="title">{removed ? 'Restoring' : 'Removing'} submission</span>
|
||||
<span slot="title">
|
||||
{purge ? 'Purging' : removed ? 'Restoring' : 'Removing'} submission
|
||||
</span>
|
||||
{#if item}
|
||||
<form
|
||||
on:submit|preventDefault={remove}
|
||||
@@ -135,10 +186,15 @@
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed}
|
||||
{#if !removed && !purge}
|
||||
<Checkbox bind:checked={commentReason}>Reply with reason</Checkbox>
|
||||
|
||||
{#if commentReason}
|
||||
<MultiSelect
|
||||
options={[false, true]}
|
||||
optionNames={['Comment', 'Message']}
|
||||
bind:selected={privateMessage}
|
||||
/>
|
||||
<MarkdownEditor
|
||||
bind:value={replyReason}
|
||||
placeholder={replyReason}
|
||||
@@ -148,8 +204,19 @@
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<Button color="primary" size="lg" {loading} disabled={loading} submit>
|
||||
{removed ? 'Restore' : 'Remove'}
|
||||
<Button
|
||||
color={purge ? 'danger' : 'primary'}
|
||||
size="lg"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
submit
|
||||
>
|
||||
<Icon src={purge ? Fire : Trash} mini size="16" slot="icon" />
|
||||
{#if purge}
|
||||
Purge
|
||||
{:else}
|
||||
{removed ? 'Restore' : 'Remove'}
|
||||
{/if}
|
||||
</Button>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
@@ -17,6 +17,7 @@ interface Modals {
|
||||
removing: {
|
||||
open: boolean
|
||||
item: PostView | CommentView | undefined
|
||||
purge: boolean
|
||||
}
|
||||
banning: {
|
||||
open: boolean
|
||||
@@ -34,6 +35,7 @@ export let modals = writable<Modals>({
|
||||
removing: {
|
||||
open: false,
|
||||
item: undefined,
|
||||
purge: false,
|
||||
},
|
||||
banning: {
|
||||
open: false,
|
||||
@@ -53,12 +55,13 @@ export function report(item: PostView | CommentView) {
|
||||
}))
|
||||
}
|
||||
|
||||
export function remove(item: PostView | CommentView) {
|
||||
export function remove(item: PostView | CommentView, purge: boolean = false) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
removing: {
|
||||
open: true,
|
||||
item: item,
|
||||
purge: purge
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user