feat: add comment distinguish option

This commit is contained in:
Xylight committed 2024-07-20 11:49:05 -07:00
1 parent 5ea1f2e0cf
commit 0a6310380f
3 files changed
+42 -7

No files matched your search

@@ -1,7 +1,13 @@
<script lang="ts">
import type { CommentView, PostView } from 'lemmy-js-client'
import { amMod, ban, isAdmin, remove } from './moderation'
import { Fire, Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
import { amMod, ban, feature, isAdmin, remove } from './moderation'
import {
Fire,
Icon,
Megaphone,
ShieldExclamation,
Trash,
} from 'svelte-hero-icons'
import { isCommentView } from '$lib/lemmy/item.js'
import { profile } from '$lib/auth.js'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
@@ -29,8 +35,8 @@
{$t('moderation.label')}
{/if}
</MenuDivider>
<MenuButton color="success-subtle" on:click={() => remove(item)}>
<Icon src={Trash} size="16" mini />
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
<Icon src={Trash} size="16" mini slot="prefix" />
{#if isCommentView(item)}
{item.comment.removed
? $t('moderation.restore')
@@ -40,16 +46,37 @@
{/if}
</MenuButton>
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
<!--Comment made by someone else-->
<MenuButton
color="danger-subtle"
on:click={() =>
ban(item.creator_banned_from_community, item.creator, item.community)}
>
<Icon src={ShieldExclamation} size="16" mini />
<Icon src={ShieldExclamation} size="16" mini slot="prefix" />
{item.creator_banned_from_community
? $t('moderation.ban.unbanFromCommunity')
: $t('moderation.ban.banFromCommunity')}
</MenuButton>
{:else if isCommentView(item)}
<!--Comment made by self-->
<MenuButton
color="success-subtle"
on:click={async () => {
if (!$profile.jwt) return
item.comment = (
await feature(
!item.comment.distinguished,
item.comment,
$profile.jwt
)
).comment_view.comment
}}
>
<Icon src={Megaphone} size="16" micro slot="prefix" />
{item.comment.distinguished
? $t('moderation.unfeature')
: $t('moderation.feature')}
</MenuButton>
{/if}
{/if}
@@ -1,5 +1,6 @@
import { client } from '$lib/lemmy'
import type { SubmissionView } from '$lib/lemmy/contentview.js'
import type { Community, MyUserInfo, Person } from 'lemmy-js-client'
import type { Comment, Community, MyUserInfo, Person } from 'lemmy-js-client'
import { get, writable } from 'svelte/store'
interface Modals {
@@ -71,6 +72,13 @@ export function ban(banned: boolean, item: Person, community?: Community) {
}))
}
export async function feature(featured: boolean, item: Comment, jwt: string) {
return await client({ auth: jwt }).distinguishComment({
comment_id: item.id,
distinguished: featured,
})
}
export const amMod = (me: MyUserInfo, community: Community) =>
me.moderates.map((c) => c.community.id).includes(community.id) ||
(community.local && isAdmin(me))