feat: add post and comment purging, fix #92

This commit is contained in:
Xyphyn committed 2023-08-10 16:48:11 -07:00
1 parent a134ba11b1
commit c5afc07b41
8 files changed
+119 -16

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "0.6.1", "version": "0.6.2",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
@@ -24,7 +24,11 @@
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js' import { isCommentMutable } from '$lib/components/lemmy/post/helpers.js'
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js' import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte' import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte' import CommentModerationMenu from '$lib/components/lemmy/moderation/CommentModerationMenu.svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
@@ -73,7 +77,7 @@
<Icon src={ArrowUturnLeft} width={14} height={14} mini /> <Icon src={ArrowUturnLeft} width={14} height={14} mini />
<span class="text-xs">Reply</span> <span class="text-xs">Reply</span>
</Button> </Button>
{#if $profile?.user && amMod($profile?.user, comment.community)} {#if $profile?.user && (amMod($profile?.user, comment.community) || isAdmin($profile.user))}
<CommentModerationMenu item={comment} /> <CommentModerationMenu item={comment} />
{/if} {/if}
<Menu <Menu
@@ -6,11 +6,11 @@
CommunityView, CommunityView,
PostView, PostView,
} from 'lemmy-js-client' } 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 Menu from '$lib/components/ui/menu/Menu.svelte'
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.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 { Color } from '$lib/ui/colors.js'
import { isComment } from '$lib/lemmy/item.js' import { isComment } from '$lib/lemmy/item.js'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
@@ -20,7 +20,7 @@
<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 <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" size="sm"
on:click={toggleOpen} on:click={toggleOpen}
slot="button" slot="button"
@@ -43,9 +43,10 @@
/> />
</svg> </svg>
</Button> </Button>
<span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400"> {#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 Moderation
</span> </li>
<MenuButton color="success" on:click={() => remove(item)}> <MenuButton color="success" on:click={() => remove(item)}>
<Icon src={Trash} size="16" mini /> <Icon src={Trash} size="16" mini />
{#if isComment(item)} {#if isComment(item)}
@@ -69,4 +70,15 @@
: 'Ban from community'} : 'Ban from community'}
</MenuButton> </MenuButton>
{/if} {/if}
{/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> </Menu>
@@ -17,6 +17,7 @@
<RemoveModal <RemoveModal
bind:open={$modals.removing.open} bind:open={$modals.removing.open}
item={$modals.removing.item} item={$modals.removing.item}
purge={$modals.removing.purge}
/> />
{/await} {/await}
{/if} {/if}
@@ -1,11 +1,12 @@
<script lang="ts"> <script lang="ts">
import { getClient } from '$lib/lemmy' import { getClient } from '$lib/lemmy'
import type { CommentView, Community, PostView } from 'lemmy-js-client' 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 Menu from '$lib/components/ui/menu/Menu.svelte'
import Button from '$lib/components/input/Button.svelte' import Button from '$lib/components/input/Button.svelte'
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte' import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { import {
Fire,
Icon, Icon,
InformationCircle, InformationCircle,
LockClosed, LockClosed,
@@ -111,6 +112,7 @@
/> />
</svg> </svg>
</Button> </Button>
{#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"> <span class="px-4 py-1 my-1 text-xs text-slate-600 dark:text-zinc-400">
Moderation Moderation
</span> </span>
@@ -160,4 +162,14 @@
: 'Ban from community'} : 'Ban from community'}
</MenuButton> </MenuButton>
{/if} {/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> </Menu>
@@ -11,12 +11,16 @@
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import Checkbox from '$lib/components/input/Checkbox.svelte' import Checkbox from '$lib/components/input/Checkbox.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.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 open: boolean
export let item: PostView | CommentView | undefined = undefined export let item: PostView | CommentView | undefined = undefined
export let purge: boolean = false
let reason = '' let reason = ''
let commentReason: boolean = false let commentReason: boolean = false
let privateMessage: boolean = false
let loading = false let loading = false
$: removed = item $: removed = item
@@ -25,7 +29,9 @@
: item.post.removed : item.post.removed
: false : 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() { async function remove() {
if (!item) return if (!item) return
@@ -34,6 +40,32 @@
loading = true loading = true
try { 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 (commentReason) {
if (replyReason == '') { if (replyReason == '') {
toast({ toast({
@@ -42,6 +74,22 @@
return return
} }
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() await getClient()
.createComment({ .createComment({
auth: $profile.jwt, auth: $profile.jwt,
@@ -56,6 +104,7 @@
}) })
}) })
} }
}
if (isComment(item)) { if (isComment(item)) {
await getClient().removeComment({ await getClient().removeComment({
@@ -108,7 +157,9 @@
</script> </script>
<Modal bind:open> <Modal bind:open>
<span slot="title">{removed ? 'Restoring' : 'Removing'} submission</span> <span slot="title">
{purge ? 'Purging' : removed ? 'Restoring' : 'Removing'} submission
</span>
{#if item} {#if item}
<form <form
on:submit|preventDefault={remove} on:submit|preventDefault={remove}
@@ -135,10 +186,15 @@
bind:value={reason} bind:value={reason}
/> />
{#if !removed} {#if !removed && !purge}
<Checkbox bind:checked={commentReason}>Reply with reason</Checkbox> <Checkbox bind:checked={commentReason}>Reply with reason</Checkbox>
{#if commentReason} {#if commentReason}
<MultiSelect
options={[false, true]}
optionNames={['Comment', 'Message']}
bind:selected={privateMessage}
/>
<MarkdownEditor <MarkdownEditor
bind:value={replyReason} bind:value={replyReason}
placeholder={replyReason} placeholder={replyReason}
@@ -148,8 +204,19 @@
{/if} {/if}
{/if} {/if}
<Button color="primary" size="lg" {loading} disabled={loading} submit> <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'} {removed ? 'Restore' : 'Remove'}
{/if}
</Button> </Button>
</form> </form>
{/if} {/if}
@@ -17,6 +17,7 @@ interface Modals {
removing: { removing: {
open: boolean open: boolean
item: PostView | CommentView | undefined item: PostView | CommentView | undefined
purge: boolean
} }
banning: { banning: {
open: boolean open: boolean
@@ -34,6 +35,7 @@ export let modals = writable<Modals>({
removing: { removing: {
open: false, open: false,
item: undefined, item: undefined,
purge: false,
}, },
banning: { banning: {
open: false, 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) => ({ modals.update((m) => ({
...m, ...m,
removing: { removing: {
open: true, open: true,
item: item, item: item,
purge: purge
}, },
})) }))
} }
@@ -24,7 +24,11 @@
import { createEventDispatcher } from 'svelte' import { createEventDispatcher } from 'svelte'
import Modal from '$lib/components/ui/modal/Modal.svelte' import Modal from '$lib/components/ui/modal/Modal.svelte'
import PostForm from '$lib/components/lemmy/post/PostForm.svelte' import PostForm from '$lib/components/lemmy/post/PostForm.svelte'
import { amMod, report } from '$lib/components/lemmy/moderation/moderation.js' import {
amMod,
isAdmin,
report,
} from '$lib/components/lemmy/moderation/moderation.js'
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte' import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
@@ -114,7 +118,7 @@
<FormattedNumber number={post.counts.comments} /> <FormattedNumber number={post.counts.comments} />
</Button> </Button>
<div class="ml-auto" /> <div class="ml-auto" />
{#if $profile?.user && amMod($profile.user, post.community)} {#if $profile?.user && (amMod($profile.user, post.community) || isAdmin($profile.user))}
<ModerationMenu item={post} community={post.community} /> <ModerationMenu item={post} community={post.community} />
{/if} {/if}
<Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen> <Menu alignment="bottom-right" class="overflow-auto" let:toggleOpen>