From 5cfc98188c8e47fdd07554f3bd61980a6f79ea74 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 17:23:01 -0700 Subject: [PATCH 01/13] misc: add modlog buttons --- src/lib/components/lemmy/SiteCard.svelte | 6 +++++ src/routes/moderation/+page.svelte | 28 +++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/lib/components/lemmy/SiteCard.svelte b/src/lib/components/lemmy/SiteCard.svelte index 96a54b01..52995f41 100644 --- a/src/lib/components/lemmy/SiteCard.svelte +++ b/src/lib/components/lemmy/SiteCard.svelte @@ -54,6 +54,12 @@ +
+ +
{#if taglines && taglines.length > 0}

Reports

- { - $page.url.searchParams.delete('page') - $page.url.searchParams.set('type', e.detail) - goto($page.url.toString(), { - invalidateAll: true, - }) - }} - /> +
+ searchParam($page.url, 'type', e.detail, 'page')} + /> + +
{#if data.items && data.items.length > 0}
From 281ef04c43eaa76ef55372d9f7fc2d3728bc3219 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 18:01:03 -0700 Subject: [PATCH 02/13] feat: add basic moderation actions --- src/routes/comment/[id]/+page.ts | 16 +++++ src/routes/modlog/+page.svelte | 16 +++++ src/routes/modlog/+page.ts | 98 +++++++++++++++++++++++++++++ src/routes/modlog/ModlogItem.svelte | 31 +++++++++ 4 files changed, 161 insertions(+) create mode 100644 src/routes/comment/[id]/+page.ts create mode 100644 src/routes/modlog/ModlogItem.svelte diff --git a/src/routes/comment/[id]/+page.ts b/src/routes/comment/[id]/+page.ts new file mode 100644 index 00000000..1581aa15 --- /dev/null +++ b/src/routes/comment/[id]/+page.ts @@ -0,0 +1,16 @@ +import { profile } from '$lib/auth.js' +import { getClient } from '$lib/lemmy.js' +import { redirect } from '@sveltejs/kit' +import { get } from 'svelte/store' + +export async function load({ params, fetch }) { + const comment = await getClient(undefined, fetch).getComment({ + id: Number(params.id), + auth: get(profile)?.jwt, + }) + + throw redirect( + 300, + `/post/${comment.comment_view.post.id}?thread=${comment.comment_view.comment.path}#${comment.comment_view.comment.id}` + ) +} diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index e69de29b..c2f1947a 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -0,0 +1,16 @@ + + +
+

Modlog

+ {#if data.modlog} +
    + {#each data.modlog as modlog} + + {/each} +
+ {/if} +
diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index e69de29b..0f782da2 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -0,0 +1,98 @@ +import { profile } from '$lib/auth.js' +import { getClient } from '$lib/lemmy.js' +import type { + Community, + ModBanFromCommunityView, + ModRemoveCommentView, + ModRemovePostView, + Person, +} from 'lemmy-js-client' +import { get } from 'svelte/store' + +type ModAction = + | ModBanFromCommunityView + | ModRemoveCommentView + | ModRemovePostView + +export interface ModLog { + reason?: string + moderatee?: Person + content?: string + moderator?: Person + community?: Community + actionName: string + timestamp: number + link?: string +} + +const fullUserName = (user: Person) => + `${user.name}@${new URL(user.actor_id).hostname}` + +export const _toModLog = (item: ModAction): ModLog => { + if ('mod_ban_from_community' in item) { + return { + moderator: item.moderator, + moderatee: item.banned_person, + community: item.community, + actionName: 'Ban', + reason: item.mod_ban_from_community.reason, + timestamp: Date.parse(`${item.mod_ban_from_community.when_}Z`), + } + } else if ('mod_remove_comment' in item) { + return { + actionName: 'Comment Removal', + community: item.community, + content: item.comment.content, + timestamp: Date.parse(`${item.mod_remove_comment.when_}Z`), + moderatee: item.commenter, + moderator: item.moderator, + reason: item.mod_remove_comment.reason, + link: `/comment/${item.comment.id}`, + } + } else if ('mod_remove_post' in item) { + return { + actionName: 'Post Removal', + community: item.community, + content: item.post.name, + timestamp: Date.parse(`${item.mod_remove_post.when_}Z`), + moderator: item.moderator, + reason: item.mod_remove_post.reason, + } + } + + return { + actionName: 'Unknown', + timestamp: 0, + } +} + +export async function load({ url }) { + if (!get(profile)) return + const { jwt } = get(profile)! + if (!jwt) return + + let community = Number(url.searchParams.get('community')) || undefined + let modId = Number(url.searchParams.get('mod_id')) || undefined + const page = Number(url.searchParams.get('page')) || 1 + + const results = await getClient().getModlog({ + auth: jwt, + community_id: community, + limit: 40, + type_: 'All', + page: page, + mod_person_id: modId, + }) + + const moderation = [ + ...results.banned_from_community, + ...results.removed_comments, + ...results.removed_posts, + ] + + const moderationActions = moderation.map(_toModLog) + + return { + modlog: moderationActions, + } +} diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte new file mode 100644 index 00000000..a3af95bc --- /dev/null +++ b/src/routes/modlog/ModlogItem.svelte @@ -0,0 +1,31 @@ + + + + Action + {item.actionName} + {#if item.moderator} + Moderator + + {/if} + {#if item.moderatee} + Moderatee + + {/if} + {#if item.community} + Community + + {/if} + {#if item.link} + Link + + {/if} + From 114856a052608ee910ea58fdb834704de828eb74 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 18:22:39 -0700 Subject: [PATCH 03/13] feat: switch to table --- .../lemmy/comment/CommentActions.svelte | 4 +- src/routes/comment/[instance]/+page.ts | 6 +++ .../comment/{ => [instance]}/[id]/+page.ts | 0 src/routes/modlog/+page.svelte | 38 +++++++++++++++- src/routes/modlog/+page.ts | 5 ++- src/routes/modlog/ModlogItem.svelte | 45 ++++++++++--------- 6 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 src/routes/comment/[instance]/+page.ts rename src/routes/comment/{ => [instance]}/[id]/+page.ts (100%) diff --git a/src/lib/components/lemmy/comment/CommentActions.svelte b/src/lib/components/lemmy/comment/CommentActions.svelte index 6dbd976c..a380fe84 100644 --- a/src/lib/components/lemmy/comment/CommentActions.svelte +++ b/src/lib/components/lemmy/comment/CommentActions.svelte @@ -72,9 +72,7 @@ { navigator.clipboard.writeText( - `${$page.url.origin}/post/${getInstance()}/${ - comment.post.id - }?thread=${comment.comment.path}#${comment.comment.id}` + `/comment/${getInstance()}/${comment.comment.id}` ) }} > diff --git a/src/routes/comment/[instance]/+page.ts b/src/routes/comment/[instance]/+page.ts new file mode 100644 index 00000000..7cec2e91 --- /dev/null +++ b/src/routes/comment/[instance]/+page.ts @@ -0,0 +1,6 @@ +import { getInstance } from '$lib/lemmy.js' +import { redirect } from '@sveltejs/kit' + +export function load({ params }) { + throw redirect(300, `/comment/${getInstance()}/${params.instance}`) +} diff --git a/src/routes/comment/[id]/+page.ts b/src/routes/comment/[instance]/[id]/+page.ts similarity index 100% rename from src/routes/comment/[id]/+page.ts rename to src/routes/comment/[instance]/[id]/+page.ts diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index c2f1947a..62114617 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -7,10 +7,44 @@

Modlog

{#if data.modlog} -
    + + + + + + + + + + + + + + + + + {#each data.modlog as modlog} {/each} - +
    ActionModeratorModerateeCommunityLink
    {/if}
+ + diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 0f782da2..d5449ac3 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -57,6 +57,7 @@ export const _toModLog = (item: ModAction): ModLog => { timestamp: Date.parse(`${item.mod_remove_post.when_}Z`), moderator: item.moderator, reason: item.mod_remove_post.reason, + link: `/post/${item.post.id}`, } } @@ -90,7 +91,9 @@ export async function load({ url }) { ...results.removed_posts, ] - const moderationActions = moderation.map(_toModLog) + const moderationActions = moderation + .map(_toModLog) + .sort((b, a) => b.timestamp - a.timestamp) return { modlog: moderationActions, diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte index a3af95bc..381b7601 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/ModlogItem.svelte @@ -9,23 +9,28 @@ export let item: ModLog - - Action - {item.actionName} - {#if item.moderator} - Moderator - - {/if} - {#if item.moderatee} - Moderatee - - {/if} - {#if item.community} - Community - - {/if} - {#if item.link} - Link - - {/if} - + + + {item.actionName} + + + {#if item.moderator} + + {/if} + + + {#if item.moderatee} + + {/if} + + + {#if item.community} + + {/if} + + + {#if item.link} + + {/if} + + From 12b13293643a92a453fe736e203359a31f7c1c8f Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 18:56:17 -0700 Subject: [PATCH 04/13] feat: add sticky table header --- src/routes/modlog/+page.svelte | 72 ++++++++++++++++++++--------- src/routes/modlog/+page.ts | 11 +++-- src/routes/modlog/ModlogItem.svelte | 49 ++++++++++++++++++-- 3 files changed, 99 insertions(+), 33 deletions(-) diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 62114617..51a4fe56 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -1,39 +1,65 @@ + + Modlog + +

Modlog

{#if data.modlog} - - - - - - - - - - - - - - - - - - {#each data.modlog as modlog} - - {/each} -
ActionModeratorModerateeCommunityLink
+
+ + + + + + + + + + + + + + + + + + + + + + + + + {#each data.modlog as modlog} + + {/each} + +
TimeModeratorActionUserCommunityContentReasonLink
+
{/if} + searchParam($page.url, 'page', e.detail.toString())} + />
diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index d5449ac3..4f7c74ff 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -34,13 +34,13 @@ export const _toModLog = (item: ModAction): ModLog => { moderator: item.moderator, moderatee: item.banned_person, community: item.community, - actionName: 'Ban', + actionName: 'ban', reason: item.mod_ban_from_community.reason, timestamp: Date.parse(`${item.mod_ban_from_community.when_}Z`), } } else if ('mod_remove_comment' in item) { return { - actionName: 'Comment Removal', + actionName: 'commentRemoval', community: item.community, content: item.comment.content, timestamp: Date.parse(`${item.mod_remove_comment.when_}Z`), @@ -51,7 +51,7 @@ export const _toModLog = (item: ModAction): ModLog => { } } else if ('mod_remove_post' in item) { return { - actionName: 'Post Removal', + actionName: 'postRemoval', community: item.community, content: item.post.name, timestamp: Date.parse(`${item.mod_remove_post.when_}Z`), @@ -68,9 +68,9 @@ export const _toModLog = (item: ModAction): ModLog => { } export async function load({ url }) { - if (!get(profile)) return + if (!get(profile)) return { page: 1 } const { jwt } = get(profile)! - if (!jwt) return + if (!jwt) return { page: 1 } let community = Number(url.searchParams.get('community')) || undefined let modId = Number(url.searchParams.get('mod_id')) || undefined @@ -96,6 +96,7 @@ export async function load({ url }) { .sort((b, a) => b.timestamp - a.timestamp) return { + page: page, modlog: moderationActions, } } diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte index 381b7601..6523724e 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/ModlogItem.svelte @@ -4,28 +4,67 @@ import UserLink from '$lib/components/lemmy/user/UserLink.svelte' import Card from '$lib/components/ui/Card.svelte' import SectionTitle from '$lib/components/ui/SectionTitle.svelte' + import RelativeDate from '$lib/components/util/RelativeDate.svelte' + import { Icon, Trash, XCircle } from 'svelte-hero-icons' import type { ModLog } from './+page.js' export let item: ModLog - + - {item.actionName} + + + {#if item.moderator} - + {/if} + + + {#if item.actionName == 'ban'} + + Ban + + {:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'} + + Removal + + {:else} + {item.actionName} + {/if} + + {#if item.moderatee} - + {/if} {#if item.community} - + + {/if} + + + {#if item.content} +

{item.content}

+ {/if} + + + {#if item.reason} +

{item.reason}

{/if} From a938f70a4e4e503746142947139d22c62bc5301b Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 18:57:19 -0700 Subject: [PATCH 05/13] fix: reversed sort --- src/routes/modlog/+page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 4f7c74ff..20b32585 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -93,7 +93,7 @@ export async function load({ url }) { const moderationActions = moderation .map(_toModLog) - .sort((b, a) => b.timestamp - a.timestamp) + .sort((a, b) => b.timestamp - a.timestamp) return { page: page, From 08c4124c5e44695a5ad6a6ed2519baafdd3548a9 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 19:01:11 -0700 Subject: [PATCH 06/13] misc: improve responsiveness --- src/routes/modlog/+page.svelte | 8 ++++---- src/routes/modlog/ModlogItem.svelte | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 51a4fe56..7ae9aa41 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -16,10 +16,10 @@

Modlog

{#if data.modlog} -
+
@@ -31,8 +31,8 @@ - - + + diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte index 6523724e..e5372650 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/ModlogItem.svelte @@ -31,11 +31,11 @@ {#if item.actionName == 'ban'} - Ban + Ban {:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'} - Removal + Removal {:else} {item.actionName} From 25c5dee2244be02cc3479ebc9fdfe784a67e3da4 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 19:04:58 -0700 Subject: [PATCH 07/13] fix: remove auth requirement --- src/routes/modlog/+page.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 20b32585..5ddacacf 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -68,16 +68,12 @@ export const _toModLog = (item: ModAction): ModLog => { } export async function load({ url }) { - if (!get(profile)) return { page: 1 } - const { jwt } = get(profile)! - if (!jwt) return { page: 1 } - let community = Number(url.searchParams.get('community')) || undefined let modId = Number(url.searchParams.get('mod_id')) || undefined const page = Number(url.searchParams.get('page')) || 1 const results = await getClient().getModlog({ - auth: jwt, + auth: get(profile)?.jwt, community_id: community, limit: 40, type_: 'All', From 693f2f9a083e49056ceecb164bda1ca5092788ae Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Tue, 22 Aug 2023 20:32:29 -0700 Subject: [PATCH 08/13] fix: tweak widths --- src/routes/modlog/+page.svelte | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 7ae9aa41..0d967633 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -22,14 +22,14 @@ style="min-width: 800px;" > + + + + + + + - - - - - - - @@ -43,7 +43,7 @@ - + {#each data.modlog as modlog} {/each} From 5507cf8254948e9620a609559fcfa7c96bcf1775 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 17:10:41 -0700 Subject: [PATCH 09/13] feat: add community filters --- src/lib/components/input/SearchInput.svelte | 21 +++--- .../lemmy/ObjectAutocomplete.svelte | 37 +++++++--- src/routes/modlog/+page.svelte | 37 ++++++++++ src/routes/modlog/+page.ts | 30 +++++++- src/routes/modlog/ModlogAction.svelte | 71 +++++++++++++++++++ src/routes/modlog/ModlogItem.svelte | 15 +--- 6 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 src/routes/modlog/ModlogAction.svelte diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index 4b1dea24..b1cbe3e7 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -12,6 +12,7 @@ export let options: T[] export let extractSelected: (item: T | null) => any export let extractName: (item: T) => string + export let showWhenEmpty: boolean = false const debounce = (fn: Function, ms = 300) => { let timeoutId: ReturnType @@ -37,13 +38,17 @@ }} {...$$restProps} /> - - {#each options as option} - - extractSelected(option)}> - {extractName(option)} - - - {/each} + + {#if query == ''} + + {:else} + {#each options as option} + + extractSelected(option)}> + {extractName(option)} + + + {/each} + {/if} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte index 4d73977f..1b193017 100644 --- a/src/lib/components/lemmy/ObjectAutocomplete.svelte +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -5,6 +5,7 @@ import { getClient } from '$lib/lemmy.js' import type { Community, ListingType } from 'lemmy-js-client' import { createEventDispatcher } from 'svelte' + import { Icon, XCircle } from 'svelte-hero-icons' let type: 'community' = 'community' export let q: string = '' @@ -12,6 +13,7 @@ export let jwt: string | undefined = undefined export let listing_type: ListingType = 'Subscribed' export let items: Community[] | undefined = undefined + let showNone: boolean = false const dispatcher = createEventDispatcher<{ select: Community }>() @@ -20,8 +22,11 @@ { + if (q == '') showNone = true + else showNone = false + const results = await getClient().search({ - q: q, + q: q || ' ', auth: jwt, type_: 'Communities', limit: 20, @@ -40,15 +45,27 @@ let:extractName let:extractSelected let:option + showWhenEmpty + {...$$restProps} + let:query > - extractSelected(option)}> - -
- {option.title} - - {new URL(option.actor_id).hostname} - -
-
+ {#if query == ''} + dispatcher('select', undefined)}> + +
+ None +
+
+ {:else if option} + extractSelected(option)}> + +
+ {option.title} + + {new URL(option.actor_id).hostname} + +
+
+ {/if}
{/if} diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 0d967633..7af93e99 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -5,6 +5,9 @@ import Pageination from '$lib/components/ui/Pageination.svelte' import { searchParam } from '$lib/util.js' import { page } from '$app/stores' + import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte' + import { profile } from '$lib/auth.js' + import MultiSelect from '$lib/components/input/MultiSelect.svelte' export let data @@ -15,6 +18,40 @@

Modlog

+
+ searchParam($page.url, 'type', e.detail, 'page')} + /> +
+
Community
+ + searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} + /> +
+
{#if data.modlog}
Time Moderator Action
Link
{ reason: item.mod_remove_post.reason, link: `/post/${item.post.id}`, } + } else if ('mod_add_community' in item) { + return { + actionName: item.mod_add_community.removed ? 'modRemove' : 'modAdd', + community: item.community, + timestamp: Date.parse(`${item.mod_add_community.when_}Z`), + moderator: item.moderator, + moderatee: item.modded_person, + } } return { @@ -71,12 +93,14 @@ export async function load({ url }) { let community = Number(url.searchParams.get('community')) || undefined let modId = Number(url.searchParams.get('mod_id')) || undefined const page = Number(url.searchParams.get('page')) || 1 + let type: ModlogActionType = + (url.searchParams.get('type') as ModlogActionType) || 'All' const results = await getClient().getModlog({ auth: get(profile)?.jwt, community_id: community, limit: 40, - type_: 'All', + type_: type, page: page, mod_person_id: modId, }) @@ -85,6 +109,7 @@ export async function load({ url }) { ...results.banned_from_community, ...results.removed_comments, ...results.removed_posts, + ...results.added_to_community, ] const moderationActions = moderation @@ -93,6 +118,7 @@ export async function load({ url }) { return { page: page, + type: type, modlog: moderationActions, } } diff --git a/src/routes/modlog/ModlogAction.svelte b/src/routes/modlog/ModlogAction.svelte new file mode 100644 index 00000000..d138f821 --- /dev/null +++ b/src/routes/modlog/ModlogAction.svelte @@ -0,0 +1,71 @@ + + + + + + {actionData.text} + + diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/ModlogItem.svelte index e5372650..539e31af 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/ModlogItem.svelte @@ -7,6 +7,7 @@ import RelativeDate from '$lib/components/util/RelativeDate.svelte' import { Icon, Trash, XCircle } from 'svelte-hero-icons' import type { ModLog } from './+page.js' + import ModlogAction from './ModlogAction.svelte' export let item: ModLog @@ -28,19 +29,7 @@ {/if} - + diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 4e1dac34..12754d7d 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -4,8 +4,11 @@ import type { Community, ModAddCommunityView, ModBanFromCommunityView, + ModFeaturePostView, + ModLockPostView, ModRemoveCommentView, ModRemovePostView, + ModTransferCommunityView, ModlogActionType, ModlogListParams, Person, @@ -17,6 +20,8 @@ export type ActionName = | 'postRemoval' | 'commentRemoval' | 'postLock' + | 'postUnlock' + | 'postUnfeature' | 'postFeature' | 'modAdd' | 'modRemove' @@ -27,6 +32,9 @@ type ModAction = | ModRemoveCommentView | ModRemovePostView | ModAddCommunityView + | ModLockPostView + | ModFeaturePostView + | ModTransferCommunityView export interface ModLog { reason?: string @@ -81,8 +89,27 @@ export const _toModLog = (item: ModAction): ModLog => { moderator: item.moderator, moderatee: item.modded_person, } + } else if ('mod_feature_post' in item) { + return { + actionName: item.mod_feature_post.featured + ? 'postFeature' + : 'postUnfeature', + timestamp: Date.parse(`${item.mod_feature_post.when_}Z`), + community: item.community, + link: `/post/${item.post.id}`, + moderator: item.moderator, + content: item.post.name, + } + } else if ('mod_lock_post' in item) { + return { + actionName: item.mod_lock_post.locked ? 'postLock' : 'postUnlock', + timestamp: Date.parse(`${item.mod_lock_post.when_}Z`), + community: item.community, + link: `/post/${item.post.id}`, + moderator: item.moderator, + content: item.post.name, + } } - return { actionName: 'Unknown', timestamp: 0, @@ -109,7 +136,12 @@ export async function load({ url }) { ...results.banned_from_community, ...results.removed_comments, ...results.removed_posts, + ...results.added_to_community, + ...results.transferred_to_community, + + ...results.featured_posts, + ...results.locked_posts, ] const moderationActions = moderation diff --git a/src/routes/modlog/ModlogAction.svelte b/src/routes/modlog/ModlogAction.svelte index d138f821..a85868f4 100644 --- a/src/routes/modlog/ModlogAction.svelte +++ b/src/routes/modlog/ModlogAction.svelte @@ -2,6 +2,9 @@ import type { IconSource } from 'svelte-hero-icons' import { Icon, + InformationCircle, + LockClosed, + LockOpen, QuestionMarkCircle, Trash, UserMinus, @@ -53,6 +56,34 @@ text: 'Removed Mod', } } + case 'postFeature': { + return { + icon: InformationCircle, + class: 'text-green-600 dark:text-green-400', + text: 'Featured Post', + } + } + case 'postUnfeature': { + return { + icon: InformationCircle, + class: 'text-red-600 dark:text-red-400', + text: 'Unfeatured Post', + } + } + case 'postLock': { + return { + icon: LockClosed, + class: 'text-yellow-600 dark:text-yellow-400', + text: 'Locked Post', + } + } + case 'postUnlock': { + return { + icon: LockOpen, + class: 'text-yellow-600 dark:text-yellow-400', + text: 'Unlocked Post', + } + } } return { From 861fb4949a3770a4cb943e76bd4a062f57e2b751 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 18:15:04 -0700 Subject: [PATCH 11/13] feat: add card view --- src/lib/settings.ts | 2 + src/routes/modlog/+page.svelte | 89 +++++++++++-------- src/routes/modlog/item/ModlogItemCard.svelte | 55 ++++++++++++ .../ModlogItemTable.svelte} | 7 +- 4 files changed, 111 insertions(+), 42 deletions(-) create mode 100644 src/routes/modlog/item/ModlogItemCard.svelte rename src/routes/modlog/{ModlogItem.svelte => item/ModlogItemTable.svelte} (81%) diff --git a/src/lib/settings.ts b/src/lib/settings.ts index d969608f..bb2b5ecc 100644 --- a/src/lib/settings.ts +++ b/src/lib/settings.ts @@ -49,6 +49,7 @@ interface Settings { } newVote: boolean randomPlaceholders: boolean + modlogCardView: boolean | undefined } export const defaultSettings: Settings = { @@ -85,6 +86,7 @@ export const defaultSettings: Settings = { }, newVote: toBool(env.PUBLIC_NEW_VOTE_BUTTONS) ?? false, randomPlaceholders: toBool(env.PUBLIC_RANDOM_PLACEHOLDERS) ?? true, + modlogCardView: toBool(env.PUBLIC_MODLOG_CARD_VIEW) ?? undefined, } export const userSettings = writable(defaultSettings) diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 3086e172..87e5954c 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -1,13 +1,13 @@ @@ -70,42 +70,57 @@ searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} /> + ($userSettings.modlogCardView = e.detail)} + /> {#if data.modlog} -
-
- - {#if item.actionName == 'ban'} - - Ban - - {:else if item.actionName == 'postRemoval' || item.actionName == 'commentRemoval'} - - Removal - - {:else} - {item.actionName} - {/if} - + {#if item.moderatee} From 22ce7bf39e525c33e009de4b46cf261db436370b Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 17:53:33 -0700 Subject: [PATCH 10/13] feat: add more moderator actions --- src/lib/components/input/SearchInput.svelte | 10 ++++-- src/lib/components/input/TextInput.svelte | 1 + .../lemmy/ObjectAutocomplete.svelte | 5 +-- src/routes/modlog/+page.svelte | 21 +++++++++++- src/routes/modlog/+page.ts | 34 ++++++++++++++++++- src/routes/modlog/ModlogAction.svelte | 31 +++++++++++++++++ 6 files changed, 96 insertions(+), 6 deletions(-) diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index b1cbe3e7..13df9129 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -13,6 +13,8 @@ export let extractSelected: (item: T | null) => any export let extractName: (item: T) => string export let showWhenEmpty: boolean = false + let canSearch: boolean = false + export { canSearch as searchOnMount } const debounce = (fn: Function, ms = 300) => { let timeoutId: ReturnType @@ -25,6 +27,7 @@ const dispatcher = createEventDispatcher<{ search: string }>() const debounceFunc = debounce(() => { + canSearch = true dispatcher('search', query) }, debounceTime) @@ -38,8 +41,11 @@ }} {...$$restProps} /> - - {#if query == ''} + + {#if query == '' && showWhenEmpty} {:else} {#each options as option} diff --git a/src/lib/components/input/TextInput.svelte b/src/lib/components/input/TextInput.svelte index 9c69bc5a..af7df2ed 100644 --- a/src/lib/components/input/TextInput.svelte +++ b/src/lib/components/input/TextInput.svelte @@ -40,6 +40,7 @@ on:keydown={(e) => dispatcher('keydown', e)} on:input={(e) => dispatcher('input', e)} on:change={(e) => dispatcher('change', e)} + on:focus {...$$restProps} class={className} {required} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte index 1b193017..66a6307f 100644 --- a/src/lib/components/lemmy/ObjectAutocomplete.svelte +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -13,6 +13,7 @@ export let jwt: string | undefined = undefined export let listing_type: ListingType = 'Subscribed' export let items: Community[] | undefined = undefined + export let showWhenEmpty: boolean = false let showNone: boolean = false const dispatcher = createEventDispatcher<{ select: Community }>() @@ -45,11 +46,11 @@ let:extractName let:extractSelected let:option - showWhenEmpty + {showWhenEmpty} {...$$restProps} let:query > - {#if query == ''} + {#if query == '' && showWhenEmpty} dispatcher('select', undefined)}>
diff --git a/src/routes/modlog/+page.svelte b/src/routes/modlog/+page.svelte index 7af93e99..3086e172 100644 --- a/src/routes/modlog/+page.svelte +++ b/src/routes/modlog/+page.svelte @@ -38,6 +38,24 @@ 'AdminPurgePost', 'AdminPurgeComment', ]} + optionNames={[ + 'All', + 'Remove Post', + 'Lock Post', + 'Feature Post', + 'Remove Comment', + 'Remove Community', + 'Ban From Community', + 'Add Community', + 'Transfer Community', + 'Add', + 'Ban', + 'Hide Community', + 'Purge Person', + 'Purge Community', + 'Purge Post', + 'Purge Comment', + ]} selected={data.type} on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')} /> @@ -47,6 +65,7 @@ placeholder="Filter by community" jwt={$profile?.jwt} listing_type="All" + showWhenEmpty={true} on:select={(e) => searchParam($page.url, 'community', e.detail?.id.toString(), 'page')} /> @@ -61,7 +80,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - {#each data.modlog as modlog} - - {/each} - -
TimeModeratorActionUserCommunityContentReasonLink
-
+ {#if $userSettings.modlogCardView ?? !window.matchMedia('(min-width: 1600px)').matches} +
+ {#each data.modlog as modlog} + + {/each} +
+ {:else} +
+ + + + + + + + + + + + + + + + + + + + + + + + + {#each data.modlog as modlog} + + {/each} + +
TimeModeratorActionUserCommunityContentReasonLink
+
+ {/if} {/if} + import Link from '$lib/components/input/Link.svelte' + import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte' + import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte' + import UserLink from '$lib/components/lemmy/user/UserLink.svelte' + import Card from '$lib/components/ui/Card.svelte' + import SectionTitle from '$lib/components/ui/SectionTitle.svelte' + import RelativeDate from '$lib/components/util/RelativeDate.svelte' + import type { ModLog } from '../+page.js' + import ModlogAction from '../ModlogAction.svelte' + + export let item: ModLog + + + +
+ {#if item.community} + + {/if} + + + +
+ {#if item.actionName} + Action + + + + {/if} + {#if item.moderator} + Moderator + + + + + {/if} + {#if item.moderatee} + User + + {/if} + {#if item.link || item.content} + Submission + {#if item.link && item.content} + + {item.content} + + {:else if item.content} +

{item.content}

+ {:else if item.link} + + {/if} + {/if} +
diff --git a/src/routes/modlog/ModlogItem.svelte b/src/routes/modlog/item/ModlogItemTable.svelte similarity index 81% rename from src/routes/modlog/ModlogItem.svelte rename to src/routes/modlog/item/ModlogItemTable.svelte index 539e31af..07122ae4 100644 --- a/src/routes/modlog/ModlogItem.svelte +++ b/src/routes/modlog/item/ModlogItemTable.svelte @@ -2,12 +2,9 @@ import Link from '$lib/components/input/Link.svelte' import CommunityLink from '$lib/components/lemmy/community/CommunityLink.svelte' import UserLink from '$lib/components/lemmy/user/UserLink.svelte' - import Card from '$lib/components/ui/Card.svelte' - import SectionTitle from '$lib/components/ui/SectionTitle.svelte' import RelativeDate from '$lib/components/util/RelativeDate.svelte' - import { Icon, Trash, XCircle } from 'svelte-hero-icons' - import type { ModLog } from './+page.js' - import ModlogAction from './ModlogAction.svelte' + import type { ModLog } from '../+page.js' + import ModlogAction from '../ModlogAction.svelte' export let item: ModLog From 01032a02187c127ecb0e22705f8abda715e51248 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 18:18:33 -0700 Subject: [PATCH 12/13] feat: all mod actions --- src/routes/modlog/+page.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 12754d7d..426caa08 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -49,6 +49,7 @@ export interface ModLog { const fullUserName = (user: Person) => `${user.name}@${new URL(user.actor_id).hostname}` +const timestamp = (when: string) => Date.parse(`${when}Z`) export const _toModLog = (item: ModAction): ModLog => { if ('mod_ban_from_community' in item) { @@ -58,14 +59,14 @@ export const _toModLog = (item: ModAction): ModLog => { community: item.community, actionName: 'ban', reason: item.mod_ban_from_community.reason, - timestamp: Date.parse(`${item.mod_ban_from_community.when_}Z`), + timestamp: timestamp(item.mod_ban_from_community.when_), } } else if ('mod_remove_comment' in item) { return { actionName: 'commentRemoval', community: item.community, content: item.comment.content, - timestamp: Date.parse(`${item.mod_remove_comment.when_}Z`), + timestamp: timestamp(item.mod_remove_comment.when_), moderatee: item.commenter, moderator: item.moderator, reason: item.mod_remove_comment.reason, @@ -76,7 +77,7 @@ export const _toModLog = (item: ModAction): ModLog => { actionName: 'postRemoval', community: item.community, content: item.post.name, - timestamp: Date.parse(`${item.mod_remove_post.when_}Z`), + timestamp: timestamp(item.mod_remove_post.when_), moderator: item.moderator, reason: item.mod_remove_post.reason, link: `/post/${item.post.id}`, @@ -85,7 +86,7 @@ export const _toModLog = (item: ModAction): ModLog => { return { actionName: item.mod_add_community.removed ? 'modRemove' : 'modAdd', community: item.community, - timestamp: Date.parse(`${item.mod_add_community.when_}Z`), + timestamp: timestamp(item.mod_add_community.when_), moderator: item.moderator, moderatee: item.modded_person, } @@ -94,7 +95,7 @@ export const _toModLog = (item: ModAction): ModLog => { actionName: item.mod_feature_post.featured ? 'postFeature' : 'postUnfeature', - timestamp: Date.parse(`${item.mod_feature_post.when_}Z`), + timestamp: timestamp(item.mod_feature_post.when_), community: item.community, link: `/post/${item.post.id}`, moderator: item.moderator, @@ -103,12 +104,20 @@ export const _toModLog = (item: ModAction): ModLog => { } else if ('mod_lock_post' in item) { return { actionName: item.mod_lock_post.locked ? 'postLock' : 'postUnlock', - timestamp: Date.parse(`${item.mod_lock_post.when_}Z`), + timestamp: timestamp(item.mod_lock_post.when_), community: item.community, link: `/post/${item.post.id}`, moderator: item.moderator, content: item.post.name, } + } else if ('mod_transfer_community' in item) { + return { + actionName: 'Unknown', + timestamp: timestamp(item.mod_transfer_community.when_), + moderator: item.moderator, + moderatee: item.modded_person, + community: item.community, + } } return { actionName: 'Unknown', From 57dbe5176a29a4df1dc7adbd36f1bb51532065e9 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 23 Aug 2023 18:39:22 -0700 Subject: [PATCH 13/13] feat: add all admin actions --- src/routes/modlog/+page.ts | 81 +++++++++++++++++++- src/routes/modlog/ModlogAction.svelte | 32 +++++++- src/routes/modlog/item/ModlogItemCard.svelte | 12 ++- 3 files changed, 120 insertions(+), 5 deletions(-) diff --git a/src/routes/modlog/+page.ts b/src/routes/modlog/+page.ts index 426caa08..1d6a5d89 100644 --- a/src/routes/modlog/+page.ts +++ b/src/routes/modlog/+page.ts @@ -1,10 +1,17 @@ import { profile } from '$lib/auth.js' import { getClient } from '$lib/lemmy.js' import type { + AdminPurgeCommentView, + AdminPurgeCommunityView, + AdminPurgePersonView, + AdminPurgePostView, Community, ModAddCommunityView, + ModAddView, ModBanFromCommunityView, + ModBanView, ModFeaturePostView, + ModHideCommunityView, ModLockPostView, ModRemoveCommentView, ModRemovePostView, @@ -17,6 +24,9 @@ import { get } from 'svelte/store' export type ActionName = | 'ban' + | 'banCommunity' + | 'unban' + | 'unbanCommunity' | 'postRemoval' | 'commentRemoval' | 'postLock' @@ -25,6 +35,7 @@ export type ActionName = | 'postFeature' | 'modAdd' | 'modRemove' + | 'purge' | 'Unknown' type ModAction = @@ -35,6 +46,13 @@ type ModAction = | ModLockPostView | ModFeaturePostView | ModTransferCommunityView + | AdminPurgeCommentView + | AdminPurgeCommunityView + | AdminPurgePostView + | AdminPurgePersonView + | ModHideCommunityView + | ModBanView + | ModAddView export interface ModLog { reason?: string @@ -57,7 +75,9 @@ export const _toModLog = (item: ModAction): ModLog => { moderator: item.moderator, moderatee: item.banned_person, community: item.community, - actionName: 'ban', + actionName: item.mod_ban_from_community.banned + ? 'banCommunity' + : 'unbanCommunity', reason: item.mod_ban_from_community.reason, timestamp: timestamp(item.mod_ban_from_community.when_), } @@ -118,7 +138,57 @@ export const _toModLog = (item: ModAction): ModLog => { moderatee: item.modded_person, community: item.community, } + } else if ('admin_purge_post' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_post.when_), + moderator: item.admin, + community: item.community, + content: 'Purged a post', + reason: item.admin_purge_post.reason, + } + } else if ('admin_purge_comment' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_comment.when_), + moderator: item.admin, + content: 'Purged a comment', + reason: item.admin_purge_comment.reason, + } + } else if ('admin_purge_community' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_community.when_), + moderator: item.admin, + content: 'Purged a community', + reason: item.admin_purge_community.reason, + } + } else if ('admin_purge_person' in item) { + return { + actionName: 'purge', + timestamp: timestamp(item.admin_purge_person.when_), + moderator: item.admin, + content: 'Purged a user', + reason: item.admin_purge_person.reason, + } + } else if ('mod_ban' in item) { + return { + actionName: item.mod_ban.banned ? 'ban' : 'unban', + timestamp: timestamp(item.mod_ban.when_), + moderator: item.moderator, + moderatee: item.banned_person, + reason: item.mod_ban.reason, + link: `/u/${fullUserName(item.banned_person)}`, + } + } else if ('mod_add' in item) { + return { + actionName: item.mod_add.removed ? 'modRemove' : 'modAdd', + timestamp: timestamp(item.mod_add.when_), + moderator: item.moderator, + moderatee: item.modded_person, + } } + return { actionName: 'Unknown', timestamp: 0, @@ -151,6 +221,15 @@ export async function load({ url }) { ...results.featured_posts, ...results.locked_posts, + + ...results.admin_purged_comments, + ...results.admin_purged_communities, + ...results.admin_purged_posts, + ...results.admin_purged_persons, + + ...results.hidden_communities, + ...results.banned, + ...results.added, ] const moderationActions = moderation diff --git a/src/routes/modlog/ModlogAction.svelte b/src/routes/modlog/ModlogAction.svelte index a85868f4..37eb12d4 100644 --- a/src/routes/modlog/ModlogAction.svelte +++ b/src/routes/modlog/ModlogAction.svelte @@ -1,6 +1,8 @@