feat: add removal templates
This commit is contained in:
1 parent
147349d0c2
commit
9fd32aa7dd
9 files changed
+97
-10
No files matched your search
@@ -13,6 +13,9 @@
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { Fire, Icon, Trash } from 'svelte-hero-icons'
|
||||
import MultiSelect from '$lib/components/input/MultiSelect.svelte'
|
||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { fullCommunityName } from '$lib/util.js'
|
||||
|
||||
export let open: boolean
|
||||
export let item: PostView | CommentView | undefined = undefined
|
||||
@@ -30,10 +33,20 @@
|
||||
: false
|
||||
|
||||
const getReplyReason = (reason: string) => {
|
||||
return `Your submission in *"${item?.post.name}"* was removed for:\n${reason}`
|
||||
if (!item) return `no template`
|
||||
|
||||
return removalTemplate($userSettings.moderation.removalReasonPreset, {
|
||||
communityLink: `!${fullCommunityName(
|
||||
item!.community.name,
|
||||
item!.community.actor_id
|
||||
)}`,
|
||||
postTitle: item.post.name,
|
||||
reason: reason,
|
||||
username: item.creator.name,
|
||||
})
|
||||
}
|
||||
|
||||
$: replyReason = getReplyReason(reason)
|
||||
$: replyReason = commentReason ? getReplyReason(reason) : ''
|
||||
|
||||
async function remove() {
|
||||
if (!item) return
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type Post from '$lib/components/lemmy/post/Post.svelte'
|
||||
import type {
|
||||
CommentView,
|
||||
Community,
|
||||
@@ -61,7 +62,7 @@ export function remove(item: PostView | CommentView, purge: boolean = false) {
|
||||
removing: {
|
||||
open: true,
|
||||
item: item,
|
||||
purge: purge
|
||||
purge: purge,
|
||||
},
|
||||
}))
|
||||
}
|
||||
@@ -86,3 +87,21 @@ 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
|
||||
}
|
||||
@@ -24,6 +24,8 @@
|
||||
export let previewButton: boolean = false
|
||||
export let disabled: boolean = false
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
@@ -119,7 +121,7 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
||||
>
|
||||
{#if previewing}
|
||||
<div class="px-3 py-2.5 h-32 overflow-auto text-sm">
|
||||
<Markdown source={value} />
|
||||
<Markdown source={beforePreview(value)} />
|
||||
</div>
|
||||
{:else}
|
||||
<!--Toolbar-->
|
||||
|
||||
@@ -163,7 +163,7 @@
|
||||
<Menu
|
||||
let:toggleOpen
|
||||
alignment="bottom-right"
|
||||
itemsClass="h-8 md:h-9"
|
||||
itemsClass="h-8 md:h-8"
|
||||
containerClass="!max-h-[28rem]"
|
||||
>
|
||||
<button
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<aside
|
||||
class="sticky top-16 break-words flex
|
||||
flex-col gap-4 p-6 max-w-full w-80 max-h-[calc(100svh-4rem)]
|
||||
flex-col gap-4 p-6 max-w-full w-96 max-h-[calc(100svh-4rem)]
|
||||
overflow-auto text-sm border-slate-200 dark:border-zinc-800 {$$props.class}"
|
||||
>
|
||||
<slot />
|
||||
|
||||
@@ -32,6 +32,9 @@ interface Settings {
|
||||
}
|
||||
displayNames: boolean
|
||||
nsfwBlur: boolean
|
||||
moderation: {
|
||||
removalReasonPreset: string
|
||||
}
|
||||
}
|
||||
|
||||
export const defaultSettings: Settings = {
|
||||
@@ -63,6 +66,9 @@ export const defaultSettings: Settings = {
|
||||
},
|
||||
displayNames: true,
|
||||
nsfwBlur: true,
|
||||
moderation: {
|
||||
removalReasonPreset: `Your submission in *"{{post.title}}"* was removed for {{reason}}.`,
|
||||
},
|
||||
}
|
||||
|
||||
export const userSettings = writable(defaultSettings)
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<aside class="hidden xl:block">
|
||||
<div class="hidden xl:block">
|
||||
{#await data.streamed.site}
|
||||
<StickyCard>
|
||||
<div class="h-64 grid place-items-center">
|
||||
@@ -79,5 +79,5 @@
|
||||
<h1 class="font-bold text-lg">Failed to load</h1>
|
||||
</StickyCard>
|
||||
{/await}
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
@@ -11,6 +11,9 @@
|
||||
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||
import Link from '$lib/components/input/Link.svelte'
|
||||
import { ArrowLeftCircle, ArrowPath, Icon } from 'svelte-hero-icons'
|
||||
import TextArea from '$lib/components/input/TextArea.svelte'
|
||||
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
|
||||
import { removalTemplate } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
|
||||
let data = {
|
||||
loading: false,
|
||||
@@ -143,4 +146,43 @@
|
||||
</Checkbox>
|
||||
</div>
|
||||
</Setting>
|
||||
|
||||
<SectionTitle class="mt-4">Moderation</SectionTitle>
|
||||
<Setting>
|
||||
<span slot="title">Removal reply preset</span>
|
||||
<span slot="description">
|
||||
<p>The preset to use for "Reply reason" in a submission removal.</p>
|
||||
<ul class="leading-6">
|
||||
<li>Syntax:</li>
|
||||
<li>
|
||||
<code>{'{{reason}}'}</code>
|
||||
: The provided reason
|
||||
</li>
|
||||
<li>
|
||||
<code>{'{{post}}'}</code>
|
||||
: The title of the post
|
||||
</li>
|
||||
<li>
|
||||
<code>{'{{community}}'}</code>
|
||||
: The community the submission was removed in.
|
||||
</li>
|
||||
<li>
|
||||
<code>{'{{username}}'}</code>
|
||||
: The username of the creator of the submission.
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
<MarkdownEditor
|
||||
bind:value={$userSettings.moderation.removalReasonPreset}
|
||||
images={false}
|
||||
previewButton
|
||||
beforePreview={(input) =>
|
||||
removalTemplate(input, {
|
||||
postTitle: '<Example post>',
|
||||
communityLink: '[!community@example.com]()',
|
||||
reason: '<Being a meanie>',
|
||||
username: '@Bob',
|
||||
})}
|
||||
/>
|
||||
</Setting>
|
||||
</div>
|
||||
+7
-2
@@ -40,6 +40,11 @@ pre {
|
||||
}
|
||||
|
||||
:not(pre) > code {
|
||||
@apply bg-slate-200 border border-slate-300 dark:bg-zinc-800
|
||||
dark:border-zinc-700 rounded-md px-1 py-0.5;
|
||||
@apply bg-slate-100 border border-slate-300 dark:bg-zinc-800
|
||||
dark:border-zinc-700;
|
||||
padding-left: 0.25rem;
|
||||
padding-right: 0.25rem;
|
||||
padding-top: 0.125rem;
|
||||
padding-bottom: 0.125rem;
|
||||
border-radius: 3px;
|
||||
}
|
||||
Reference in new issue
Block a user