feat: rewrite report/inbox handling

This commit is contained in:
Xyphyn committed 2023-09-17 14:40:55 -07:00
1 parent d9ab0db31c
commit 30d5dc9bf2
13 files changed
+468 -429

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "1.7.3", "version": "1.8.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
-39
View File
@@ -2,7 +2,6 @@ import { amModOfAny } 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 { getClient, site } from '$lib/lemmy.js' import { getClient, site } from '$lib/lemmy.js'
import { getInbox, getInboxItemPublished } from '$lib/lemmy/inbox.js'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import { moveItem } from '$lib/util.js' import { moveItem } from '$lib/util.js'
import { import {
@@ -294,41 +293,3 @@ setInterval(async () => {
user: user, user: user,
})) }))
}, get(userSettings).notifications.pollRate ?? 30 * 1000) }, get(userSettings).notifications.pollRate ?? 30 * 1000)
setFromStorage('seenUntil', Date.now().toString(), false)
export async function getInboxNotifications(dontUpdate: boolean = false) {
if (!get(profile) || !get(userSettings).notifications.enabled) return
const { jwt } = get(profile)!
if (!jwt) return
let until = Number(localStorage.getItem('seenUntil'))
if (Number.isNaN(until) || until == 0) {
const now = Date.now()
localStorage.setItem('seenUntil', now.toString())
until = now
}
const inbox = await getInbox(jwt, until)
inbox.forEach((item) => {
const notif = new Notification(
item.person.display_name ?? item.person.name,
{
body: item.body,
timestamp: item.created,
icon: item.person.avatar,
}
)
notif.onclick = (e) => {
window.open('/inbox')
}
})
if (dontUpdate) return
localStorage.setItem('seenUntil', Date.now().toString())
}
@@ -0,0 +1,44 @@
<script lang="ts">
import { profile } from '$lib/auth.js'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
import type { PrivateMessageView } from 'lemmy-js-client'
import { Icon, PaperAirplane } from 'svelte-hero-icons'
export let message: PrivateMessageView
</script>
<div class="flex flex-col gap-2">
<div class="flex flex-row gap-2 items-center flex-wrap">
<span class="font-medium text-xs">From</span>
<UserLink
showInstance={false}
user={message.creator}
avatar
avatarSize={20}
shownBadges={{
admin: true,
banned: true,
bot: true,
you: $profile?.user?.local_user_view.person.id == message.creator.id,
}}
/>
{#if $profile?.user?.local_user_view.person.id != message.recipient.id}
to
<UserLink
showInstance={false}
user={message.recipient}
avatar
avatarSize={20}
shownBadges={{
admin: true,
banned: true,
bot: true,
you:
$profile?.user?.local_user_view.person.id == message.recipient.id,
}}
/>
{/if}
</div>
<Markdown source={message.private_message.content} />
</div>
@@ -0,0 +1,61 @@
<script lang="ts">
import { profile } from '$lib/auth.js'
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { getClient } from '$lib/lemmy.js'
import type { Person } from 'lemmy-js-client'
import { Button, Modal, toast } from 'mono-svelte'
export let open: boolean = false
export let user: Person
let message = ''
let loading = false
async function sendMessage() {
if (!$profile?.jwt || message == '') return
loading = true
try {
await getClient().createPrivateMessage({
auth: $profile.jwt,
content: message,
recipient_id: user.id,
})
toast({
content: 'Successfully sent that person a message.',
type: 'success',
})
open = false
} catch (err) {
toast({
content: err as any,
type: 'error',
})
}
loading = false
}
</script>
<Modal bind:open>
<h1 class="text-2xl font-bold" slot="title">Message</h1>
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4">
<p class="inline-flex flex-row gap-2 items-center">
Sending <UserLink avatar {user} /> a message
</p>
<MarkdownEditor
bind:value={message}
label="Message"
placeholder="your hair looks nice today"
rows={4}
/>
<Button color="primary" size="lg" submit {loading} disabled={loading}>
Send
</Button>
</form>
</Modal>
+27 -16
View File
@@ -1,8 +1,10 @@
<script lang="ts"> <script lang="ts">
import { profile } from '$lib/auth.js'
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte' import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte' import Avatar from '$lib/components/ui/Avatar.svelte'
import { userSettings } from '$lib/settings.js' import { userSettings } from '$lib/settings.js'
import type { Person } from 'lemmy-js-client' import type { Person } from 'lemmy-js-client'
import { Badge } from 'mono-svelte'
import { Icon, NoSymbol } from 'svelte-hero-icons' import { Icon, NoSymbol } from 'svelte-hero-icons'
export let user: Person export let user: Person
@@ -11,6 +13,12 @@
export let badges: boolean = true export let badges: boolean = true
export let inComment: boolean = false export let inComment: boolean = false
export let showInstance: boolean = false export let showInstance: boolean = false
export let shownBadges = {
admin: true,
you: false,
bot: true,
banned: true,
}
function linkFromCommunity(user: Person) { function linkFromCommunity(user: Person) {
const domain = new URL(user.actor_id).hostname const domain = new URL(user.actor_id).hostname
@@ -44,21 +52,24 @@
</span> </span>
{/if} {/if}
</span> </span>
{#if badges && (user.admin || user.banned || user.bot_account)} {#if badges}
<span> {#if shownBadges.you}
{#if user.admin} <Badge color="green-subtle" label="You" class="text-[10px] px-1 py-[1px]">
<div class="text-red-500" title="Admin"> You
<ShieldIcon width={12} filled /> </Badge>
</div> {/if}
{/if} {#if shownBadges.admin && user.admin}
{#if user.banned} <div class="text-red-500" title="Admin">
<div class="text-red-500" title="Banned"> <ShieldIcon width={12} filled />
<Icon src={NoSymbol} mini size="12" /> </div>
</div> {/if}
{/if} {#if shownBadges.banned && user.banned}
{#if user.bot_account} <div class="text-red-500" title="Banned">
<div class="text-blue-500 font-bold" title="Bot">BOT</div> <Icon src={NoSymbol} mini size="12" />
{/if} </div>
</span> {/if}
{#if shownBadges.bot && user.bot_account}
<div class="text-blue-500 font-bold" title="Bot">BOT</div>
{/if}
{/if} {/if}
</a> </a>
+52 -102
View File
@@ -1,10 +1,12 @@
import { publishedToDate } from '$lib/components/util/date.js'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import type { Result } from '$lib/lemmy/item.js' import type { Result } from '$lib/lemmy/item.js'
import type { import type {
Comment,
CommentReplyView, CommentReplyView,
CommentView,
Person, Person,
PersonMentionView, PersonMentionView,
PersonView,
PrivateMessageView, PrivateMessageView,
} from 'lemmy-js-client' } from 'lemmy-js-client'
@@ -13,110 +15,58 @@ export type InboxItemView =
| CommentReplyView | CommentReplyView
| PrivateMessageView | PrivateMessageView
export function getInboxItemPublished(item: InboxItemView): string { export const generalizeCommentReply = (item: CommentReplyView): InboxItem => ({
if ('comment_reply' in item) { type: 'comment_reply',
return item.comment_reply.published id: item.comment_reply.id,
} published: item.comment_reply.published,
item: { ...item },
creator: item.creator,
read: item.comment_reply.read,
})
if ('private_message' in item) { export const generalizePersonMention = (
return item.private_message.published item: PersonMentionView
} ): InboxItem => ({
type: 'person_mention',
id: item.person_mention.id,
published: item.person_mention.published,
item: {
...item,
},
creator: item.creator,
read: item.person_mention.read,
})
return item.person_mention.published export const generalizePrivateMessage = (
item: PrivateMessageView
): InboxItem => ({
type: 'private_message',
id: item.private_message.id,
published: item.private_message.published,
item: item,
creator: item.creator,
read: item.private_message.read,
})
interface PrivateMessage {
type: 'private_message'
item: PrivateMessageView
}
interface CommentReply {
type: 'comment_reply'
item: CommentView
}
interface PersonMention {
type: 'person_mention'
item: CommentView
} }
export function isRead( interface BaseInboxItem {
item: PersonMentionView | CommentReplyView | PrivateMessageView creator: Person
) { published: string
if ('person_mention' in item) { read: boolean
return (item as PersonMentionView).person_mention.read id: number
}
if ('comment_reply' in item) {
return (item as CommentReplyView).comment_reply.read
}
if ('private_message' in item) {
return (item as PrivateMessageView).private_message.read
}
return false
} }
export const getInbox = async ( export type InboxItem = BaseInboxItem &
jwt: string, (PrivateMessage | CommentReply | PersonMention)
until?: number
): Promise<InboxItem[]> => {
const client = getClient()
const params = {
limit: 50,
auth: jwt,
unread_only: true,
}
const [replies, mentions, privateMessages] = await Promise.all([
client.getReplies({
...params,
sort: 'New',
}),
client.getPersonMentions({
...params,
sort: 'New',
}),
client.getPrivateMessages({ ...params }),
])
let items = [
...replies.replies,
...mentions.mentions,
...privateMessages.private_messages,
]
.map(toInboxItem)
.sort((a, b) => b.created - a.created)
if (until) {
items = items.filter((item) => item.created > until)
}
return items
}
const toInboxItem = (item: InboxItemView): InboxItem => {
let type: 'private_message' | 'comment_reply' | 'person_mention'
let body: string
let personView: Person
let created: number
if ('comment_reply' in item) {
type = 'comment_reply'
body = item.comment.content
personView = item.creator
created = Date.parse(`${item.comment_reply.published}Z`)
} else if ('person_mention' in item) {
type = 'person_mention'
body = item.comment.content
personView = item.creator
created = Date.parse(`${item.person_mention.published}Z`)
} else if ('private_message' in item) {
type = 'private_message'
body = item.private_message.content
personView = item.creator
created = Date.parse(`${item.private_message.published}Z`)
} else {
throw new Error('Invalid item')
}
return {
type: type,
body: body,
person: personView,
created,
}
}
interface InboxItem {
type: 'private_message' | 'comment_reply' | 'person_mention'
body: string
person: Person
created: number
}
+93
View File
@@ -0,0 +1,93 @@
import { publishedToDate } from '$lib/components/util/date.js'
import type {
CommentReportView,
CommentView,
Person,
PostReportView,
PostView,
PrivateMessage,
PrivateMessageReportView,
PrivateMessageView,
} from 'lemmy-js-client'
interface CommentReport {
type: 'comment'
item: CommentView
}
interface PostReport {
type: 'post'
item: PostView
}
interface PrivateMessageReport {
type: 'message'
item: PrivateMessage
reportee: Person
}
interface BaseReport {
creator: Person
reason: string
reportee?: Person
timestamp: Date
resolved: boolean
id: number
}
export const generalizeCommentReport = (
report: CommentReportView
): ReportView => ({
creator: report.creator,
item: {
...report,
subscribed: 'NotSubscribed',
saved: false,
creator_blocked: false,
creator: report.comment_creator,
},
reason: report.comment_report.reason,
type: 'comment',
timestamp: publishedToDate(report.comment_report.published),
resolved: report.comment_report.resolved,
id: report.comment_report.id,
})
export const generalizePostReport = (report: PostReportView): ReportView => ({
creator: report.creator,
item: {
...report,
unread_comments: 0,
saved: false,
creator_blocked: false,
read: false,
subscribed: 'NotSubscribed',
creator: report.post_creator,
},
reason: report.post_report.reason,
type: 'post',
timestamp: publishedToDate(report.post_report.published),
resolved: report.post_report.resolved,
id: report.post_report.id,
})
export const generalizePrivateMessageReport = (
report: PrivateMessageReportView
): ReportView => ({
creator: report.creator,
item: report.private_message,
reason: report.private_message_report.reason,
type: 'message',
reportee: report.private_message_creator,
timestamp: publishedToDate(report.private_message_report.published),
resolved: report.private_message_report.resolved,
id: report.private_message_report.id,
})
export type Report =
| CommentReportView
| PostReportView
| PrivateMessageReportView
export type ReportView = BaseReport &
(CommentReport | PostReport | PrivateMessageReport)
+1 -3
View File
@@ -11,9 +11,7 @@
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import { page } from '$app/stores' import { page } from '$app/stores'
import { isRead } from '$lib/lemmy/inbox.js'
import Pageination from '$lib/components/ui/Pageination.svelte' import Pageination from '$lib/components/ui/Pageination.svelte'
import MultiSelect from '$lib/components/input/Switch.svelte'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import Placeholder from '$lib/components/ui/Placeholder.svelte' import Placeholder from '$lib/components/ui/Placeholder.svelte'
import { fly } from 'svelte/transition' import { fly } from 'svelte/transition'
@@ -109,7 +107,7 @@
{:else} {:else}
{#each data.data as item} {#each data.data as item}
<div in:fly={{ duration: 500, y: -6, opacity: 0 }}> <div in:fly={{ duration: 500, y: -6, opacity: 0 }}>
<InboxItem {item} read={isRead(item)} /> <InboxItem {item} />
</div> </div>
{/each} {/each}
<Pageination <Pageination
+11 -6
View File
@@ -1,6 +1,11 @@
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { publishedToDate } from '$lib/components/util/date.js'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import { getInboxItemPublished } from '$lib/lemmy/inbox.js' import {
generalizeCommentReply,
generalizePersonMention,
generalizePrivateMessage,
} from '$lib/lemmy/inbox.js'
import { get } from 'svelte/store' import { get } from 'svelte/store'
type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all' type InboxFeedType = 'replies' | 'mentions' | 'messages' | 'all'
@@ -45,13 +50,13 @@ export async function load({ url, fetch }) {
]) ])
const data = [ const data = [
...replies.replies, ...replies.replies.map(generalizeCommentReply),
...mentions.mentions, ...mentions.mentions.map(generalizePersonMention),
...privateMessages.private_messages, ...privateMessages.private_messages.map(generalizePrivateMessage),
].sort( ].sort(
(a, b) => (a, b) =>
Date.parse(getInboxItemPublished(b)) - publishedToDate(b.published).getTime() -
Date.parse(getInboxItemPublished(a)) publishedToDate(a.published).getTime()
) )
return { unreadOnly: unreadOnly, type: type, page: page, data: data } return { unreadOnly: unreadOnly, type: type, page: page, data: data }
+69 -115
View File
@@ -12,26 +12,18 @@
} from 'lemmy-js-client' } from 'lemmy-js-client'
import { ChatBubbleOvalLeft, Check, Icon } from 'svelte-hero-icons' import { ChatBubbleOvalLeft, Check, Icon } from 'svelte-hero-icons'
import { page } from '$app/stores' import { page } from '$app/stores'
import { Material, toast } from 'mono-svelte' import { Material, Modal, toast } from 'mono-svelte'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte' import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte' import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte' import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import RelativeDate from '$lib/components/util/RelativeDate.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte'
import { publishedToDate } from '$lib/components/util/date.js' import { publishedToDate } from '$lib/components/util/date.js'
import type { InboxItem, InboxItemView } from '$lib/lemmy/inbox.js'
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
import PrivateMessageModal from '$lib/components/lemmy/modal/PrivateMessageModal.svelte'
export let item: CommentReplyView | PersonMentionView | PrivateMessageView export let item: InboxItem
export let read: boolean
function isPrivateMessage(
item: CommentReplyView | PersonMentionView | PrivateMessageView
): item is PrivateMessageView {
return 'private_message' in item
}
const isCommentReply = (
item: CommentReplyView | PersonMentionView | PrivateMessageView
): item is CommentReplyView => 'comment_reply' in item
let replying = false let replying = false
let reply = '' let reply = ''
@@ -74,132 +66,94 @@
loading = true loading = true
if ('person_mention' in item) { if (item.type == 'person_mention') {
await getClient().markPersonMentionAsRead({ await getClient().markPersonMentionAsRead({
auth: $profile?.jwt, auth: $profile?.jwt,
person_mention_id: item.person_mention.id, person_mention_id: item.id,
read: isRead, read: isRead,
}) })
} else if ('comment_reply' in item) { } else if (item.type == 'comment_reply') {
await getClient().markCommentReplyAsRead({ await getClient().markCommentReplyAsRead({
auth: $profile?.jwt, auth: $profile?.jwt,
comment_reply_id: item.comment_reply.id, comment_reply_id: item.id,
read: isRead, read: isRead,
}) })
} }
read = isRead item.read = isRead
if ($profile.user) $profile.user.unreads += isRead ? -1 : 1 if ($profile.user) $profile.user.unreads += isRead ? -1 : 1
loading = false loading = false
} }
</script> </script>
{#if replying && item.type == 'private_message'}
<PrivateMessageModal bind:open={replying} user={item.item.creator} />
{/if}
<Material padding="lg" class="flex flex-col max-w-full gap-2"> <Material padding="lg" class="flex flex-col max-w-full gap-2">
{#if !isPrivateMessage(item)} <div class="flex flex-col gap-1">
<div class="flex flex-col gap-1"> <span class="text-xs text-slate-600 dark:text-zinc-400">
<span class="text-xs text-slate-600 dark:text-zinc-400"> <RelativeDate date={publishedToDate(item.published)} />
{#if isCommentReply(item)} </span>
<RelativeDate date={publishedToDate(item.comment_reply.published)} /> {#if item.type != 'private_message'}
{:else} <PostMeta title={item.item.post.name} id={item.item.post.id} />
<RelativeDate date={publishedToDate(item.person_mention.published)} /> {/if}
{/if} </div>
</span> <div class="flex flex-col">
<PostMeta title={item.post.name} id={item.post.id} /> <SectionTitle class="mb-2 text-xs">
</div> {#if item.type == 'private_message'}
<div Message
class="flex flex-col" {:else if item.type == 'person_mention'}
class:mt-2={$profile?.user && Mention
item.post.creator_id != $profile.user.local_user_view.person.id} {:else if item.type == 'comment_reply'}
> Reply
<SectionTitle class="mb-2 text-xs">Reply</SectionTitle>
{#if $profile?.user && item.post.creator_id != $profile.user.local_user_view.person.id}
<div class="flex flex-row text-xs items-center gap-2">
<div
class="border-t w-8 rounded-tl h-2 border-l ml-2 border-zinc-700"
/>
<div>
<UserLink
avatar
avatarSize={16}
user={$profile.user.local_user_view.person}
/>
</div>
</div>
{/if} {/if}
</SectionTitle>
{#if item.type != 'private_message' && $profile?.user && item.item.post.creator_id != $profile.user.local_user_view.person.id}
<div class="flex flex-row text-xs items-center gap-2">
<div
class="border-t w-8 rounded-tl h-2 border-l ml-2 border-zinc-700"
/>
<div>
<UserLink
avatar
avatarSize={16}
user={$profile.user.local_user_view.person}
/>
</div>
</div>
{/if}
{#if item.type == 'private_message'}
<PrivateMessage message={item.item} />
{:else}
<Comment <Comment
postId={item.post.id} postId={item.item.post.id}
node={{ children: [], comment_view: item, depth: 1 }} node={{ children: [], comment_view: item.item, depth: 1 }}
replying={false} replying={false}
class="!p-0" class="!p-0"
/> />
</div> {/if}
<div class="flex flex-row ml-auto gap-2"> </div>
<Button <div class="flex flex-row ml-auto gap-2 h-8">
class={read ? '!text-green-500' : ''} <Button
size="square-md" class={item.read ? '!text-green-500' : ''}
{loading} size="square-md"
disabled={loading} {loading}
on:click={() => markAsRead(!read)} disabled={loading}
> on:click={() => markAsRead(!item.read)}
<Icon slot="prefix" src={Check} mini size="16" /> >
</Button> <Icon slot="prefix" src={Check} mini size="16" />
</Button>
<Button href="/comment/{item.comment.id}" size="md" class="h-8"> {#if item.type == 'private_message'}
{#if item.item.creator.id != $profile?.user?.local_user_view.person.id}
<Button size="md" on:click={() => (replying = !replying)}>Reply</Button>
{/if}
{:else}
<Button href="/comment/{item.item.comment.id}" size="md" class="h-full">
Jump Jump
</Button> </Button>
</div>
{:else}
<div class="flex flex-row items-center">
<div
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
overflow-hidden flex flex-row items-center gap-1 {read ? 'opacity-80' : ''}"
>
<span class="font-bold flex items-center">
{#if item.creator.id == $profile?.user?.local_user_view.person.id}
You
{:else}
<UserLink avatar user={item.creator} />
{/if}
</span>
<span>messaged</span>
<span class="font-bold flex items-center">
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
You
{:else}
<UserLink avatar user={item.recipient} />
{/if}
</span>
</div>
</div>
<p class="text-sm py-2">
<Markdown source={item.private_message.content} />
</p>
{#if item.recipient.id == $profile?.user?.local_user_view.person.id}
<div class="flex flex-row gap-2">
<Button color="ghost" on:click={() => (replying = !replying)}>
<Icon mini src={ChatBubbleOvalLeft} width={16} />
Reply
</Button>
</div>
{/if} {/if}
{#if isPrivateMessage(item)} </div>
{#if replying}
<div class="mt-2 flex flex-col gap-2">
<MarkdownEditor placeholder="Message" bind:value={reply} rows={4} />
<div class="ml-auto w-24">
<Button
disabled={loading}
{loading}
on:click={() => replyToMessage(item)}
color="primary"
size="sm"
>
Submit
</Button>
</div>
</div>
{/if}
{/if}
{/if}
</Material> </Material>
+17 -5
View File
@@ -1,6 +1,11 @@
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
import { getClient } from '$lib/lemmy.js' import { getClient } from '$lib/lemmy.js'
import { getItemPublished } from '$lib/lemmy/item.js' import {
generalizeCommentReport,
generalizePostReport,
generalizePrivateMessageReport,
} from '$lib/lemmy/report.js'
import { get } from 'svelte/store' import { get } from 'svelte/store'
type ReportListType = 'unread' | 'all' type ReportListType = 'unread' | 'all'
@@ -33,18 +38,25 @@ export async function load({ url, fetch }) {
unresolved_only: type == 'unread', unresolved_only: type == 'unread',
} }
const [posts, comments] = await Promise.all([ const admin = get(profile)?.user ? isAdmin(get(profile)!.user!) : false
const [posts, comments, messages] = await Promise.all([
client.listPostReports({ client.listPostReports({
...params, ...params,
}), }),
client.listCommentReports({ client.listCommentReports({
...params, ...params,
}), }),
admin ? client.listPrivateMessageReports({ ...params }) : undefined,
]) ])
const everything = [...posts.post_reports, ...comments.comment_reports].sort( const everything = [
(a, b) => Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a)) ...posts.post_reports.map(generalizePostReport),
) ...comments.comment_reports.map(generalizeCommentReport),
...(messages?.private_message_reports ?? []).map(
generalizePrivateMessageReport
),
].sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime())
return { return {
type: type, type: type,
+87 -89
View File
@@ -12,14 +12,10 @@
import { Check, Icon } from 'svelte-hero-icons' import { Check, Icon } from 'svelte-hero-icons'
import { profile } from '$lib/auth.js' import { profile } from '$lib/auth.js'
import { Button } from 'mono-svelte' import { Button } from 'mono-svelte'
import type { ReportView } from '$lib/lemmy/report.js'
import PrivateMessage from '$lib/components/lemmy/inbox/PrivateMessage.svelte'
export let item: PostReportView | CommentReportView | PrivateMessageReportView export let item: ReportView
$: resolved = isCommentReport(item)
? item.comment_report.resolved
: isPostReport(item)
? item.post_report.resolved
: false
let resolving = false let resolving = false
async function resolve() { async function resolve() {
@@ -27,31 +23,60 @@
resolving = true resolving = true
try { try {
if (isCommentReport(item)) { switch (item.type) {
await getClient().resolveCommentReport({ case 'comment': {
auth: $profile.jwt, const res = await getClient().resolveCommentReport({
report_id: item.comment_report.id, auth: $profile.jwt,
resolved: !resolved, report_id: item.id,
}) resolved: !item.resolved,
})
resolved = !resolved item.resolved = res.comment_report_view.comment_report.resolved
toast({ toast({
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`, content: `${
type: 'success', item.resolved ? 'Resolved' : 'Unresolved'
}) } that report.`,
} else if (isPostReport(item)) { type: 'success',
await getClient().resolvePostReport({ })
auth: $profile.jwt,
report_id: item.post_report.id,
resolved: !resolved,
})
resolved = !resolved break
toast({ }
content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`, case 'post': {
type: 'success', const res = await getClient().resolvePostReport({
}) auth: $profile.jwt,
report_id: item.id,
resolved: !item.resolved,
})
item.resolved = res.post_report_view.post_report.resolved
toast({
content: `${
item.resolved ? 'Resolved' : 'Unresolved'
} that report.`,
type: 'success',
})
break
}
case 'message': {
const res = await getClient().resolvePrivateMessageReport({
auth: $profile.jwt,
report_id: item.id,
resolved: !item.resolved,
})
item.resolved =
res.private_message_report_view.private_message_report.resolved
toast({
content: `${
item.resolved ? 'Resolved' : 'Unresolved'
} that report.`,
type: 'success',
})
break
}
} }
const reports = await getClient().getReportCount({ const reports = await getClient().getReportCount({
@@ -73,66 +98,39 @@
} }
</script> </script>
{#if isCommentReport(item)} {#if item.type == 'comment'}
<CommentItem <CommentItem comment={item.item} />
comment={{ {:else if item.type == 'post'}
...item, <Post post={item.item} />
subscribed: 'NotSubscribed', {:else if item.type == 'message'}
creator_blocked: false, <PrivateMessage
saved: false, message={{
creator: item.comment_creator, creator: item.reportee,
private_message: item.item,
recipient: item.creator,
}} }}
/> />
<div class="flex flex-row gap-4 items-center">
<div>
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
Reason
</span>
<p>
{item.comment_report.reason}
</p>
</div>
<Button
on:click={resolve}
class="w-8 h-8 !p-1 ml-auto {resolved ? '!text-green-500' : ''}"
aria-label="Resolve"
title="Resolve"
loading={resolving}
disabled={resolving}
>
<Icon src={Check} mini size="16" slot="prefix" />
</Button>
</div>
{:else if isPostReport(item)}
<Post
post={{
...item,
saved: false,
subscribed: 'NotSubscribed',
unread_comments: 0,
read: false,
creator_blocked: false,
creator: item.post_creator,
}}
/>
<div class="flex flex-row gap-4 items-center">
<div>
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
Reason
</span>
<p>
{item.post_report.reason}
</p>
</div>
<Button
on:click={resolve}
class="w-8 h-8 !p-1 ml-auto {resolved ? '!text-green-500' : ''}"
aria-label="Resolve"
title="Resolve"
loading={resolving}
disabled={resolving}
>
<Icon src={Check} mini size="16" slot="prefix" />
</Button>
</div>
{/if} {/if}
<div class="flex flex-row gap-4 items-center">
<div>
<span class="text-xs font-bold dark:text-zinc-400 text-slate-600">
Reason
</span>
<p>
{item.reason}
</p>
</div>
<Button
on:click={resolve}
class="w-8 h-8 !p-1 ml-auto {item.resolved
? '!text-green-600 dark:!text-green-400'
: ''}"
aria-label="Resolve"
title="Resolve"
loading={resolving}
disabled={resolving}
>
<Icon src={Check} mini size="16" slot="prefix" />
</Button>
</div>
+5 -53
View File
@@ -35,6 +35,7 @@
import { Button, Modal, Select } from 'mono-svelte' import { Button, Modal, Select } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte' import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { publishedToDate } from '$lib/components/util/date.js' import { publishedToDate } from '$lib/components/util/date.js'
import PrivateMessageModal from '$lib/components/lemmy/modal/PrivateMessageModal.svelte'
export let data export let data
@@ -77,37 +78,7 @@
blocking = false blocking = false
} }
let loadingMessage = false
let messaging = false let messaging = false
let message = ''
async function sendMessage() {
if (!$profile?.jwt || message == '') return
loadingMessage = true
try {
await getClient().createPrivateMessage({
auth: $profile.jwt,
content: message,
recipient_id: data.person_view.person.id,
})
toast({
content: 'Successfully sent that person a message.',
type: 'success',
})
messaging = false
} catch (err) {
toast({
content: err as any,
type: 'error',
})
}
loadingMessage = false
}
</script> </script>
<svelte:head> <svelte:head>
@@ -115,29 +86,10 @@
</svelte:head> </svelte:head>
{#if $profile?.user} {#if $profile?.user}
<Modal bind:open={messaging}> <PrivateMessageModal
<h1 class="text-2xl font-bold" slot="title">Message</h1> bind:user={data.person_view.person}
<form on:submit|preventDefault={sendMessage} class="flex flex-col gap-4"> bind:open={messaging}
<p class="inline-flex flex-row gap-2 items-center"> />
Sending <UserLink avatar user={data.person_view.person} /> a message
</p>
<MarkdownEditor
bind:value={message}
label="Message"
placeholder="your hair looks nice today"
rows={4}
/>
<Button
color="primary"
size="lg"
submit
loading={loadingMessage}
disabled={loadingMessage}
>
Send
</Button>
</form>
</Modal>
{/if} {/if}
<div class="flex flex-col-reverse xl:flex-row gap-4 max-w-full w-full"> <div class="flex flex-col-reverse xl:flex-row gap-4 max-w-full w-full">