Coves frontend - a photon fork
1<script lang="ts">
2 // @ts-nocheck TODO(coves-migration): Needs Coves comment moderation API (distinguish, lock)
3 import type { CommentView } from '$lib/api/types'
4 import { profile } from '$lib/app/auth.svelte'
5 import { t } from '$lib/app/i18n'
6 import { Menu, MenuButton, MenuDivider } from 'mono-svelte'
7 import type { Snippet } from 'svelte'
8 import {
9 ArrowsUpDown,
10 Fire,
11 Icon,
12 Megaphone,
13 Newspaper,
14 ShieldExclamation,
15 Trash,
16 } from 'svelte-hero-icons/dist'
17 import type { Attachment } from 'svelte/attachments'
18 import { isCommentView } from '../legacy/item.svelte'
19 import { ban, feature, remove, viewVotes } from './moderation.svelte'
20
21 interface Props {
22 item: CommentView
23 target: Snippet<[Attachment]>
24 }
25
26 let { item = $bindable(), target, ...rest }: Props = $props()
27</script>
28
29<Menu {...rest} placement="bottom" {target}>
30 {#if profile.isMod(item.community) || profile.isAdmin}
31 <MenuDivider hidden>
32 {#if !item.community.local && !profile.isMod(item.community)}
33 {$t('moderation.labelInstanceOnly')}
34 {:else}
35 {$t('moderation.label')}
36 {/if}
37 </MenuDivider>
38 <MenuButton color="danger-subtle" onclick={() => remove(item)} icon={Trash}>
39 {#if isCommentView(item)}
40 {item.comment.removed
41 ? $t('moderation.restore')
42 : $t('moderation.remove')}
43 {/if}
44 </MenuButton>
45 {#if profile.current?.jwt}
46 <!-- TODO: Check comment ownership using DID when Coves API provides creator DID -->
47 <MenuButton
48 color="danger-subtle"
49 onclick={() =>
50 ban(item.creator_banned_from_community, item.creator, item.community)}
51 icon={ShieldExclamation}
52 >
53 {item.creator_banned_from_community
54 ? $t('moderation.ban.unbanFromCommunity')
55 : $t('moderation.ban.banFromCommunity')}
56 </MenuButton>
57 {:else}
58 <!--Comment made by self-->
59 <MenuButton
60 color="success-subtle"
61 onclick={async () => {
62 if (!profile.current.jwt) return
63 item.comment = (
64 await feature(
65 !item.comment.distinguished,
66 item.comment,
67 profile.current.jwt,
68 )
69 ).comment_view.comment
70 }}
71 icon={Megaphone}
72 >
73 {item.comment.distinguished
74 ? $t('moderation.unfeature')
75 : $t('moderation.feature')}
76 </MenuButton>
77 {/if}
78
79 <MenuButton color="success-subtle" href="/modlog?comment={item.comment.id}">
80 <Icon src={Newspaper} size="16" micro />
81 {$t('moderation.modlog.comment')}
82 </MenuButton>
83 <MenuButton color="success-subtle" href="/modlog?user={item.creator.id}">
84 <Icon src={Newspaper} size="16" micro />
85 {$t('moderation.modlog.user')}
86 </MenuButton>
87 <MenuButton color="blue-subtle" onclick={() => viewVotes(item)}>
88 <Icon src={ArrowsUpDown} size="16" micro />
89 {$t('moderation.votes')}
90 </MenuButton>
91 {/if}
92
93 {#if profile.isAdmin}
94 <MenuDivider showLabel>{$t('admin.label')}</MenuDivider>
95 <MenuButton
96 color="danger-subtle"
97 onclick={() => remove(item, true)}
98 icon={Fire}
99 >
100 {$t('admin.purge')}
101 </MenuButton>
102 {/if}
103</Menu>