feat: add removal templates

This commit is contained in:
Xyphyn committed 2023-08-12 19:07:42 -07:00
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
}