feat: add comment distinguish option
This commit is contained in:
1 parent
5ea1f2e0cf
commit
0a6310380f
3 files changed
+42
-7
No files matched your search
@@ -1,7 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||||
import { amMod, ban, isAdmin, remove } from './moderation'
|
import { amMod, ban, feature, isAdmin, remove } from './moderation'
|
||||||
import { Fire, Icon, ShieldExclamation, Trash } from 'svelte-hero-icons'
|
import {
|
||||||
|
Fire,
|
||||||
|
Icon,
|
||||||
|
Megaphone,
|
||||||
|
ShieldExclamation,
|
||||||
|
Trash,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
import { isCommentView } from '$lib/lemmy/item.js'
|
import { isCommentView } from '$lib/lemmy/item.js'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
||||||
@@ -29,8 +35,8 @@
|
|||||||
{$t('moderation.label')}
|
{$t('moderation.label')}
|
||||||
{/if}
|
{/if}
|
||||||
</MenuDivider>
|
</MenuDivider>
|
||||||
<MenuButton color="success-subtle" on:click={() => remove(item)}>
|
<MenuButton color="danger-subtle" on:click={() => remove(item)}>
|
||||||
<Icon src={Trash} size="16" mini />
|
<Icon src={Trash} size="16" mini slot="prefix" />
|
||||||
{#if isCommentView(item)}
|
{#if isCommentView(item)}
|
||||||
{item.comment.removed
|
{item.comment.removed
|
||||||
? $t('moderation.restore')
|
? $t('moderation.restore')
|
||||||
@@ -40,16 +46,37 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
{#if $profile?.user && $profile.user?.local_user_view.person.id != item.creator.id}
|
||||||
|
<!--Comment made by someone else-->
|
||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
on:click={() =>
|
||||||
ban(item.creator_banned_from_community, item.creator, item.community)}
|
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
|
{item.creator_banned_from_community
|
||||||
? $t('moderation.ban.unbanFromCommunity')
|
? $t('moderation.ban.unbanFromCommunity')
|
||||||
: $t('moderation.ban.banFromCommunity')}
|
: $t('moderation.ban.banFromCommunity')}
|
||||||
</MenuButton>
|
</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}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import { client } from '$lib/lemmy'
|
||||||
import type { SubmissionView } from '$lib/lemmy/contentview.js'
|
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'
|
import { get, writable } from 'svelte/store'
|
||||||
|
|
||||||
interface Modals {
|
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) =>
|
export const amMod = (me: MyUserInfo, community: Community) =>
|
||||||
me.moderates.map((c) => c.community.id).includes(community.id) ||
|
me.moderates.map((c) => c.community.id).includes(community.id) ||
|
||||||
(community.local && isAdmin(me))
|
(community.local && isAdmin(me))
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ type Feature = keyof typeof FEATURES
|
|||||||
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
||||||
versionIsSupported(version, FEATURES[feature])
|
versionIsSupported(version, FEATURES[feature])
|
||||||
|
|
||||||
export const MINIMUM_VERSION = '0.19.0'
|
export const MINIMUM_VERSION = '0.19.4'
|
||||||
export const MAXIMUM_VERSION = '0.999'
|
export const MAXIMUM_VERSION = '0.999'
|
||||||
|
|
||||||
export const versionIsSupported = (v: string, minimum: string) => {
|
export const versionIsSupported = (v: string, minimum: string) => {
|
||||||
|
|||||||
Reference in new issue
Block a user