-
Reply
- {#if $profile?.user && item.post.creator_id != $profile.user.local_user_view.person.id}
-
-
+
+
+
+ {#if item.type != 'private_message'}
+
+ {/if}
+
+
+
+ {#if item.type == 'private_message'}
+ Message
+ {:else if item.type == 'person_mention'}
+ Mention
+ {:else if item.type == 'comment_reply'}
+ Reply
+ {/if}
+
+ {#if item.type != 'private_message' && $profile?.user && item.item.post.creator_id != $profile.user.local_user_view.person.id}
+
+ {/if}
+ {#if item.type == 'private_message'}
+
+ {:else}
-
-
-
+ {/if}
+
+
+
-
- {:else}
-
-
-
- {#if item.creator.id == $profile?.user?.local_user_view.person.id}
- You
- {:else}
-
- {/if}
-
- messaged
-
- {#if item.recipient.id == $profile?.user?.local_user_view.person.id}
- You
- {:else}
-
- {/if}
-
-
-
-
-
-
- {#if item.recipient.id == $profile?.user?.local_user_view.person.id}
-
- (replying = !replying)}>
-
- Reply
-
-
- {/if}
- {#if isPrivateMessage(item)}
- {#if replying}
-
-
-
- replyToMessage(item)}
- color="primary"
- size="sm"
- >
- Submit
-
-
-
- {/if}
{/if}
- {/if}
+
diff --git a/src/routes/moderation/+page.ts b/src/routes/moderation/+page.ts
index 81b41a90..cd371701 100644
--- a/src/routes/moderation/+page.ts
+++ b/src/routes/moderation/+page.ts
@@ -1,6 +1,11 @@
import { profile } from '$lib/auth.js'
+import { isAdmin } from '$lib/components/lemmy/moderation/moderation.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'
type ReportListType = 'unread' | 'all'
@@ -33,18 +38,25 @@ export async function load({ url, fetch }) {
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({
...params,
}),
client.listCommentReports({
...params,
}),
+ admin ? client.listPrivateMessageReports({ ...params }) : undefined,
])
- const everything = [...posts.post_reports, ...comments.comment_reports].sort(
- (a, b) => Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
- )
+ const everything = [
+ ...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 {
type: type,
diff --git a/src/routes/moderation/Report.svelte b/src/routes/moderation/Report.svelte
index 233213e2..ac3dde2f 100644
--- a/src/routes/moderation/Report.svelte
+++ b/src/routes/moderation/Report.svelte
@@ -12,14 +12,10 @@
import { Check, Icon } from 'svelte-hero-icons'
import { profile } from '$lib/auth.js'
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
-
- $: resolved = isCommentReport(item)
- ? item.comment_report.resolved
- : isPostReport(item)
- ? item.post_report.resolved
- : false
+ export let item: ReportView
let resolving = false
async function resolve() {
@@ -27,31 +23,60 @@
resolving = true
try {
- if (isCommentReport(item)) {
- await getClient().resolveCommentReport({
- auth: $profile.jwt,
- report_id: item.comment_report.id,
- resolved: !resolved,
- })
+ switch (item.type) {
+ case 'comment': {
+ const res = await getClient().resolveCommentReport({
+ auth: $profile.jwt,
+ report_id: item.id,
+ resolved: !item.resolved,
+ })
+
+ item.resolved = res.comment_report_view.comment_report.resolved
+
+ toast({
+ content: `${
+ item.resolved ? 'Resolved' : 'Unresolved'
+ } that report.`,
+ type: 'success',
+ })
- resolved = !resolved
+ break
+ }
+ case 'post': {
+ const res = await getClient().resolvePostReport({
+ auth: $profile.jwt,
+ report_id: item.id,
+ resolved: !item.resolved,
+ })
- toast({
- content: `${resolved ? 'Resolved' : 'Unresolved'} that report.`,
- type: 'success',
- })
- } else if (isPostReport(item)) {
- await getClient().resolvePostReport({
- auth: $profile.jwt,
- report_id: item.post_report.id,
- resolved: !resolved,
- })
+ item.resolved = res.post_report_view.post_report.resolved
+ toast({
+ content: `${
+ item.resolved ? 'Resolved' : 'Unresolved'
+ } that report.`,
+ type: 'success',
+ })
- resolved = !resolved
- toast({
- content: `${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({
@@ -73,66 +98,39 @@
}
-{#if isCommentReport(item)}
-
+{:else if item.type == 'post'}
+
+{:else if item.type == 'message'}
+
-
-
-
- Reason
-
-
- {item.comment_report.reason}
-
-
-
-
-
-
-{:else if isPostReport(item)}
-
-
-
-
- Reason
-
-
- {item.post_report.reason}
-
-
-
-
-
-
{/if}
+
+
+
+
+ Reason
+
+
+ {item.reason}
+
+
+
+
+
+
diff --git a/src/routes/u/[name]/+page.svelte b/src/routes/u/[name]/+page.svelte
index 28dc9579..3a83d818 100644
--- a/src/routes/u/[name]/+page.svelte
+++ b/src/routes/u/[name]/+page.svelte
@@ -35,6 +35,7 @@
import { Button, Modal, Select } from 'mono-svelte'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
import { publishedToDate } from '$lib/components/util/date.js'
+ import PrivateMessageModal from '$lib/components/lemmy/modal/PrivateMessageModal.svelte'
export let data
@@ -77,37 +78,7 @@
blocking = false
}
- let loadingMessage = 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
- }
@@ -115,29 +86,10 @@
{#if $profile?.user}
-
- Message
-
-
+
{/if}