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