impr: restructure src/lib
This commit is contained in:
376 files changed
+1000
-1033
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import UserLink from '$comp/lemmy/user/UserLink.svelte'
|
||||
import MarkdownEditor from '$lib/app/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import type { Person } from '$lib/api/types'
|
||||
import { Button, Modal } from 'mono-svelte'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person
|
||||
denying: boolean
|
||||
denyReason?: string
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user,
|
||||
denying = $bindable(),
|
||||
denyReason = $bindable(''),
|
||||
}: Props = $props()
|
||||
|
||||
let loading = false
|
||||
|
||||
function deny() {
|
||||
denying = true
|
||||
open = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
{#snippet customTitle()}
|
||||
<h1 class="text-2xl font-bold">
|
||||
{$t('routes.admin.applications.modalTitle')}
|
||||
</h1>
|
||||
{/snippet}
|
||||
<form onsubmit={preventDefault(() => deny())} class="flex flex-col gap-4">
|
||||
<UserLink avatar {user} />
|
||||
<MarkdownEditor
|
||||
bind:value={denyReason}
|
||||
label={$t('routes.admin.applications.reason')}
|
||||
rows={4}
|
||||
/>
|
||||
<Button color="primary" size="lg" submit {loading} disabled={loading}>
|
||||
{$t('routes.admin.applications.deny')}
|
||||
</Button>
|
||||
</form>
|
||||
</Modal>
|
||||
@@ -0,0 +1,133 @@
|
||||
<script lang="ts">
|
||||
import Avatar from '$lib/ui/generic/Avatar.svelte'
|
||||
import type { Community, Person } from '$lib/api/types'
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { Label, toast, Button, Modal, Switch } from 'mono-svelte'
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/app/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import Duration from '$comp/form/Duration.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import CommunityLink from '../community/CommunityLink.svelte'
|
||||
|
||||
interface Props {
|
||||
open?: boolean
|
||||
user: Person | undefined
|
||||
community: Community | undefined
|
||||
banned: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(false),
|
||||
user: item = $bindable(),
|
||||
community,
|
||||
banned,
|
||||
}: Props = $props()
|
||||
|
||||
let reason = $state('')
|
||||
let deleteData = $state(false)
|
||||
let expires = $state(-1)
|
||||
let loading = $state(false)
|
||||
|
||||
// hack due to svelte's reactive declarations
|
||||
const resetReason = () => {
|
||||
reason = ''
|
||||
deleteData = false
|
||||
expires = -1
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (item) resetReason()
|
||||
})
|
||||
|
||||
async function submit() {
|
||||
if (!item || !profile.current?.user || !profile.current?.jwt) return
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
let date: number | undefined
|
||||
|
||||
if (expires > 0) {
|
||||
date = Math.floor(Date.now() / 1000) + expires
|
||||
}
|
||||
|
||||
if (community) {
|
||||
await client().banFromCommunity({
|
||||
ban: !banned,
|
||||
community_id: community.id,
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
remove_data: deleteData,
|
||||
expires: date,
|
||||
})
|
||||
} else {
|
||||
await client().banPerson({
|
||||
ban: !banned,
|
||||
person_id: item.id,
|
||||
reason: reason || undefined,
|
||||
remove_data: deleteData,
|
||||
expires: date,
|
||||
})
|
||||
}
|
||||
|
||||
open = false
|
||||
|
||||
toast({
|
||||
content: banned ? $t('toast.unbannedUser') : $t('toast.bannedUser'),
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
item.banned = !banned
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
bind:open
|
||||
title={banned ? $t('moderation.ban.unbanning') : $t('moderation.ban.banning')}
|
||||
>
|
||||
{#if item}
|
||||
<form
|
||||
class="flex flex-col gap-4"
|
||||
onsubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit()
|
||||
}}
|
||||
>
|
||||
<div class="flex items-center gap-1">
|
||||
<Avatar url={item.avatar} alt={item.name} width={24} />
|
||||
<span class="font-bold">{item.name}</span>
|
||||
</div>
|
||||
{#if community}
|
||||
<CommunityLink {community} avatar />
|
||||
{/if}
|
||||
<MarkdownEditor
|
||||
required
|
||||
bind:value={reason}
|
||||
label={$t('moderation.reason')}
|
||||
/>
|
||||
{#if !banned}
|
||||
<Switch bind:checked={deleteData}>
|
||||
{$t('moderation.ban.deleteData')}
|
||||
{#snippet description()}
|
||||
{$t('moderation.ban.warning')}
|
||||
{/snippet}
|
||||
</Switch>
|
||||
<Label text={$t('moderation.ban.expires')}>
|
||||
<Duration bind:value={expires}></Duration>
|
||||
</Label>
|
||||
{/if}
|
||||
<Button submit color="primary" {loading} disabled={loading} size="lg">
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import ShieldIcon from '$comp/lemmy/moderation/ShieldIcon.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { isCommentView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView } from '$lib/api/types'
|
||||
import { Button, Menu, MenuButton, MenuDivider } from 'mono-svelte'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
Icon,
|
||||
Megaphone,
|
||||
Newspaper,
|
||||
ShieldExclamation,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { amMod, ban, feature, isAdmin, remove, viewVotes } from './moderation'
|
||||
|
||||
interface Props {
|
||||
item: CommentView
|
||||
}
|
||||
|
||||
let { item = $bindable(), ...rest }: Props = $props()
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom" class="top-0 h-[26px] w-[26px] ">
|
||||
{#snippet target(attachment)}
|
||||
<Button
|
||||
{@attach attachment}
|
||||
class="w-[26px] h-[26px] hover:text-green-500! dark:text-zinc-400 text-slate-600"
|
||||
size="square-md"
|
||||
color="tertiary"
|
||||
{...rest}
|
||||
>
|
||||
<ShieldIcon filled width={14} />
|
||||
</Button>
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider showLabel>
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)} icon={Trash}>
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
: $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.current?.user && profile.current.user?.local_user_view.person.id != item.creator.id}
|
||||
<!--Comment made by someone else-->
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
icon={ShieldExclamation}
|
||||
>
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
</MenuButton>
|
||||
{:else}
|
||||
<!--Comment made by self-->
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
onclick={async () => {
|
||||
if (!profile.current.jwt) return
|
||||
item.comment = (
|
||||
await feature(
|
||||
!item.comment.distinguished,
|
||||
item.comment,
|
||||
profile.current.jwt,
|
||||
)
|
||||
).comment_view.comment
|
||||
}}
|
||||
icon={Megaphone}
|
||||
>
|
||||
{item.comment.distinguished
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
<MenuButton color="success-subtle" href="/modlog?comment={item.comment.id}">
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{$t('moderation.modlog.comment')}
|
||||
</MenuButton>
|
||||
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{$t('moderation.modlog.user')}
|
||||
</MenuButton>
|
||||
<MenuButton color="blue-subtle" onclick={() => viewVotes(item)}>
|
||||
<Icon src={ArrowsUpDown} size="16" micro />
|
||||
{$t('moderation.votes')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() => remove(item, true)}
|
||||
icon={Fire}
|
||||
>
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { modals } from '$comp/lemmy/moderation/moderation.js'
|
||||
</script>
|
||||
|
||||
<!--These weird await hacks are for lazy loading, better network performance-->
|
||||
{#if $modals.reporting.open}
|
||||
{#await import('$comp/lemmy/moderation/ReportModal.svelte') then { default: ReportModal }}
|
||||
<ReportModal
|
||||
bind:open={$modals.reporting.open}
|
||||
bind:item={$modals.reporting.item}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
{#if $modals.removing.open}
|
||||
{#await import('$comp/lemmy/moderation/RemoveModal.svelte') then { default: RemoveModal }}
|
||||
<RemoveModal
|
||||
bind:open={$modals.removing.open}
|
||||
item={$modals.removing.item}
|
||||
purge={$modals.removing.purge}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
{#if $modals.banning.open}
|
||||
{#await import('$comp/lemmy/moderation/BanModal.svelte') then { default: BanModal }}
|
||||
<BanModal
|
||||
bind:open={$modals.banning.open}
|
||||
banned={$modals.banning.banned}
|
||||
user={$modals.banning.user}
|
||||
community={$modals.banning.community}
|
||||
/>
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
{#if $modals.votes.open}
|
||||
{#await import('$comp/lemmy/moderation/ViewVotesModal.svelte') then { default: VotesModal }}
|
||||
<VotesModal bind:open={$modals.votes.open} item={$modals.votes.item} />
|
||||
{/await}
|
||||
{/if}
|
||||
@@ -0,0 +1,178 @@
|
||||
<script lang="ts">
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import type { CommentView, PostView } from '$lib/api/types'
|
||||
import { Menu, MenuButton, MenuDivider, toast } from 'mono-svelte'
|
||||
import type { Snippet } from 'svelte'
|
||||
import {
|
||||
ArrowsUpDown,
|
||||
Fire,
|
||||
Icon,
|
||||
LockClosed,
|
||||
LockOpen,
|
||||
Megaphone,
|
||||
Newspaper,
|
||||
ShieldExclamation,
|
||||
Trash,
|
||||
} from 'svelte-hero-icons'
|
||||
import { amMod, ban, isAdmin, remove, viewVotes } from './moderation'
|
||||
import type { Attachment } from 'svelte/attachments'
|
||||
|
||||
interface Props {
|
||||
item: PostView | CommentView
|
||||
target: Snippet<[Attachment, boolean]>
|
||||
}
|
||||
|
||||
let { item = $bindable(), target: passedTarget }: Props = $props()
|
||||
|
||||
let acting = $state(false)
|
||||
|
||||
async function lock(lock: boolean) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().lockPost({
|
||||
locked: lock,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
|
||||
item.post.locked = lock
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
acting = false
|
||||
}
|
||||
|
||||
async function pin(pinned: boolean, toInstance: boolean = false) {
|
||||
if (!profile.current?.jwt || !isPostView(item)) return
|
||||
|
||||
acting = true
|
||||
|
||||
try {
|
||||
await getClient().featurePost({
|
||||
feature_type: toInstance ? 'Local' : 'Community',
|
||||
featured: pinned,
|
||||
post_id: item.post.id,
|
||||
})
|
||||
|
||||
item.post.featured_community = pinned
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
acting = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<Menu placement="bottom-end">
|
||||
{#snippet target(attachment)}
|
||||
{@render passedTarget(attachment, acting)}
|
||||
{/snippet}
|
||||
{#if (profile.current?.user && amMod(profile.current.user, item.community)) || (profile.current?.user && isAdmin(profile.current.user))}
|
||||
<MenuDivider showLabel>
|
||||
{#if !item.community.local && !amMod(profile.current.user, item.community)}
|
||||
{$t('moderation.labelInstanceOnly')}
|
||||
{:else}
|
||||
{$t('moderation.label')}
|
||||
{/if}
|
||||
</MenuDivider>
|
||||
<MenuButton
|
||||
color="warning-subtle"
|
||||
onclick={() => lock(!item.post.locked)}
|
||||
loading={acting}
|
||||
icon={item.post.locked ? LockOpen : LockClosed}
|
||||
>
|
||||
{item.post.locked ? $t('moderation.unlock') : $t('moderation.lock')}
|
||||
</MenuButton>
|
||||
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_community : false)}
|
||||
loading={acting}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" mini />
|
||||
<div
|
||||
class="flex flex-row gap-2 text-left items-center justify-between w-full"
|
||||
>
|
||||
<span>
|
||||
{item.post.featured_community
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
{#if isAdmin(profile.current.user)}
|
||||
<span class="text-xs opacity-80">{$t('form.post.community')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</MenuButton>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item)}>
|
||||
<Icon src={Trash} size="16" mini />
|
||||
{#if isCommentView(item)}
|
||||
{item.comment.removed
|
||||
? $t('moderation.restore')
|
||||
: $t('moderation.remove')}
|
||||
{:else}
|
||||
{item.post.removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</MenuButton>
|
||||
{#if profile.current?.user && profile.current.user.local_user_view.person.id != item.creator.id}
|
||||
<MenuButton
|
||||
color="danger-subtle"
|
||||
onclick={() =>
|
||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
||||
>
|
||||
<Icon src={ShieldExclamation} size="16" mini />
|
||||
{item.creator_banned_from_community
|
||||
? $t('moderation.ban.unbanFromCommunity')
|
||||
: $t('moderation.ban.banFromCommunity')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
<MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{$t('moderation.modlog.user')}
|
||||
</MenuButton>
|
||||
<MenuButton color="success-subtle" href="/modlog?post={item.post.id}">
|
||||
<Icon src={Newspaper} size="16" micro />
|
||||
{$t('moderation.modlog.post')}
|
||||
</MenuButton>
|
||||
<MenuButton color="blue-subtle" onclick={() => viewVotes(item)}>
|
||||
<Icon src={ArrowsUpDown} size="16" micro />
|
||||
{$t('moderation.votes')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
{#if profile.current?.user && isAdmin(profile.current.user)}
|
||||
<MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
|
||||
<MenuButton
|
||||
color="success-subtle"
|
||||
onclick={() =>
|
||||
pin(isPostView(item) ? !item.post.featured_local : false, true)}
|
||||
>
|
||||
<Icon src={Megaphone} size="16" mini />
|
||||
<div
|
||||
class="flex flex-row gap-2 text-left items-center justify-between w-full"
|
||||
>
|
||||
<span>
|
||||
{item.post.featured_local
|
||||
? $t('moderation.unfeature')
|
||||
: $t('moderation.feature')}
|
||||
</span>
|
||||
<span class="text-xs opacity-80">{$t('admin.instance')}</span>
|
||||
</div>
|
||||
</MenuButton>
|
||||
<MenuButton color="danger-subtle" onclick={() => remove(item, true)}>
|
||||
<Icon src={Fire} size="16" mini />
|
||||
{$t('admin.purge')}
|
||||
</MenuButton>
|
||||
{/if}
|
||||
</Menu>
|
||||
@@ -0,0 +1,270 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault, run } from 'svelte/legacy'
|
||||
|
||||
import MultiSelect from '$comp/input/Switch.svelte'
|
||||
import { removalTemplate } from '$comp/lemmy/moderation/moderation.js'
|
||||
import MarkdownEditor from '$lib/app/markdown/MarkdownEditor.svelte'
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import type { CommentView, PostView } from '$lib/api/types'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item.js'
|
||||
import { settings } from '$lib/settings.svelte.js'
|
||||
import { fullCommunityName } from '$lib/util.svelte.js'
|
||||
import { Button, Modal, Select, Switch, toast } from 'mono-svelte'
|
||||
import Option from 'mono-svelte/forms/select/Option.svelte'
|
||||
import { Fire, Trash } from 'svelte-hero-icons'
|
||||
import Comment from '../comment/Comment.svelte'
|
||||
import { Post } from '../post'
|
||||
import { amMod, isAdmin } from './moderation'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | undefined
|
||||
purge?: boolean
|
||||
}
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
item = $bindable(undefined),
|
||||
purge = false,
|
||||
}: Props = $props()
|
||||
|
||||
let reason = $state('')
|
||||
let commentReason: boolean = $state(
|
||||
settings.moderation.defaultRemoveAction != null,
|
||||
)
|
||||
let privateMessage: boolean = $state(
|
||||
settings.moderation.defaultRemoveAction == 'message',
|
||||
)
|
||||
let loading = $state(false)
|
||||
let preset = $state(settings.moderation.presets[0]?.content ?? '')
|
||||
|
||||
$effect(() => {
|
||||
if (!commentReason) settings.moderation.defaultRemoveAction = null
|
||||
else if (privateMessage) settings.moderation.defaultRemoveAction = 'message'
|
||||
else settings.moderation.defaultRemoveAction = 'comment'
|
||||
})
|
||||
|
||||
let removed = $derived(
|
||||
item
|
||||
? isCommentView(item)
|
||||
? item.comment.removed
|
||||
: item.post.removed
|
||||
: false,
|
||||
)
|
||||
|
||||
const getReplyReason = (reason: string, preset: string) => {
|
||||
if (!item) return `no template`
|
||||
|
||||
return removalTemplate(preset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id,
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
username: item.creator.name,
|
||||
})
|
||||
}
|
||||
|
||||
let replyReason = $state('')
|
||||
$effect(() => {
|
||||
replyReason = commentReason ? getReplyReason(reason, preset) : ''
|
||||
})
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
if (!profile.current?.jwt) throw new Error('Unauthenticated')
|
||||
|
||||
loading = true
|
||||
|
||||
try {
|
||||
if (purge) {
|
||||
if (isCommentView(item)) {
|
||||
await getClient(undefined, fetch).purgeComment({
|
||||
comment_id: item.comment.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else {
|
||||
await getClient(undefined, fetch).purgePost({
|
||||
post_id: item.post.id,
|
||||
reason: reason,
|
||||
})
|
||||
}
|
||||
|
||||
toast({
|
||||
content: $t('moderation.removeSubmission.successPurge'),
|
||||
type: 'success',
|
||||
})
|
||||
|
||||
loading = false
|
||||
open = false
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (commentReason) {
|
||||
if (replyReason == '') {
|
||||
toast({
|
||||
content: $t('moderation.removeSubmission.failEmptyReply'),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (privateMessage) {
|
||||
await getClient()
|
||||
.createPrivateMessage({
|
||||
content: replyReason,
|
||||
recipient_id: isCommentView(item)
|
||||
? item.comment.creator_id
|
||||
: item.post.creator_id,
|
||||
})
|
||||
.catch(() => {
|
||||
toast({
|
||||
content: $t('moderation.removeSubmission.failMessage'),
|
||||
type: 'warning',
|
||||
})
|
||||
})
|
||||
} else {
|
||||
await getClient()
|
||||
.createComment({
|
||||
content: replyReason,
|
||||
post_id: item.post.id,
|
||||
parent_id: isCommentView(item) ? item.comment.id : undefined,
|
||||
})
|
||||
.catch(() => {
|
||||
toast({
|
||||
content: $t('moderation.removeSubmission.failReply'),
|
||||
type: 'warning',
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (isCommentView(item)) {
|
||||
await getClient().removeComment({
|
||||
comment_id: item.comment.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
})
|
||||
item.comment.removed = !removed
|
||||
} else if (isPostView(item)) {
|
||||
await getClient().removePost({
|
||||
post_id: item.post.id,
|
||||
removed: !removed,
|
||||
reason: reason || undefined,
|
||||
})
|
||||
|
||||
item.post.removed = !removed
|
||||
}
|
||||
|
||||
open = false
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: errorMessage(err),
|
||||
type: 'error',
|
||||
})
|
||||
}
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
const resetText = () => {
|
||||
reason = ''
|
||||
}
|
||||
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal
|
||||
bind:open
|
||||
title={purge
|
||||
? $t('moderation.removeSubmission.titlePurge')
|
||||
: removed
|
||||
? $t('moderation.removeSubmission.titleRestore')
|
||||
: $t('moderation.removeSubmission.title')}
|
||||
>
|
||||
{#if item}
|
||||
<form
|
||||
onsubmit={preventDefault(remove)}
|
||||
class="flex flex-col gap-4 list-none"
|
||||
>
|
||||
{#if isCommentView(item)}
|
||||
<Comment
|
||||
node={{
|
||||
children: [],
|
||||
comment_view: item,
|
||||
depth: 1,
|
||||
}}
|
||||
postId={item.post.id}
|
||||
actions={false}
|
||||
/>
|
||||
{:else if isPostView(item)}
|
||||
<Post actions={false} post={item} />
|
||||
{/if}
|
||||
|
||||
<MarkdownEditor
|
||||
rows={3}
|
||||
label="Reason"
|
||||
placeholder="Optional"
|
||||
bind:value={reason}
|
||||
/>
|
||||
|
||||
{#if !removed && profile.current?.user && (amMod(profile.current.user, item.community) || (isAdmin(profile.current.user) && item.community.local))}
|
||||
<Switch bind:checked={commentReason}>
|
||||
{$t('moderation.removeSubmission.withReason')}
|
||||
</Switch>
|
||||
|
||||
{#if commentReason}
|
||||
<MultiSelect
|
||||
options={[false, true]}
|
||||
optionNames={[
|
||||
$t('moderation.removeSubmission.comment'),
|
||||
$t('moderation.removeSubmission.message'),
|
||||
]}
|
||||
bind:selected={privateMessage}
|
||||
/>
|
||||
<MarkdownEditor
|
||||
bind:value={replyReason}
|
||||
placeholder={replyReason}
|
||||
rows={3}
|
||||
>
|
||||
{#snippet customLabel()}
|
||||
<div class="flex justify-between items-end mb-1">
|
||||
{$t('comment.reply')}
|
||||
<Select bind:value={preset} placeholder="No preset">
|
||||
{#each settings.moderation.presets as preset}
|
||||
<Option value={preset.content}>
|
||||
{preset.title}
|
||||
</Option>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
{/snippet}
|
||||
</MarkdownEditor>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
color={purge ? 'danger' : 'primary'}
|
||||
size="lg"
|
||||
{loading}
|
||||
disabled={loading}
|
||||
submit
|
||||
icon={purge ? Fire : Trash}
|
||||
>
|
||||
{#if purge}
|
||||
{$t('admin.purge')}
|
||||
{:else}
|
||||
{removed ? $t('moderation.restore') : $t('moderation.remove')}
|
||||
{/if}
|
||||
</Button>
|
||||
</form>
|
||||
{/if}
|
||||
</Modal>
|
||||
@@ -0,0 +1,115 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault, run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/app/auth.svelte.js'
|
||||
import MarkdownEditor from '$lib/app/markdown/MarkdownEditor.svelte'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { getClient } from '$lib/api/client.svelte'
|
||||
import type {
|
||||
CommentView,
|
||||
PostView,
|
||||
PrivateMessageView,
|
||||
} from '$lib/api/types'
|
||||
import { Button, Modal, toast } from 'mono-svelte'
|
||||
import PrivateMessage from '../inbox/PrivateMessage.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Post } from '../post'
|
||||
import Comment from '../comment/Comment.svelte'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | PrivateMessageView | undefined
|
||||
}
|
||||
|
||||
let { open = $bindable(), item = $bindable() }: Props = $props()
|
||||
|
||||
const isComment = (
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is CommentView => 'comment' in item
|
||||
|
||||
const isPost = (
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PostView => !isComment(item) && 'post' in item
|
||||
|
||||
const isPrivateMessage = (
|
||||
item: PostView | CommentView | PrivateMessageView,
|
||||
): item is PrivateMessageView => !isComment(item) && 'private_message' in item
|
||||
|
||||
let loading = $state(false)
|
||||
let reason = $state('')
|
||||
|
||||
async function report() {
|
||||
if (!item || !profile.current?.jwt || reason == '') return
|
||||
loading = true
|
||||
|
||||
try {
|
||||
if (isComment(item)) {
|
||||
await getClient().createCommentReport({
|
||||
comment_id: item.comment.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else if (isPost(item)) {
|
||||
await getClient().createPostReport({
|
||||
post_id: item.post.id,
|
||||
reason: reason,
|
||||
})
|
||||
} else if (isPrivateMessage(item)) {
|
||||
await getClient().createPrivateMessageReport({
|
||||
private_message_id: item.private_message.id,
|
||||
reason: reason,
|
||||
})
|
||||
}
|
||||
open = false
|
||||
toast({
|
||||
content: $t('moderation.reportModal.success'),
|
||||
type: 'success',
|
||||
})
|
||||
} catch (err) {
|
||||
toast({ content: errorMessage(err as string), type: 'error' })
|
||||
}
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
const resetText = () => (reason = '')
|
||||
|
||||
run(() => {
|
||||
if (item) {
|
||||
resetText()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('moderation.reportModal.title')}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(report)}>
|
||||
{#if item}
|
||||
<div class="pointer-events-none list-none">
|
||||
{#if isComment(item)}
|
||||
<Comment
|
||||
actions={false}
|
||||
node={{
|
||||
children: [],
|
||||
comment_view: item,
|
||||
depth: 1,
|
||||
loading: false,
|
||||
}}
|
||||
postId={item.post.id}
|
||||
/>
|
||||
{:else if isPost(item)}
|
||||
<Post actions={false} post={item} />
|
||||
{:else}
|
||||
<PrivateMessage message={item} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
<MarkdownEditor
|
||||
required
|
||||
rows={4}
|
||||
label={$t('moderation.reason')}
|
||||
bind:value={reason}
|
||||
/>
|
||||
<Button submit {loading} disabled={loading} color="primary" size="lg">
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
</Modal>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
width?: number
|
||||
filled?: boolean
|
||||
class?: string
|
||||
}
|
||||
|
||||
let { width = 16, filled = false, class: clazz = '' }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if filled}
|
||||
<svg
|
||||
{width}
|
||||
height={width}
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline {clazz}"
|
||||
>
|
||||
<path
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
{:else}
|
||||
<svg
|
||||
{width}
|
||||
height={width}
|
||||
viewBox="0 0 20 22"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="inline {clazz}"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
d="M10.516 1.17C10.3767 1.03791 10.192 0.964283 10 0.964283C9.80801 0.964283 9.62333 1.03791 9.484 1.17C7.36127 3.18588 4.53412 4.29133 1.607 4.25C1.44753 4.24793 1.29156 4.29674 1.16172 4.38935C1.03189 4.48196 0.934957 4.61355 0.885 4.765C0.462973 6.05116 0.248618 7.39637 0.25 8.75C0.25 14.692 4.314 19.683 9.813 21.098C9.93566 21.1296 10.0643 21.1296 10.187 21.098C15.686 19.683 19.75 14.692 19.75 8.75C19.75 7.36 19.527 6.02 19.115 4.765C19.0652 4.61336 18.9684 4.48156 18.8385 4.38875C18.7087 4.29595 18.5526 4.247 18.393 4.249L18.25 4.25C15.254 4.25 12.533 3.08 10.516 1.17Z"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
/>
|
||||
</svg>
|
||||
{/if}
|
||||
@@ -0,0 +1,130 @@
|
||||
<script lang="ts">
|
||||
import { t } from '$lib/app/i18n'
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { isCommentView, isPostView } from '$lib/lemmy/item'
|
||||
import type { CommentView, PostView, VoteView } from '$lib/api/types'
|
||||
import { Button, Modal, Spinner } from 'mono-svelte'
|
||||
import {
|
||||
ArrowDownCircle,
|
||||
ArrowUpCircle,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
Icon,
|
||||
Newspaper,
|
||||
} from 'svelte-hero-icons'
|
||||
import UserLink from '../user/UserLink.svelte'
|
||||
|
||||
interface Props {
|
||||
open: boolean
|
||||
item?: PostView | CommentView | undefined
|
||||
}
|
||||
|
||||
let { open = $bindable(), item = $bindable() }: Props = $props()
|
||||
|
||||
let page = $state(1)
|
||||
|
||||
async function loadVotes(page: number): Promise<VoteView[]> {
|
||||
if (!item) return []
|
||||
|
||||
if (isPostView(item))
|
||||
return await client()
|
||||
.listPostLikes({ post_id: item.post.id, limit: 50, page: page })
|
||||
.then((i) => i.post_likes)
|
||||
if (isCommentView(item))
|
||||
return await client()
|
||||
.listCommentLikes({
|
||||
comment_id: item.comment.id,
|
||||
limit: 50,
|
||||
page: page,
|
||||
})
|
||||
.then((i) => i.comment_likes)
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
let votes: Promise<VoteView[]> = $derived(loadVotes(page))
|
||||
</script>
|
||||
|
||||
<Modal bind:open title={$t('moderation.votes')}>
|
||||
<div class="flex flex-col gap-1">
|
||||
{#await votes}
|
||||
<div class="self-center justify-self-center h-48 grid place-items-center">
|
||||
<Spinner width={24} />
|
||||
</div>
|
||||
{:then votes}
|
||||
<table class="w-full border-collapse overflow-y-auto table-fixed">
|
||||
<thead>
|
||||
<tr
|
||||
class="border divide-x divide-slate-200 dark:divide-zinc-800 border-slate-200 dark:border-zinc-800 *:px-4 *:py-2"
|
||||
>
|
||||
<th style="width: 6%;"></th>
|
||||
<th style="width: 60%;" class="text-left">
|
||||
{$t('routes.admin.applications.user')}
|
||||
</th>
|
||||
<th style="width: 5%;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-slate-200 dark:divide-zinc-800">
|
||||
{#each votes as vote}
|
||||
<tr>
|
||||
<td class="py-1 px-1 w-full">
|
||||
<Icon
|
||||
src={vote.score == 1 ? ArrowUpCircle : ArrowDownCircle}
|
||||
mini
|
||||
size="20"
|
||||
class={vote.score == 1 ? 'text-blue-400' : 'text-red-400'}
|
||||
aria-label={vote.score == 1
|
||||
? $t('routes.profile.upvoted')
|
||||
: $t('routes.profile.downvoted')}
|
||||
/>
|
||||
</td>
|
||||
<td class="text-sm w-full overflow-hidden">
|
||||
<UserLink
|
||||
user={{
|
||||
...vote.creator,
|
||||
banned: vote.creator_banned_from_community,
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td class="text-sm w-full text-right">
|
||||
<a
|
||||
href="/modlog?user={vote.creator.id}"
|
||||
data-sveltekit-preload-data="tap"
|
||||
class="text-green-400 hover:underline flex flex-row items-center gap-1 font-medium text-xs"
|
||||
aria-label={$t('moderation.modlog.user')}
|
||||
>
|
||||
<Icon src={Newspaper} size="18" micro />
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{#if !(votes.length < 50 && page == 1)}
|
||||
<div class="flex flex-row justify-center items-center gap-2">
|
||||
<Button
|
||||
onclick={() => page--}
|
||||
color="ghost"
|
||||
aria-label={$t('common.back')}
|
||||
rounding="pill"
|
||||
size="square-md"
|
||||
disabled={page == 1}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="20" mini />
|
||||
</Button>
|
||||
{page}
|
||||
<Button
|
||||
onclick={() => page++}
|
||||
color="ghost"
|
||||
aria-label={$t('common.next')}
|
||||
rounding="pill"
|
||||
size="square-md"
|
||||
disabled={votes.length < 50}
|
||||
>
|
||||
<Icon src={ChevronRight} size="20" mini />
|
||||
</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{/await}
|
||||
</div>
|
||||
</Modal>
|
||||
@@ -0,0 +1,133 @@
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import type {
|
||||
Comment,
|
||||
CommentView,
|
||||
Community,
|
||||
MyUserInfo,
|
||||
Person,
|
||||
PostView,
|
||||
PrivateMessageView,
|
||||
} from '$lib/api/types'
|
||||
import type { SubmissionView } from '$lib/lemmy/contentview.js'
|
||||
import { writable } from 'svelte/store'
|
||||
|
||||
interface Modals {
|
||||
reporting: {
|
||||
open: boolean
|
||||
item: PostView | CommentView | PrivateMessageView | undefined
|
||||
}
|
||||
removing: {
|
||||
open: boolean
|
||||
item: SubmissionView | undefined
|
||||
purge: boolean
|
||||
}
|
||||
banning: {
|
||||
open: boolean
|
||||
banned: boolean
|
||||
user: Person | undefined
|
||||
community: Community | undefined
|
||||
}
|
||||
votes: {
|
||||
open: boolean
|
||||
item: PostView | CommentView | undefined
|
||||
}
|
||||
}
|
||||
|
||||
export const modals = writable<Modals>({
|
||||
reporting: {
|
||||
open: false,
|
||||
item: undefined,
|
||||
},
|
||||
removing: {
|
||||
open: false,
|
||||
item: undefined,
|
||||
purge: false,
|
||||
},
|
||||
banning: {
|
||||
open: false,
|
||||
banned: false,
|
||||
user: undefined,
|
||||
community: undefined,
|
||||
},
|
||||
votes: {
|
||||
open: false,
|
||||
item: undefined,
|
||||
},
|
||||
})
|
||||
|
||||
export function report(item: PostView | CommentView | PrivateMessageView) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
reporting: {
|
||||
open: true,
|
||||
item: item,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export function remove(item: SubmissionView, purge: boolean = false) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
removing: {
|
||||
open: true,
|
||||
item: item,
|
||||
purge: purge,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export function ban(banned: boolean, item: Person, community?: Community) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
banning: {
|
||||
open: true,
|
||||
user: item,
|
||||
banned: banned,
|
||||
community,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export async function feature(featured: boolean, item: Comment, jwt: string) {
|
||||
return await client({ auth: jwt }).distinguishComment({
|
||||
comment_id: item.id,
|
||||
distinguished: featured,
|
||||
})
|
||||
}
|
||||
|
||||
export async function viewVotes(item: PostView | CommentView) {
|
||||
modals.update((m) => ({
|
||||
...m,
|
||||
votes: {
|
||||
open: true,
|
||||
item: item,
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
||||
export const amMod = (me: MyUserInfo, community: Community) =>
|
||||
me.moderates.map((c) => c.community.id).includes(community.id) ||
|
||||
(community.local && isAdmin(me))
|
||||
|
||||
export const amModOfAny = (me?: MyUserInfo) =>
|
||||
me && (me.moderates.length > 0 || isAdmin(me))
|
||||
|
||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
||||
|
||||
export const removalTemplate = (
|
||||
input: string,
|
||||
content: {
|
||||
postTitle?: string
|
||||
communityLink?: string
|
||||
username?: string
|
||||
reason?: string
|
||||
},
|
||||
) => {
|
||||
if (content.postTitle) input = input.replaceAll('{{post}}', content.postTitle)
|
||||
if (content.communityLink)
|
||||
input = input.replaceAll('{{community}}', content.communityLink)
|
||||
if (content.username)
|
||||
input = input.replaceAll('{{username}}', content.username)
|
||||
if (content.reason) input = input.replaceAll('{{reason}}', content.reason)
|
||||
return input
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
import { publishedToDate } from '$comp/util/date.js'
|
||||
import type {
|
||||
CommentReportView,
|
||||
CommentView,
|
||||
Person,
|
||||
PostReportView,
|
||||
PostView,
|
||||
PrivateMessage,
|
||||
PrivateMessageReportView,
|
||||
} from '$lib/client/types'
|
||||
|
||||
interface CommentReport {
|
||||
type: 'comment'
|
||||
item: CommentView
|
||||
}
|
||||
|
||||
interface PostReport {
|
||||
type: 'post'
|
||||
item: PostView
|
||||
}
|
||||
|
||||
interface PrivateMessageReport {
|
||||
type: 'message'
|
||||
item: PrivateMessage
|
||||
reportee: Person
|
||||
}
|
||||
|
||||
interface BaseReport {
|
||||
creator: Person
|
||||
reason: string
|
||||
reportee?: Person
|
||||
timestamp: Date
|
||||
resolved: boolean
|
||||
id: number
|
||||
resolver?: Person
|
||||
}
|
||||
|
||||
export const generalizeCommentReport = (
|
||||
report: CommentReportView,
|
||||
): ReportView => ({
|
||||
creator: report.creator,
|
||||
item: {
|
||||
...report,
|
||||
subscribed: 'NotSubscribed',
|
||||
saved: false,
|
||||
creator_blocked: false,
|
||||
creator: report.comment_creator,
|
||||
banned_from_community: false,
|
||||
},
|
||||
reason: report.comment_report.reason,
|
||||
type: 'comment',
|
||||
timestamp: publishedToDate(report.comment_report.published),
|
||||
resolved: report.comment_report.resolved,
|
||||
id: report.comment_report.id,
|
||||
resolver: report.resolver,
|
||||
})
|
||||
|
||||
export const generalizePostReport = (report: PostReportView): ReportView => ({
|
||||
creator: report.creator,
|
||||
item: {
|
||||
...report,
|
||||
unread_comments: 0,
|
||||
saved: false,
|
||||
creator_blocked: false,
|
||||
read: false,
|
||||
subscribed: 'NotSubscribed',
|
||||
creator: report.post_creator,
|
||||
banned_from_community: false,
|
||||
},
|
||||
reason: report.post_report.reason,
|
||||
type: 'post',
|
||||
timestamp: publishedToDate(report.post_report.published),
|
||||
resolved: report.post_report.resolved,
|
||||
id: report.post_report.id,
|
||||
resolver: report.resolver,
|
||||
})
|
||||
|
||||
export const generalizePrivateMessageReport = (
|
||||
report: PrivateMessageReportView,
|
||||
): ReportView => ({
|
||||
creator: report.creator,
|
||||
item: report.private_message,
|
||||
reason: report.private_message_report.reason,
|
||||
type: 'message',
|
||||
reportee: report.private_message_creator,
|
||||
timestamp: publishedToDate(report.private_message_report.published),
|
||||
resolved: report.private_message_report.resolved,
|
||||
id: report.private_message_report.id,
|
||||
resolver: report.resolver,
|
||||
})
|
||||
|
||||
export type Report =
|
||||
| CommentReportView
|
||||
| PostReportView
|
||||
| PrivateMessageReportView
|
||||
|
||||
export type ReportView = BaseReport &
|
||||
(CommentReport | PostReport | PrivateMessageReport)
|
||||
Reference in new issue
Block a user