feat: add and close #169
This commit is contained in:
1 parent
ea594e0061
commit
108169f5a9
9 files changed
+89
-44
No files matched your search
+52
-15
@@ -1,4 +1,7 @@
|
||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import {
|
||||
amModOfAny,
|
||||
isAdmin,
|
||||
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||
import { toast } from 'mono-svelte'
|
||||
import { DEFAULT_INSTANCE_URL, instance } from '$lib/instance.js'
|
||||
import { client, getClient, site } from '$lib/lemmy.js'
|
||||
@@ -51,8 +54,11 @@ interface ProfileData {
|
||||
}
|
||||
|
||||
interface PersonData extends MyUserInfo {
|
||||
unreads: number
|
||||
reports: number
|
||||
notifications: {
|
||||
inbox: number
|
||||
reports: number
|
||||
applications: number
|
||||
}
|
||||
}
|
||||
|
||||
export let profileData = writable<ProfileData>(
|
||||
@@ -192,8 +198,11 @@ async function userFromJwt(
|
||||
|
||||
return {
|
||||
user: {
|
||||
unreads: 0,
|
||||
reports: 0,
|
||||
notifications: {
|
||||
applications: 0,
|
||||
inbox: 0,
|
||||
reports: 0,
|
||||
},
|
||||
...myUser,
|
||||
},
|
||||
site: site,
|
||||
@@ -296,23 +305,44 @@ export function moveProfile(id: number, up: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
const getNotificationCount = async (jwt: string, mod: boolean) => {
|
||||
const getNotificationCount = async (
|
||||
jwt: string,
|
||||
mod: boolean,
|
||||
admin: boolean
|
||||
) => {
|
||||
const unreads = await getClient().getUnreadCount()
|
||||
|
||||
let reports: number = 0
|
||||
let applications: number = 0
|
||||
|
||||
if (mod) {
|
||||
const reportRes = await getClient().getReportCount({})
|
||||
try {
|
||||
const reportRes = await getClient().getReportCount({})
|
||||
|
||||
reports =
|
||||
reportRes.comment_reports +
|
||||
reportRes.post_reports +
|
||||
(reportRes.private_message_reports ?? 0)
|
||||
reports =
|
||||
reportRes.comment_reports +
|
||||
reportRes.post_reports +
|
||||
(reportRes.private_message_reports ?? 0)
|
||||
} catch (e) {
|
||||
// doesn't matter
|
||||
}
|
||||
}
|
||||
|
||||
if (admin) {
|
||||
try {
|
||||
const applicationRes =
|
||||
await getClient().getUnreadRegistrationApplicationCount()
|
||||
|
||||
applications = applicationRes.registration_applications
|
||||
} catch (e) {
|
||||
// doesn't matter
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
unreads: unreads.mentions + unreads.private_messages + unreads.replies,
|
||||
reports: reports,
|
||||
applications: applications,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,13 +353,20 @@ setInterval(async () => {
|
||||
const { user, jwt } = get(profile)!
|
||||
if (!jwt || !user) return
|
||||
|
||||
const notifs = await getNotificationCount(jwt, amModOfAny(user) ?? false)
|
||||
const notifs = await getNotificationCount(
|
||||
jwt,
|
||||
amModOfAny(user) ?? false,
|
||||
isAdmin(user)
|
||||
)
|
||||
|
||||
user.unreads = notifs.unreads
|
||||
user.reports = notifs.reports
|
||||
user.notifications = {
|
||||
inbox: notifs.unreads,
|
||||
applications: notifs.applications,
|
||||
reports: notifs.reports,
|
||||
}
|
||||
|
||||
profile.update((p) => ({
|
||||
...p!,
|
||||
user: user,
|
||||
}))
|
||||
}, get(userSettings).notifications.pollRate ?? 30 * 1000)
|
||||
}, 5 * 60 * 1000)
|
||||
@@ -13,6 +13,7 @@
|
||||
import { userSettings } from '$lib/settings.js'
|
||||
import { theme } from '$lib/ui/colors.js'
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Menu,
|
||||
MenuButton,
|
||||
@@ -111,10 +112,16 @@
|
||||
<Button
|
||||
href="/admin"
|
||||
aria-label="Admin"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 dark:text-zinc-300 text-slate-700"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 dark:text-zinc-300 text-slate-700 relative"
|
||||
>
|
||||
<Icon src={ServerStack} mini size="18" slot="prefix" />
|
||||
<span class="hidden md:inline">Admin</span>
|
||||
|
||||
{#if $profile?.user?.notifications.applications ?? 0 > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
{/if}
|
||||
</Button>
|
||||
{/if}
|
||||
{#if amModOfAny($profile?.user)}
|
||||
@@ -123,7 +130,7 @@
|
||||
aria-label="Moderation"
|
||||
class="max-md:w-9 max-md:h-8 max-md:!p-0 dark:text-zinc-300 text-slate-700 relative"
|
||||
>
|
||||
{#if $profile?.user?.reports ?? 0 > 0}
|
||||
{#if $profile?.user?.notifications.reports ?? 0 > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
||||
/>
|
||||
@@ -205,7 +212,7 @@
|
||||
alt={$profile.user.local_user_view.person.name}
|
||||
/>
|
||||
</div>
|
||||
{#if $profile.user.unreads > 0}
|
||||
{#if $profile.user.notifications.inbox > 0}
|
||||
<div
|
||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
||||
/>
|
||||
@@ -226,12 +233,10 @@
|
||||
<MenuButton link href="/inbox">
|
||||
<Icon src={Inbox} mini width={16} />
|
||||
Inbox
|
||||
{#if $profile.user.unreads > 0}
|
||||
<div
|
||||
class="rounded-full w-auto flex items-center px-2 h-5 justify-center font-bold bg-red-500 ml-auto"
|
||||
>
|
||||
{$profile.user.unreads}
|
||||
</div>
|
||||
{#if $profile.user.notifications.inbox > 0}
|
||||
<Badge color="red-subtle" class="text-xs ml-auto font-bold !py-0.5">
|
||||
{$profile.user.notifications.inbox}
|
||||
</Badge>
|
||||
{/if}
|
||||
</MenuButton>
|
||||
<MenuButton link href="/saved">
|
||||
@@ -241,11 +246,6 @@
|
||||
<MenuButton link href="/accounts">
|
||||
<Icon src={UserGroup} mini width={16} />
|
||||
Accounts
|
||||
<span
|
||||
class="text-xs font-bold bg-slate-100 dark:bg-zinc-700 px-2 py-0.5 rounded-md ml-auto"
|
||||
>
|
||||
{$profileData.profiles.length}
|
||||
</span>
|
||||
</MenuButton>
|
||||
<hr class="dark:opacity-10 w-[90%] my-2 mx-auto" />
|
||||
<MenuDivider>App</MenuDivider>
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
<script>
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
import { profile } from '$lib/auth'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import { Badge } from 'mono-svelte'
|
||||
</script>
|
||||
|
||||
{#if $profile?.user?.notifications.applications ?? 0 > 0}
|
||||
<span class="flex flex-row text-red-500 gap-2">
|
||||
<Badge color="red-subtle" class="w-max">
|
||||
{$profile?.user?.notifications.applications}
|
||||
</Badge> unread applications
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-4 h-full">
|
||||
<MultiSelect
|
||||
headless
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
import type { RegistrationApplicationView } from 'lemmy-js-client'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Check, Icon, XMark } from 'svelte-hero-icons'
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte';
|
||||
import { publishedToDate } from '$lib/components/util/date';
|
||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||
import { publishedToDate } from '$lib/components/util/date'
|
||||
|
||||
export let application: RegistrationApplicationView
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
})
|
||||
application.creator_local_user.accepted_application = approve
|
||||
application.admin = $profile.user!.local_user_view.person
|
||||
|
||||
$profile.user!.notifications.applications -= 1
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
@@ -52,7 +54,9 @@
|
||||
<Material class="flex flex-col gap-2">
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-slate-600 dark:text-zinc-400">
|
||||
<RelativeDate date={publishedToDate(application.registration_application.published)} />
|
||||
<RelativeDate
|
||||
date={publishedToDate(application.registration_application.published)}
|
||||
/>
|
||||
</span>
|
||||
|
||||
<SectionTitle>User</SectionTitle>
|
||||
@@ -79,8 +83,8 @@
|
||||
<div class="ml-auto">
|
||||
<Button
|
||||
size="square-md"
|
||||
class="hover:bg-slate-200 {!application.creator_local_user
|
||||
.accepted_application
|
||||
class="hover:bg-slate-200 {application.creator_local_user
|
||||
.accepted_application === false && application.admin
|
||||
? '!text-red-500'
|
||||
: ''}"
|
||||
aria-label="Deny"
|
||||
|
||||
@@ -134,7 +134,6 @@
|
||||
Captcha enabled
|
||||
</Checkbox>
|
||||
{#if formData.captcha_enabled}
|
||||
{console.log(formData.captcha_difficulty)}
|
||||
<Select bind:value={formData.captcha_difficulty} />
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
const response = await getClient().markAllAsRead()
|
||||
|
||||
$profile.user.unreads = 0
|
||||
$profile.user.notifications.inbox = 0
|
||||
|
||||
goto($page.url, {
|
||||
invalidateAll: true,
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
}
|
||||
|
||||
item.read = isRead
|
||||
if ($profile.user) $profile.user.unreads += isRead ? -1 : 1
|
||||
if ($profile.user) $profile.user.notifications.inbox += isRead ? -1 : 1
|
||||
|
||||
loading = false
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</script>
|
||||
|
||||
<div class="mb-4 flex flex-col gap-4">
|
||||
<h1 class="font-bold text-3xl">Reports</h1>
|
||||
<h1 class="font-bold text-3xl">Moderation</h1>
|
||||
<div class="flex flex-row gap-2 flex-wrap items-center">
|
||||
<Select
|
||||
bind:value={data.type}
|
||||
|
||||
@@ -76,12 +76,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
const reports = await getClient().getReportCount({})
|
||||
|
||||
$profile.user.reports =
|
||||
reports.comment_reports +
|
||||
reports.post_reports +
|
||||
(reports.private_message_reports ?? 0)
|
||||
$profile.user.notifications.reports += item.resolved ? 1 : -1
|
||||
} catch (err) {
|
||||
toast({
|
||||
content: err as any,
|
||||
|
||||
Reference in new issue
Block a user