feat: add basic moderation actions
This commit is contained in:
1 parent
5cfc98188c
commit
281ef04c43
4 files changed
+161
No files matched your search
@@ -0,0 +1,16 @@
|
|||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import { redirect } from '@sveltejs/kit'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
export async function load({ params, fetch }) {
|
||||||
|
const comment = await getClient(undefined, fetch).getComment({
|
||||||
|
id: Number(params.id),
|
||||||
|
auth: get(profile)?.jwt,
|
||||||
|
})
|
||||||
|
|
||||||
|
throw redirect(
|
||||||
|
300,
|
||||||
|
`/post/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}`
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import ModlogItem from './ModlogItem.svelte'
|
||||||
|
|
||||||
|
export let data
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<h1 class="font-bold text-2xl">Modlog</h1>
|
||||||
|
{#if data.modlog}
|
||||||
|
<ul class="flex flex-col gap-4">
|
||||||
|
{#each data.modlog as modlog}
|
||||||
|
<ModlogItem item={modlog} />
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import type {
|
||||||
|
Community,
|
||||||
|
ModBanFromCommunityView,
|
||||||
|
ModRemoveCommentView,
|
||||||
|
ModRemovePostView,
|
||||||
|
Person,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
|
type ModAction =
|
||||||
|
| ModBanFromCommunityView
|
||||||
|
| ModRemoveCommentView
|
||||||
|
| ModRemovePostView
|
||||||
|
|
||||||
|
export interface ModLog {
|
||||||
|
reason?: string
|
||||||
|
moderatee?: Person
|
||||||
|
content?: string
|
||||||
|
moderator?: Person
|
||||||
|
community?: Community
|
||||||
|
actionName: string
|
||||||
|
timestamp: number
|
||||||
|
link?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullUserName = (user: Person) =>
|
||||||
|
`${user.name}@${new URL(user.actor_id).hostname}`
|
||||||
|
|
||||||
|
export const _toModLog = (item: ModAction): ModLog => {
|
||||||
|
if ('mod_ban_from_community' in item) {
|
||||||
|
return {
|
||||||
|
moderator: item.moderator,
|
||||||
|
moderatee: item.banned_person,
|
||||||
|
community: item.community,
|
||||||
|
actionName: 'Ban',
|
||||||
|
reason: item.mod_ban_from_community.reason,
|
||||||
|
timestamp: Date.parse(`${item.mod_ban_from_community.when_}Z`),
|
||||||
|
}
|
||||||
|
} else if ('mod_remove_comment' in item) {
|
||||||
|
return {
|
||||||
|
actionName: 'Comment Removal',
|
||||||
|
community: item.community,
|
||||||
|
content: item.comment.content,
|
||||||
|
timestamp: Date.parse(`${item.mod_remove_comment.when_}Z`),
|
||||||
|
moderatee: item.commenter,
|
||||||
|
moderator: item.moderator,
|
||||||
|
reason: item.mod_remove_comment.reason,
|
||||||
|
link: `/comment/${item.comment.id}`,
|
||||||
|
}
|
||||||
|
} else if ('mod_remove_post' in item) {
|
||||||
|
return {
|
||||||
|
actionName: 'Post Removal',
|
||||||
|
community: item.community,
|
||||||
|
content: item.post.name,
|
||||||
|
timestamp: Date.parse(`${item.mod_remove_post.when_}Z`),
|
||||||
|
moderator: item.moderator,
|
||||||
|
reason: item.mod_remove_post.reason,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
actionName: 'Unknown',
|
||||||
|
timestamp: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function load({ url }) {
|
||||||
|
if (!get(profile)) return
|
||||||
|
const { jwt } = get(profile)!
|
||||||
|
if (!jwt) return
|
||||||
|
|
||||||
|
let community = Number(url.searchParams.get('community')) || undefined
|
||||||
|
let modId = Number(url.searchParams.get('mod_id')) || undefined
|
||||||
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
|
|
||||||
|
const results = await getClient().getModlog({
|
||||||
|
auth: jwt,
|
||||||
|
community_id: community,
|
||||||
|
limit: 40,
|
||||||
|
type_: 'All',
|
||||||
|
page: page,
|
||||||
|
mod_person_id: modId,
|
||||||
|
})
|
||||||
|
|
||||||
|
const moderation = [
|
||||||
|
...results.banned_from_community,
|
||||||
|
...results.removed_comments,
|
||||||
|
...results.removed_posts,
|
||||||
|
]
|
||||||
|
|
||||||
|
const moderationActions = moderation.map(_toModLog)
|
||||||
|
|
||||||
|
return {
|
||||||
|
modlog: moderationActions,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Link from '$lib/components/input/Link.svelte'
|
||||||
|
import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte'
|
||||||
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
|
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
|
||||||
|
import type { ModLog } from './+page.js'
|
||||||
|
|
||||||
|
export let item: ModLog
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Card elevation={0} class="p-5 flex flex-col gap-1 text-sm">
|
||||||
|
<SectionTitle>Action</SectionTitle>
|
||||||
|
<span class="font-bold text-base">{item.actionName}</span>
|
||||||
|
{#if item.moderator}
|
||||||
|
<SectionTitle class="mt-3">Moderator</SectionTitle>
|
||||||
|
<UserLink avatar user={item.moderator} />
|
||||||
|
{/if}
|
||||||
|
{#if item.moderatee}
|
||||||
|
<SectionTitle class="mt-3">Moderatee</SectionTitle>
|
||||||
|
<UserLink avatar user={item.moderatee} />
|
||||||
|
{/if}
|
||||||
|
{#if item.community}
|
||||||
|
<SectionTitle class="mt-3">Community</SectionTitle>
|
||||||
|
<CommunityLink avatar community={item.community} />
|
||||||
|
{/if}
|
||||||
|
{#if item.link}
|
||||||
|
<SectionTitle class="mt-3">Link</SectionTitle>
|
||||||
|
<Link highlight href={item.link} />
|
||||||
|
{/if}
|
||||||
|
</Card>
|
||||||
Reference in new issue
Block a user