66 files changed
+526
-228
No files matched your search
+1
-1
@@ -21,7 +21,7 @@
|
|||||||
"@vite-pwa/sveltekit": "^0.2.5",
|
"@vite-pwa/sveltekit": "^0.2.5",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.16",
|
||||||
"jsdom": "^22.1.0",
|
"jsdom": "^22.1.0",
|
||||||
"lemmy-js-client": "^0.18.1",
|
"lemmy-js-client": "^0.19.0-rc.13",
|
||||||
"markdown-it-container": "^3.0.0",
|
"markdown-it-container": "^3.0.0",
|
||||||
"markdown-it-sub": "^1.0.0",
|
"markdown-it-sub": "^1.0.0",
|
||||||
"markdown-it-sup": "^1.0.0",
|
"markdown-it-sup": "^1.0.0",
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
function buildUrl(inputUrl: URL): URL {
|
function buildUrl(inputUrl: URL): URL {
|
||||||
let withoutCors = inputUrl.pathname.replace('/cors/', '')
|
let withoutCors = inputUrl.pathname.replace('/cors/', '')
|
||||||
|
|
||||||
if (!withoutCors.startsWith('https://')) {
|
if (
|
||||||
|
!(withoutCors.startsWith('https://') || withoutCors.startsWith('http://'))
|
||||||
|
) {
|
||||||
withoutCors = 'https://' + withoutCors
|
withoutCors = 'https://' + withoutCors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+31
-14
@@ -1,15 +1,16 @@
|
|||||||
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
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 { client, getClient, site } from '$lib/lemmy.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { moveItem } from '$lib/util.js'
|
import { instanceToURL, moveItem } from '$lib/util.js'
|
||||||
import {
|
import {
|
||||||
LemmyHttp,
|
LemmyHttp,
|
||||||
type GetSiteResponse,
|
type GetSiteResponse,
|
||||||
type MyUserInfo,
|
type MyUserInfo,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
|
import { MINIMUM_VERSION, versionIsSupported } from '$lib/version.js'
|
||||||
|
|
||||||
const getDefaultProfile = (): Profile => ({
|
const getDefaultProfile = (): Profile => ({
|
||||||
id: -1,
|
id: -1,
|
||||||
@@ -87,7 +88,7 @@ profile.subscribe(async (p) => {
|
|||||||
instance.set(p.instance)
|
instance.set(p.instance)
|
||||||
// fetch the user because p.user is undefined
|
// fetch the user because p.user is undefined
|
||||||
const user = await userFromJwt(p.jwt, p.instance)
|
const user = await userFromJwt(p.jwt, p.instance)
|
||||||
|
.then((user) => {
|
||||||
if (!user?.user)
|
if (!user?.user)
|
||||||
toast({
|
toast({
|
||||||
content: 'Your login has expired. Re-login to fix this issue.',
|
content: 'Your login has expired. Re-login to fix this issue.',
|
||||||
@@ -95,6 +96,14 @@ profile.subscribe(async (p) => {
|
|||||||
})
|
})
|
||||||
site.set(user?.site)
|
site.set(user?.site)
|
||||||
|
|
||||||
|
return user
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast({ content: err as any, type: 'error' })
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!user?.user) return
|
||||||
|
|
||||||
profile.update(() => ({
|
profile.update(() => ({
|
||||||
...p,
|
...p,
|
||||||
user: user!.user,
|
user: user!.user,
|
||||||
@@ -105,13 +114,17 @@ profile.subscribe(async (p) => {
|
|||||||
|
|
||||||
export async function setUser(jwt: string, inst: string, username: string) {
|
export async function setUser(jwt: string, inst: string, username: string) {
|
||||||
try {
|
try {
|
||||||
new URL(`https://${inst}`)
|
new URL(instanceToURL(inst))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await userFromJwt(jwt, inst)
|
const user = await userFromJwt(jwt, inst)
|
||||||
if (!user) {
|
.then((u) => u)
|
||||||
|
.catch((err) => {
|
||||||
|
toast({ content: err as any, type: 'error' })
|
||||||
|
})
|
||||||
|
if (!user?.user) {
|
||||||
toast({
|
toast({
|
||||||
content: 'Failed to fetch your user. Is your instance down?',
|
content: 'Failed to fetch your user. Is your instance down?',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
@@ -152,9 +165,7 @@ async function userFromJwt(
|
|||||||
jwt: string,
|
jwt: string,
|
||||||
instance: string
|
instance: string
|
||||||
): Promise<{ user: PersonData; site: GetSiteResponse } | undefined> {
|
): Promise<{ user: PersonData; site: GetSiteResponse } | undefined> {
|
||||||
const sitePromise = getClient(instance).getSite({
|
const sitePromise = client({ instanceURL: instance, auth: jwt }).getSite()
|
||||||
auth: jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
let timer = setTimeout(
|
let timer = setTimeout(
|
||||||
() =>
|
() =>
|
||||||
@@ -170,6 +181,12 @@ async function userFromJwt(
|
|||||||
return r
|
return r
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (!versionIsSupported(site.version, MINIMUM_VERSION)) {
|
||||||
|
throw new Error(
|
||||||
|
`This version of Photon only supports Lemmy instances with version ${MINIMUM_VERSION} or higher. This Lemmy instance is running: ${site.version}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const myUser = site.my_user
|
const myUser = site.my_user
|
||||||
if (!myUser) return undefined
|
if (!myUser) return undefined
|
||||||
|
|
||||||
@@ -250,6 +267,10 @@ export async function setUserID(id: number) {
|
|||||||
|
|
||||||
if (prof?.jwt) {
|
if (prof?.jwt) {
|
||||||
const user = await userFromJwt(prof.jwt, prof.instance)
|
const user = await userFromJwt(prof.jwt, prof.instance)
|
||||||
|
.then((u) => u)
|
||||||
|
.catch((err) => {
|
||||||
|
toast({ content: err as any, type: 'error' })
|
||||||
|
})
|
||||||
instance.set(prof.instance)
|
instance.set(prof.instance)
|
||||||
prof.user = user?.user
|
prof.user = user?.user
|
||||||
prof.avatar = user?.user.local_user_view.person.avatar
|
prof.avatar = user?.user.local_user_view.person.avatar
|
||||||
@@ -276,16 +297,12 @@ export function moveProfile(id: number, up: boolean) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getNotificationCount = async (jwt: string, mod: boolean) => {
|
const getNotificationCount = async (jwt: string, mod: boolean) => {
|
||||||
const unreads = await getClient().getUnreadCount({
|
const unreads = await getClient().getUnreadCount()
|
||||||
auth: jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
let reports: number = 0
|
let reports: number = 0
|
||||||
|
|
||||||
if (mod) {
|
if (mod) {
|
||||||
const reportRes = await getClient().getReportCount({
|
const reportRes = await getClient().getReportCount({})
|
||||||
auth: jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
reports =
|
reports =
|
||||||
reportRes.comment_reports +
|
reportRes.comment_reports +
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
search={async (q) => {
|
search={async (q) => {
|
||||||
const results = await getClient().search({
|
const results = await getClient().search({
|
||||||
q: q || ' ',
|
q: q || ' ',
|
||||||
auth: jwt,
|
|
||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
limit: 20,
|
limit: 20,
|
||||||
listing_type: listing_type,
|
listing_type: listing_type,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import { site } from '$lib/lemmy.js'
|
||||||
import { searchParam } from '$lib/util.js'
|
import { searchParam } from '$lib/util.js'
|
||||||
|
import { feature } from '$lib/version.js'
|
||||||
import { Select } from 'mono-svelte'
|
import { Select } from 'mono-svelte'
|
||||||
import { ChartBar, Clock, Icon } from 'svelte-hero-icons'
|
import { ChartBar, Clock, Icon } from 'svelte-hero-icons'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
@@ -19,7 +21,7 @@
|
|||||||
bind:value={selected}
|
bind:value={selected}
|
||||||
on:change={(e) => {
|
on:change={(e) => {
|
||||||
sort = 'TopAll'
|
sort = 'TopAll'
|
||||||
if (navigate) searchParam($page.url, 'sort', selected, 'page')
|
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span slot="label" class="flex items-center gap-1">
|
<span slot="label" class="flex items-center gap-1">
|
||||||
@@ -52,8 +54,14 @@
|
|||||||
</span>
|
</span>
|
||||||
<option value="Active">Active</option>
|
<option value="Active">Active</option>
|
||||||
<option value="Hot">Hot</option>
|
<option value="Hot">Hot</option>
|
||||||
|
{#if feature('scaledSort', $site?.version)}
|
||||||
|
<option value="Scaled">Rising</option>
|
||||||
|
{/if}
|
||||||
<option value="TopAll">Top</option>
|
<option value="TopAll">Top</option>
|
||||||
<option value="New">New</option>
|
<option value="New">New</option>
|
||||||
|
{#if feature('controversialSort', $site?.version)}
|
||||||
|
<option value="Controversial">Controversial</option>
|
||||||
|
{/if}
|
||||||
<option value="Old">Old</option>
|
<option value="Old">Old</option>
|
||||||
<option value="MostComments">Most Comments</option>
|
<option value="MostComments">Most Comments</option>
|
||||||
<option value="NewComments">New Comments</option>
|
<option value="NewComments">New Comments</option>
|
||||||
|
|||||||
@@ -41,7 +41,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().editComment({
|
await getClient().editComment({
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: node.comment_view.comment.id,
|
comment_id: node.comment_view.comment.id,
|
||||||
content: newComment,
|
content: newComment,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getClient().createComment({
|
const response = await getClient().createComment({
|
||||||
auth: $profile.jwt,
|
|
||||||
content: value,
|
content: value,
|
||||||
post_id: postId,
|
post_id: postId,
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likeComment({
|
.likeComment({
|
||||||
score: upvoted ? 0 : 1,
|
score: upvoted ? 0 : 1,
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: commentId,
|
comment_id: commentId,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
@@ -59,7 +58,6 @@
|
|||||||
await getClient()
|
await getClient()
|
||||||
.likeComment({
|
.likeComment({
|
||||||
score: upvoted ? 0 : -1,
|
score: upvoted ? 0 : -1,
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: commentId,
|
comment_id: commentId,
|
||||||
})
|
})
|
||||||
.catch((_) => undefined)
|
.catch((_) => undefined)
|
||||||
|
|||||||
@@ -43,7 +43,6 @@
|
|||||||
parent.loading = true
|
parent.loading = true
|
||||||
|
|
||||||
const newComments = await getClient($page.params.instance).getComments({
|
const newComments = await getClient($page.params.instance).getComments({
|
||||||
auth: $profile?.jwt,
|
|
||||||
max_depth: 5,
|
max_depth: 5,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { amMod } from '$lib/components/lemmy/moderation/moderation.js'
|
import {
|
||||||
|
amMod,
|
||||||
|
isAdmin,
|
||||||
|
} from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||||
import Avatar from '$lib/components/ui/Avatar.svelte'
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
import StickyCard from '$lib/components/ui/StickyCard.svelte'
|
||||||
import { Popover, toast } from 'mono-svelte'
|
import {
|
||||||
|
Menu,
|
||||||
|
MenuButton,
|
||||||
|
Modal,
|
||||||
|
Popover,
|
||||||
|
removeToast,
|
||||||
|
toast,
|
||||||
|
} from 'mono-svelte'
|
||||||
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
|
||||||
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
import RelativeDate from '$lib/components/util/RelativeDate.svelte'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { fullCommunityName } from '$lib/util.js'
|
import { fullCommunityName } from '$lib/util.js'
|
||||||
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
|
import type { CommunityModeratorView, CommunityView } from 'lemmy-js-client'
|
||||||
@@ -16,8 +26,11 @@
|
|||||||
Calendar,
|
Calendar,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
Cog6Tooth,
|
Cog6Tooth,
|
||||||
|
EllipsisHorizontal,
|
||||||
|
Fire,
|
||||||
Icon,
|
Icon,
|
||||||
Minus,
|
Minus,
|
||||||
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Plus,
|
Plus,
|
||||||
UserGroup,
|
UserGroup,
|
||||||
@@ -41,7 +54,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().followCommunity({
|
await getClient().followCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
community_id: community_view.community.id,
|
community_id: community_view.community.id,
|
||||||
follow: !subscribed,
|
follow: !subscribed,
|
||||||
})
|
})
|
||||||
@@ -61,7 +73,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().blockCommunity({
|
await getClient().blockCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
community_id: community_view.community.id,
|
community_id: community_view.community.id,
|
||||||
block: !blocked,
|
block: !blocked,
|
||||||
})
|
})
|
||||||
@@ -72,8 +83,64 @@
|
|||||||
community_view.blocked = !blocked
|
community_view.blocked = !blocked
|
||||||
loading.blocking = false
|
loading.blocking = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let purgingCommunity = false
|
||||||
|
let purgeEnabled = false
|
||||||
|
$: if (purgingCommunity) {
|
||||||
|
purgeEnabled = false
|
||||||
|
setTimeout(() => {
|
||||||
|
purgeEnabled = true
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function purgeCommunity() {
|
||||||
|
purgingCommunity = false
|
||||||
|
const purgeToast = toast({ content: 'Purging community...', loading: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client().purgeCommunity({
|
||||||
|
community_id: community_view.community.id,
|
||||||
|
})
|
||||||
|
removeToast(purgeToast)
|
||||||
|
toast({ content: 'Purged that community.', type: 'success' })
|
||||||
|
} catch (e) {
|
||||||
|
toast({ content: e as any, type: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if purgingCommunity}
|
||||||
|
<Modal bind:open={purgingCommunity}>
|
||||||
|
<svelte:fragment slot="title">Purging Community</svelte:fragment>
|
||||||
|
<p>
|
||||||
|
Purging community <span class="font-bold">
|
||||||
|
{community_view.community.title}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Are you sure you want to do this? (The button will enable in 3 seconds.)
|
||||||
|
</p>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
on:click={() => (purgingCommunity = false)}
|
||||||
|
class="flex-1"
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="danger"
|
||||||
|
on:click={purgeCommunity}
|
||||||
|
disabled={!purgeEnabled}
|
||||||
|
class="flex-1"
|
||||||
|
>
|
||||||
|
Purge
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<StickyCard>
|
<StickyCard>
|
||||||
<div class="flex flex-row gap-3 items-center">
|
<div class="flex flex-row gap-3 items-center">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
@@ -167,17 +234,8 @@
|
|||||||
? 'Unsubscribe'
|
? 'Unsubscribe'
|
||||||
: 'Subscribe'}
|
: 'Subscribe'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
|
||||||
disabled={loading.blocking}
|
|
||||||
loading={loading.blocking}
|
|
||||||
color="danger"
|
|
||||||
size="lg"
|
|
||||||
on:click={block}
|
|
||||||
>
|
|
||||||
{community_view.blocked ? 'Unblock' : 'Block'}
|
|
||||||
</Button>
|
|
||||||
{#if $profile.user && amMod($profile.user, community_view.community)}
|
|
||||||
<div class="flex flex-row gap-2 ml-auto">
|
<div class="flex flex-row gap-2 ml-auto">
|
||||||
|
{#if $profile.user && amMod($profile.user, community_view.community)}
|
||||||
<Button
|
<Button
|
||||||
href="/c/{fullCommunityName(
|
href="/c/{fullCommunityName(
|
||||||
community_view.community.name,
|
community_view.community.name,
|
||||||
@@ -187,8 +245,26 @@
|
|||||||
>
|
>
|
||||||
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
|
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
<Menu origin="bottom-right">
|
||||||
|
<Button size="square-md" slot="target">
|
||||||
|
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
|
||||||
|
</Button>
|
||||||
|
<MenuButton color="danger-subtle" size="lg" on:click={block}>
|
||||||
|
<Icon src={NoSymbol} size="16" mini slot="prefix" />
|
||||||
|
{community_view.blocked ? 'Unblock' : 'Block'}
|
||||||
|
</MenuButton>
|
||||||
|
{#if $profile.user && isAdmin($profile.user)}
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => (purgingCommunity = !purgingCommunity)}
|
||||||
|
>
|
||||||
|
<Icon src={Fire} size="16" mini slot="prefix" />
|
||||||
|
Purge
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<Markdown source={community_view.community.description} />
|
<Markdown source={community_view.community.description} />
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
|
|
||||||
const res = edit
|
const res = edit
|
||||||
? await getClient().editCommunity({
|
? await getClient().editCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
title: formData.displayName,
|
title: formData.displayName,
|
||||||
description: formData.sidebar,
|
description: formData.sidebar,
|
||||||
nsfw: formData.nsfw,
|
nsfw: formData.nsfw,
|
||||||
@@ -59,7 +58,6 @@
|
|||||||
community_id: edit,
|
community_id: edit,
|
||||||
})
|
})
|
||||||
: await getClient().createCommunity({
|
: await getClient().createCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
title: formData.displayName,
|
title: formData.displayName,
|
||||||
description: formData.sidebar,
|
description: formData.sidebar,
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().createPrivateMessage({
|
await getClient().createPrivateMessage({
|
||||||
auth: $profile.jwt,
|
|
||||||
content: message,
|
content: message,
|
||||||
recipient_id: user.id,
|
recipient_id: user.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -62,7 +62,6 @@
|
|||||||
|
|
||||||
if (community) {
|
if (community) {
|
||||||
await getClient().banFromCommunity({
|
await getClient().banFromCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
ban: !banned,
|
ban: !banned,
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: item.id,
|
person_id: item.id,
|
||||||
@@ -72,7 +71,6 @@
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await getClient().banPerson({
|
await getClient().banPerson({
|
||||||
auth: $profile.jwt,
|
|
||||||
ban: !banned,
|
ban: !banned,
|
||||||
person_id: item.id,
|
person_id: item.id,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().lockPost({
|
await getClient().lockPost({
|
||||||
auth: $profile.jwt,
|
|
||||||
locked: lock,
|
locked: lock,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
})
|
})
|
||||||
@@ -60,7 +59,6 @@
|
|||||||
try {
|
try {
|
||||||
await getClient().featurePost({
|
await getClient().featurePost({
|
||||||
feature_type: toInstance ? 'Local' : 'Community',
|
feature_type: toInstance ? 'Local' : 'Community',
|
||||||
auth: $profile.jwt,
|
|
||||||
featured: pinned,
|
featured: pinned,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -57,13 +57,11 @@
|
|||||||
if (purge) {
|
if (purge) {
|
||||||
if (isCommentView(item)) {
|
if (isCommentView(item)) {
|
||||||
await getClient(undefined, fetch).purgeComment({
|
await getClient(undefined, fetch).purgeComment({
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: item.comment.id,
|
comment_id: item.comment.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await getClient(undefined, fetch).purgePost({
|
await getClient(undefined, fetch).purgePost({
|
||||||
auth: $profile.jwt,
|
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
@@ -91,7 +89,6 @@
|
|||||||
if (privateMessage) {
|
if (privateMessage) {
|
||||||
await getClient()
|
await getClient()
|
||||||
.createPrivateMessage({
|
.createPrivateMessage({
|
||||||
auth: $profile.jwt,
|
|
||||||
content: replyReason,
|
content: replyReason,
|
||||||
recipient_id: isCommentView(item)
|
recipient_id: isCommentView(item)
|
||||||
? item.comment.creator_id
|
? item.comment.creator_id
|
||||||
@@ -106,7 +103,6 @@
|
|||||||
} else {
|
} else {
|
||||||
await getClient()
|
await getClient()
|
||||||
.createComment({
|
.createComment({
|
||||||
auth: $profile.jwt,
|
|
||||||
content: replyReason,
|
content: replyReason,
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
parent_id: isCommentView(item) ? item.comment.id : undefined,
|
parent_id: isCommentView(item) ? item.comment.id : undefined,
|
||||||
@@ -122,7 +118,6 @@
|
|||||||
|
|
||||||
if (isCommentView(item)) {
|
if (isCommentView(item)) {
|
||||||
await getClient().removeComment({
|
await getClient().removeComment({
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: item.comment.id,
|
comment_id: item.comment.id,
|
||||||
removed: !removed,
|
removed: !removed,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
@@ -130,7 +125,6 @@
|
|||||||
item.comment.removed = !removed
|
item.comment.removed = !removed
|
||||||
} else if (isPostView(item)) {
|
} else if (isPostView(item)) {
|
||||||
await getClient().removePost({
|
await getClient().removePost({
|
||||||
auth: $profile.jwt,
|
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
removed: !removed,
|
removed: !removed,
|
||||||
reason: reason || undefined,
|
reason: reason || undefined,
|
||||||
|
|||||||
@@ -27,13 +27,11 @@
|
|||||||
try {
|
try {
|
||||||
if (isComment(item)) {
|
if (isComment(item)) {
|
||||||
await getClient().createCommentReport({
|
await getClient().createCommentReport({
|
||||||
auth: $profile.jwt,
|
|
||||||
comment_id: item.comment.id,
|
comment_id: item.comment.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
} else if (isPost(item)) {
|
} else if (isPost(item)) {
|
||||||
await getClient().createPostReport({
|
await getClient().createPostReport({
|
||||||
auth: $profile.jwt,
|
|
||||||
post_id: item.post.id,
|
post_id: item.post.id,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ export const amMod = (me: MyUserInfo, community: Community) =>
|
|||||||
export const amModOfAny = (me?: MyUserInfo) =>
|
export const amModOfAny = (me?: MyUserInfo) =>
|
||||||
me && (me.moderates.length > 0 || isAdmin(me))
|
me && (me.moderates.length > 0 || isAdmin(me))
|
||||||
|
|
||||||
export const isAdmin = (me: MyUserInfo) => me.local_user_view.person.admin
|
export const isAdmin = (me: MyUserInfo) =>
|
||||||
|
// backwards compatibility hack
|
||||||
|
// @ts-ignore
|
||||||
|
me.local_user_view.local_user.admin ?? me.local_user_view.person?.admin
|
||||||
|
|
||||||
export const removalTemplate = (
|
export const removalTemplate = (
|
||||||
input: string,
|
input: string,
|
||||||
|
|||||||
@@ -63,7 +63,6 @@
|
|||||||
communitySearch = passedCommunity.name
|
communitySearch = passedCommunity.name
|
||||||
} else {
|
} else {
|
||||||
const list = await getClient().listCommunities({
|
const list = await getClient().listCommunities({
|
||||||
auth: $profile?.jwt,
|
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
sort: 'Active',
|
sort: 'Active',
|
||||||
limit: 40,
|
limit: 40,
|
||||||
@@ -107,7 +106,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const post = await getClient().editPost({
|
const post = await getClient().editPost({
|
||||||
auth: $profile.jwt,
|
|
||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
url: data.url || undefined,
|
url: data.url || undefined,
|
||||||
@@ -121,10 +119,11 @@
|
|||||||
|
|
||||||
dispatcher('submit', post.post_view)
|
dispatcher('submit', post.post_view)
|
||||||
} else {
|
} else {
|
||||||
let image = data.image ? await uploadImage(data.image[0], $profile.instance, $profile.jwt) : undefined
|
let image = data.image
|
||||||
|
? await uploadImage(data.image[0], $profile.instance, $profile.jwt)
|
||||||
|
: undefined
|
||||||
data.url = image || data.url || undefined
|
data.url = image || data.url || undefined
|
||||||
const post = await getClient().createPost({
|
const post = await getClient().createPost({
|
||||||
auth: $profile.jwt,
|
|
||||||
community_id: data.community!,
|
community_id: data.community!,
|
||||||
name: data.title,
|
name: data.title,
|
||||||
body: data.body,
|
body: data.body,
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { getInstance } from '$lib/lemmy.js'
|
import { getInstance } from '$lib/lemmy.js'
|
||||||
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
import type { CommentView, PersonView, Post, PostView } from 'lemmy-js-client'
|
||||||
|
|
||||||
export const isMutable = (post: PostView, me: PersonView) =>
|
|
||||||
(me.person.admin && post.post.local) || me.person.id == post.creator.id
|
|
||||||
|
|
||||||
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
export const isCommentMutable = (comment: CommentView, me: PersonView) =>
|
||||||
me.person.id == comment.creator.id
|
me.person.id == comment.creator.id
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@
|
|||||||
<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 relative"
|
class="max-md:w-9 max-md:h-8 max-md:!p-0 "
|
||||||
>
|
>
|
||||||
<Icon src={CommandLine} mini size="16" slot="prefix" />
|
<Icon src={CommandLine} mini size="16" slot="prefix" />
|
||||||
<span class="hidden md:inline">Admin</span>
|
<span class="hidden md:inline">Admin</span>
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let page: number
|
export let page: number
|
||||||
|
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ change: number }>()
|
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-row w-full gap-4 items-center">
|
<div class="flex flex-row w-full gap-4 items-center">
|
||||||
@@ -21,9 +22,11 @@
|
|||||||
</span>
|
</span>
|
||||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if cursor?.back}
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dispatcher('change', --page)
|
if (cursor?.back) dispatcher('cursor', cursor.back)
|
||||||
|
else dispatcher('change', --page)
|
||||||
}}
|
}}
|
||||||
disabled={page <= 1}
|
disabled={page <= 1}
|
||||||
class={$$slots.default ? '' : 'flex-1'}
|
class={$$slots.default ? '' : 'flex-1'}
|
||||||
@@ -31,10 +34,12 @@
|
|||||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
||||||
Back
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dispatcher('change', ++page)
|
if (cursor?.next) dispatcher('cursor', cursor?.next)
|
||||||
|
else dispatcher('change', ++page)
|
||||||
}}
|
}}
|
||||||
class={$$slots.default ? '' : 'flex-1'}
|
class={$$slots.default ? '' : 'flex-1'}
|
||||||
>
|
>
|
||||||
|
|||||||
+64
-18
@@ -2,47 +2,93 @@ import { type GetSiteResponse, LemmyHttp } from 'lemmy-js-client'
|
|||||||
import { get, writable } from 'svelte/store'
|
import { get, writable } from 'svelte/store'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
import { instance } from '$lib/instance.js'
|
import { instance } from '$lib/instance.js'
|
||||||
|
import { instanceToURL } from '$lib/util.js'
|
||||||
|
import { profile } from '$lib/auth.js'
|
||||||
|
|
||||||
|
export const site = writable<GetSiteResponse | undefined>(undefined)
|
||||||
|
|
||||||
|
const isURL = (input: RequestInfo | URL): input is URL =>
|
||||||
|
typeof input == 'object' && 'searchParams' in input
|
||||||
|
|
||||||
|
const toURL = (input: RequestInfo | URL): URL | undefined => {
|
||||||
|
if (isURL(input)) return input
|
||||||
|
|
||||||
|
try {
|
||||||
|
return new URL(input.toString())
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function customFetch(
|
async function customFetch(
|
||||||
func: (
|
func:
|
||||||
|
| ((
|
||||||
input: RequestInfo | URL,
|
input: RequestInfo | URL,
|
||||||
init?: RequestInit | undefined
|
init?: RequestInit | undefined
|
||||||
) => Promise<Response>,
|
) => Promise<Response>)
|
||||||
|
| undefined,
|
||||||
input: RequestInfo | URL,
|
input: RequestInfo | URL,
|
||||||
init?: RequestInit | undefined
|
init?: RequestInit | undefined,
|
||||||
|
auth?: string
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const res = await func(input, init)
|
const f = func ? func : fetch
|
||||||
|
|
||||||
|
if (init?.body && auth) {
|
||||||
|
const json = JSON.parse(init.body.toString())
|
||||||
|
json.auth = auth
|
||||||
|
init.body = JSON.stringify(json)
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = toURL(input)
|
||||||
|
if (auth && url) url.searchParams.set('auth', auth)
|
||||||
|
|
||||||
|
const res = await f(url ?? input, init)
|
||||||
if (!res.ok) throw error(res.status, await res.text())
|
if (!res.ok) throw error(res.status, await res.text())
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function client({
|
||||||
|
instanceURL,
|
||||||
|
func,
|
||||||
|
auth,
|
||||||
|
}: {
|
||||||
|
instanceURL?: string
|
||||||
|
func?: (
|
||||||
|
input: RequestInfo | URL,
|
||||||
|
init?: RequestInit | undefined
|
||||||
|
) => Promise<Response>
|
||||||
|
auth?: string
|
||||||
|
} = {}) {
|
||||||
|
if (!instanceURL) instanceURL = get(instance)
|
||||||
|
|
||||||
|
let jwt = auth ? auth : get(profile)?.jwt
|
||||||
|
|
||||||
|
let headers = jwt ? { Authorization: `Bearer ${jwt}` } : { Authorization: '' }
|
||||||
|
|
||||||
|
return new LemmyHttp(instanceToURL(instanceURL), {
|
||||||
|
fetchFunction: (input, init) => customFetch(func, input, init, jwt),
|
||||||
|
headers: headers,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function getClient(
|
export function getClient(
|
||||||
instanceURL?: string,
|
instanceURL?: string,
|
||||||
func?: (
|
func?: (
|
||||||
input: RequestInfo | URL,
|
input: RequestInfo | URL,
|
||||||
init?: RequestInit | undefined
|
init?: RequestInit | undefined
|
||||||
) => Promise<Response>
|
) => Promise<Response>,
|
||||||
|
auth?: string
|
||||||
): LemmyHttp {
|
): LemmyHttp {
|
||||||
if (!instanceURL) {
|
return client({ instanceURL, func, auth })
|
||||||
instanceURL = get(instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LemmyHttp(`https://${instanceURL}`, {
|
|
||||||
fetchFunction: func
|
|
||||||
? (input, init) => customFetch(func, input, init)
|
|
||||||
: undefined,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getInstance = () => get(instance)
|
export const getInstance = () => encodeURIComponent(get(instance))
|
||||||
|
|
||||||
export const site = writable<GetSiteResponse | undefined>(undefined)
|
|
||||||
|
|
||||||
export async function validateInstance(instance: string): Promise<boolean> {
|
export async function validateInstance(instance: string): Promise<boolean> {
|
||||||
if (instance == '') return false
|
if (instance == '') return false
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient(instance).getSite({})
|
await getClient(instance).getSite()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ export async function save(
|
|||||||
if (item.type == 'post') {
|
if (item.type == 'post') {
|
||||||
return (
|
return (
|
||||||
await getClient().savePost({
|
await getClient().savePost({
|
||||||
auth: jwt,
|
|
||||||
post_id: item.id,
|
post_id: item.id,
|
||||||
save: save,
|
save: save,
|
||||||
})
|
})
|
||||||
@@ -78,7 +77,6 @@ export async function save(
|
|||||||
} else if (item.type == 'comment') {
|
} else if (item.type == 'comment') {
|
||||||
return (
|
return (
|
||||||
await getClient().saveComment({
|
await getClient().saveComment({
|
||||||
auth: jwt,
|
|
||||||
comment_id: item.id,
|
comment_id: item.id,
|
||||||
save: save,
|
save: save,
|
||||||
})
|
})
|
||||||
@@ -97,7 +95,6 @@ export async function deleteItem(
|
|||||||
if (item.type == 'post') {
|
if (item.type == 'post') {
|
||||||
return (
|
return (
|
||||||
await getClient().deletePost({
|
await getClient().deletePost({
|
||||||
auth: jwt,
|
|
||||||
post_id: item.id,
|
post_id: item.id,
|
||||||
deleted: deleted,
|
deleted: deleted,
|
||||||
})
|
})
|
||||||
@@ -105,7 +102,6 @@ export async function deleteItem(
|
|||||||
} else if (item.type == 'comment') {
|
} else if (item.type == 'comment') {
|
||||||
return (
|
return (
|
||||||
await getClient().deleteComment({
|
await getClient().deleteComment({
|
||||||
auth: jwt,
|
|
||||||
comment_id: item.id,
|
comment_id: item.id,
|
||||||
deleted: deleted,
|
deleted: deleted,
|
||||||
})
|
})
|
||||||
@@ -124,7 +120,6 @@ export async function vote(
|
|||||||
if (item.type == 'post') {
|
if (item.type == 'post') {
|
||||||
return (
|
return (
|
||||||
await getClient().likePost({
|
await getClient().likePost({
|
||||||
auth: jwt,
|
|
||||||
post_id: item.id,
|
post_id: item.id,
|
||||||
score: vote,
|
score: vote,
|
||||||
})
|
})
|
||||||
@@ -132,7 +127,6 @@ export async function vote(
|
|||||||
} else if (item.type == 'comment') {
|
} else if (item.type == 'comment') {
|
||||||
return (
|
return (
|
||||||
await getClient().likeComment({
|
await getClient().likeComment({
|
||||||
auth: jwt,
|
|
||||||
comment_id: item.id,
|
comment_id: item.id,
|
||||||
score: vote,
|
score: vote,
|
||||||
})
|
})
|
||||||
@@ -151,7 +145,6 @@ export async function markAsRead(
|
|||||||
if (item.type == 'post') {
|
if (item.type == 'post') {
|
||||||
return (
|
return (
|
||||||
await getClient().markPostAsRead({
|
await getClient().markPostAsRead({
|
||||||
auth: jwt,
|
|
||||||
post_id: item.id,
|
post_id: item.id,
|
||||||
read: read,
|
read: read,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export const blockUser = async (block: boolean, id: number) => {
|
|||||||
if (!auth) throw new Error('Unauthorized')
|
if (!auth) throw new Error('Unauthorized')
|
||||||
|
|
||||||
const response = await getClient().blockPerson({
|
const response = await getClient().blockPerson({
|
||||||
auth: auth,
|
|
||||||
block: block,
|
block: block,
|
||||||
person_id: id,
|
person_id: id,
|
||||||
})
|
})
|
||||||
@@ -53,14 +52,12 @@ export const addSubscription = (
|
|||||||
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
|
export const addAdmin = async (handle: string, added: boolean, jwt: string) =>
|
||||||
trycatch(async () => {
|
trycatch(async () => {
|
||||||
const user = await getClient().resolveObject({
|
const user = await getClient().resolveObject({
|
||||||
auth: jwt,
|
|
||||||
q: handle,
|
q: handle,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!user.person) throw new Error('No user found')
|
if (!user.person) throw new Error('No user found')
|
||||||
|
|
||||||
return await getClient().addAdmin({
|
return await getClient().addAdmin({
|
||||||
auth: jwt,
|
|
||||||
added: true,
|
added: true,
|
||||||
person_id: user.person.person.id,
|
person_id: user.person.person.id,
|
||||||
})
|
})
|
||||||
|
|||||||
+9
-2
@@ -101,8 +101,10 @@ export const removeItem = <T>(array: T[], predicate: (item: T) => boolean) => {
|
|||||||
array.splice(array.findIndex(predicate), 1)
|
array.splice(array.findIndex(predicate), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DOMAIN_REGEX = /^((?!-)[A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,63}/gi
|
export const DOMAIN_REGEX =
|
||||||
export const DOMAIN_REGEX_FORMS = '^((?!-)[A-Za-z0-9-]{1,63}.)+[A-Za-z]{2,63}'
|
/^(http(s)?:\/\/)?((?!-)[A-Za-z0-9-]{1,63}\.)+[A-Za-z]{2,63}(:[0-9]{0,5})$/g
|
||||||
|
export const DOMAIN_REGEX_FORMS =
|
||||||
|
'(http(s)?://)?((?!-)[A-Za-z0-9-]{1,63}.)+[A-Za-z]{2,63}(:[0-9]{0,5})?'
|
||||||
|
|
||||||
export const isSubscribed = (subscribed: SubscribedType) =>
|
export const isSubscribed = (subscribed: SubscribedType) =>
|
||||||
subscribed == 'Pending' || subscribed == 'Subscribed'
|
subscribed == 'Pending' || subscribed == 'Subscribed'
|
||||||
@@ -166,3 +168,8 @@ export async function uploadImage(
|
|||||||
}: ${response.status}: ${response.statusText}`
|
}: ${response.status}: ${response.statusText}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const instanceToURL = (input: string) =>
|
||||||
|
input.startsWith('http://') || input.startsWith('https://')
|
||||||
|
? input
|
||||||
|
: `https://${input}`
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
const FEATURES = {
|
||||||
|
moderatorView: '0.19.0',
|
||||||
|
controversialSort: '0.19.0',
|
||||||
|
scaledSort: '0.19.0',
|
||||||
|
unproxiedImageUpload: '0.19.0',
|
||||||
|
cursorPagination: '0.19.0',
|
||||||
|
newTotp: '0.19.0',
|
||||||
|
blockInstances: '0.19.0',
|
||||||
|
}
|
||||||
|
|
||||||
|
type Feature = keyof typeof FEATURES
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a feature is supported by the current version.
|
||||||
|
*/
|
||||||
|
export const feature = (feature: Feature, version: string = '0.0.0'): boolean =>
|
||||||
|
versionIsSupported(version, FEATURES[feature])
|
||||||
|
|
||||||
|
export const MINIMUM_VERSION = '0.18.1'
|
||||||
|
export const MAXIMUM_VERSION = '0.999'
|
||||||
|
|
||||||
|
export const versionIsSupported = (v: string, minimum: string) => {
|
||||||
|
const regex = /^(\d+\.)?(\d+\.)?(\*|\d+)*/i
|
||||||
|
const cur = v.match(regex)
|
||||||
|
const min = minimum.match(regex)
|
||||||
|
|
||||||
|
if (!cur || !min) return false
|
||||||
|
|
||||||
|
const [minMajor, minMinor, minPatch] = min.slice(1, 4).map((i) => Number(i))
|
||||||
|
const [curMajor, curMinor, curPatch] = cur.slice(1, 4).map((i) => Number(i))
|
||||||
|
|
||||||
|
if (curMajor < minMajor) return false
|
||||||
|
else if (curMajor > minMajor) return true
|
||||||
|
|
||||||
|
if (curMinor < minMinor) return false
|
||||||
|
else if (curMinor > minMinor) return true
|
||||||
|
|
||||||
|
if (curPatch < minPatch) return false
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
+21
-14
@@ -7,10 +7,12 @@
|
|||||||
import { searchParam } from '$lib/util.js'
|
import { searchParam } from '$lib/util.js'
|
||||||
import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte'
|
import PostFeed from '$lib/components/lemmy/post/PostFeed.svelte'
|
||||||
import { Button, Modal, Select, Spinner } from 'mono-svelte'
|
import { Button, Modal, Select, Spinner } from 'mono-svelte'
|
||||||
import { GlobeAmericas, Icon } from 'svelte-hero-icons'
|
import { ChartBar, GlobeAmericas, Icon } from 'svelte-hero-icons'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte'
|
import ViewSelect from '$lib/components/lemmy/ViewSelect.svelte'
|
||||||
import { site } from '$lib/lemmy.js'
|
import { site } from '$lib/lemmy.js'
|
||||||
|
import { amModOfAny } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
|
import { feature } from '$lib/version.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -55,7 +57,7 @@
|
|||||||
<Select
|
<Select
|
||||||
bind:value={data.listingType}
|
bind:value={data.listingType}
|
||||||
on:change={() =>
|
on:change={() =>
|
||||||
searchParam($page.url, 'type', data.listingType, 'page')}
|
searchParam($page.url, 'type', data.listingType, 'page', 'cursor')}
|
||||||
>
|
>
|
||||||
<span slot="label" class="flex items-center gap-1">
|
<span slot="label" class="flex items-center gap-1">
|
||||||
<Icon src={GlobeAmericas} size="16" mini />
|
<Icon src={GlobeAmericas} size="16" mini />
|
||||||
@@ -64,6 +66,14 @@
|
|||||||
<option value="All">All</option>
|
<option value="All">All</option>
|
||||||
<option value="Local">Local</option>
|
<option value="Local">Local</option>
|
||||||
<option value="Subscribed" disabled={!$profile?.jwt}>Subscribed</option>
|
<option value="Subscribed" disabled={!$profile?.jwt}>Subscribed</option>
|
||||||
|
{#if feature('moderatorView', $site?.version)}
|
||||||
|
<option
|
||||||
|
value="ModeratorView"
|
||||||
|
disabled={!$profile?.jwt || !amModOfAny($profile?.user)}
|
||||||
|
>
|
||||||
|
Moderator
|
||||||
|
</option>
|
||||||
|
{/if}
|
||||||
</Select>
|
</Select>
|
||||||
<div class="flex gap-4 flex-wrap">
|
<div class="flex gap-4 flex-wrap">
|
||||||
<Sort selected={data.sort} />
|
<Sort selected={data.sort} />
|
||||||
@@ -78,21 +88,18 @@
|
|||||||
<div class="mt-auto">
|
<div class="mt-auto">
|
||||||
<Pageination
|
<Pageination
|
||||||
page={data.page}
|
page={data.page}
|
||||||
|
cursor={{ next: data.cursor.next, back: data.cursor.back }}
|
||||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||||
|
on:cursor={(c) => {
|
||||||
|
searchParam($page.url, 'cursor', c.detail)
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<span class="max-sm:hidden">
|
<span class="flex flex-row items-center gap-1">
|
||||||
You've viewed <span
|
<Icon src={ChartBar} size="16" mini />
|
||||||
class="text-primary-900 dark:text-primary-100 font-bold"
|
<span class="font-medium text-black dark:text-white">
|
||||||
>
|
{$site?.site_view.counts.users_active_day}
|
||||||
{data.page * 20}
|
|
||||||
</span>
|
</span>
|
||||||
posts.
|
<span class="font-normal">Active users</span>
|
||||||
</span>
|
|
||||||
<span class="sm:hidden">
|
|
||||||
<span class="text-primary-900 dark:text-primary-100">
|
|
||||||
{data.page * 20}
|
|
||||||
</span>
|
|
||||||
posts
|
|
||||||
</span>
|
</span>
|
||||||
</Pageination>
|
</Pageination>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+19
-9
@@ -4,9 +4,12 @@ import type { ListingType, SortType } from 'lemmy-js-client'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
import { error } from '@sveltejs/kit'
|
import { error } from '@sveltejs/kit'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { feature } from '$lib/version.js'
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
const page = Number(url.searchParams.get('page') || 1) || 1
|
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||||
|
const prevCursor = url.searchParams.get('prevCursor') as string | undefined
|
||||||
|
const page = Number(url.searchParams.get('page')) || undefined
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(url.searchParams.get('sort') as SortType) ||
|
(url.searchParams.get('sort') as SortType) ||
|
||||||
@@ -15,18 +18,25 @@ export async function load({ url, fetch }) {
|
|||||||
(url.searchParams.get('type') as ListingType) ||
|
(url.searchParams.get('type') as ListingType) ||
|
||||||
get(userSettings).defaultSort.feed
|
get(userSettings).defaultSort.feed
|
||||||
|
|
||||||
try {
|
const posts = await getClient(undefined, fetch).getPosts({
|
||||||
return {
|
|
||||||
sort: sort,
|
|
||||||
listingType: listingType,
|
|
||||||
page: page,
|
|
||||||
posts: await getClient(undefined, fetch).getPosts({
|
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
type_: listingType,
|
type_: listingType,
|
||||||
auth: get(profile)?.jwt,
|
page_cursor: cursor,
|
||||||
}),
|
})
|
||||||
|
|
||||||
|
try {
|
||||||
|
return {
|
||||||
|
sort: sort,
|
||||||
|
listingType: listingType,
|
||||||
|
page: page || 1,
|
||||||
|
posts: posts,
|
||||||
|
cursor: {
|
||||||
|
next: posts.next_page,
|
||||||
|
back: prevCursor,
|
||||||
|
current: cursor,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw error(500, {
|
throw error(500, {
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ export async function load({ fetch }) {
|
|||||||
let site = get(siteStore)
|
let site = get(siteStore)
|
||||||
|
|
||||||
if (!site) {
|
if (!site) {
|
||||||
const res = await getClient(undefined, fetch).getSite({
|
const res = await getClient(undefined, fetch).getSite()
|
||||||
auth: jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
site = res
|
site = res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ export async function load({ data, fetch, url }) {
|
|||||||
const unreadOnly = (url.searchParams.get('unreadOnly') || 'true') == 'true'
|
const unreadOnly = (url.searchParams.get('unreadOnly') || 'true') == 'true'
|
||||||
|
|
||||||
const res = await getClient(undefined, fetch).listRegistrationApplications({
|
const res = await getClient(undefined, fetch).listRegistrationApplications({
|
||||||
auth: jwt,
|
|
||||||
page: page,
|
page: page,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
unread_only: unreadOnly,
|
unread_only: unreadOnly,
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
try {
|
try {
|
||||||
await getClient().approveRegistrationApplication({
|
await getClient().approveRegistrationApplication({
|
||||||
approve: approve,
|
approve: approve,
|
||||||
auth: $profile.jwt,
|
|
||||||
id: application.registration_application.id,
|
id: application.registration_application.id,
|
||||||
})
|
})
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().editSite({
|
await getClient().editSite({
|
||||||
auth: jwt,
|
|
||||||
...formData,
|
...formData,
|
||||||
})
|
})
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -66,7 +66,6 @@
|
|||||||
if (!blocked) allowedInstances.push(instance)
|
if (!blocked) allowedInstances.push(instance)
|
||||||
|
|
||||||
await getClient().editSite({
|
await getClient().editSite({
|
||||||
auth: $profile.jwt,
|
|
||||||
blocked_instances: blockedInstances,
|
blocked_instances: blockedInstances,
|
||||||
allowed_instances: allowedInstances,
|
allowed_instances: allowedInstances,
|
||||||
})
|
})
|
||||||
@@ -102,7 +101,6 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
return await getClient().editSite({
|
return await getClient().editSite({
|
||||||
auth: $profile.jwt,
|
|
||||||
allowed_instances: allowedInstances,
|
allowed_instances: allowedInstances,
|
||||||
blocked_instances: blockedInstances,
|
blocked_instances: blockedInstances,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ import { getClient } from '$lib/lemmy.js'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ fetch, parent }) {
|
export async function load({ fetch, parent }) {
|
||||||
const instances = await getClient(undefined, fetch).getFederatedInstances({
|
const instances = await getClient(undefined, fetch).getFederatedInstances()
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
federated_instances: instances,
|
federated_instances: instances,
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().editSite({
|
await getClient().editSite({
|
||||||
auth: $profile.jwt,
|
|
||||||
taglines: taglines,
|
taglines: taglines,
|
||||||
})
|
})
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
const result = await trycatch(() =>
|
const result = await trycatch(() =>
|
||||||
getClient().addAdmin({
|
getClient().addAdmin({
|
||||||
added: false,
|
added: false,
|
||||||
auth: $profile!.jwt!,
|
|
||||||
person_id: id,
|
person_id: id,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import type { ListingType, SortType } from 'lemmy-js-client'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load(req: any) {
|
export async function load(req: any) {
|
||||||
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
const cursor: string | undefined = req.url.searchParams.get('cursor')
|
||||||
|
const page = Number(req.url.searchParams.get('page')) || undefined
|
||||||
|
|
||||||
const sort: SortType =
|
const sort: SortType =
|
||||||
(req.url.searchParams.get('sort') as SortType) ||
|
(req.url.searchParams.get('sort') as SortType) ||
|
||||||
@@ -13,17 +14,16 @@ export async function load(req: any) {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
sort: sort,
|
sort: sort,
|
||||||
page: page,
|
page: page || 1,
|
||||||
posts: getClient(undefined, req.fetch).getPosts({
|
posts: getClient(undefined, req.fetch).getPosts({
|
||||||
limit: 40,
|
limit: 40,
|
||||||
community_name: req.params.name,
|
community_name: req.params.name,
|
||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(profile)?.jwt,
|
page_cursor: cursor
|
||||||
}),
|
}),
|
||||||
community: getClient(undefined, req.fetch).getCommunity({
|
community: getClient(undefined, req.fetch).getCommunity({
|
||||||
name: req.params.name,
|
name: req.params.name,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
import { Button, Modal, toast } from 'mono-svelte'
|
import { Button, Modal, toast } from 'mono-svelte'
|
||||||
import { afterNavigate } from '$app/navigation'
|
import { afterNavigate } from '$app/navigation'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
|
import { ChartBar, Icon } from 'svelte-hero-icons'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -89,20 +90,22 @@
|
|||||||
|
|
||||||
<Pageination
|
<Pageination
|
||||||
page={data.page}
|
page={data.page}
|
||||||
|
cursor={{ next: data.posts.next_page }}
|
||||||
|
on:cursor={(c) => searchParam($page.url, 'cursor', c.detail)}
|
||||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||||
>
|
>
|
||||||
{#if data.posts.posts.length > 0}
|
{#if data.posts.posts.length > 0}
|
||||||
<span class="max-sm:hidden">
|
<span class="flex flex-row items-center gap-1">
|
||||||
You've scrolled <span class="text-primary-900 dark:text-primary-100">
|
<Icon src={ChartBar} size="16" mini />
|
||||||
{data.page * 20}
|
<span class="font-medium text-black dark:text-white">
|
||||||
|
{data.community.community_view.counts.users_active_day}
|
||||||
</span>
|
</span>
|
||||||
posts.
|
<span class="font-normal">
|
||||||
|
Active user{data.community.community_view.counts.users_active_day >
|
||||||
|
1
|
||||||
|
? 's'
|
||||||
|
: ''}
|
||||||
</span>
|
</span>
|
||||||
<span class="sm:hidden">
|
|
||||||
<span class="text-primary-900 dark:text-primary-100">
|
|
||||||
{data.page * 20}
|
|
||||||
</span>
|
|
||||||
posts
|
|
||||||
</span>
|
</span>
|
||||||
{/if}
|
{/if}
|
||||||
</Pageination>
|
</Pageination>
|
||||||
|
|||||||
@@ -24,13 +24,11 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().resolveObject({
|
const res = await getClient().resolveObject({
|
||||||
auth: $profile.jwt,
|
|
||||||
q: formData.newModerator,
|
q: formData.newModerator,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.person) {
|
if (res.person) {
|
||||||
const addModRes = await getClient().addModToCommunity({
|
const addModRes = await getClient().addModToCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
added: true,
|
added: true,
|
||||||
person_id: res.person.person.id,
|
person_id: res.person.person.id,
|
||||||
community_id: data.community.community_view.community.id,
|
community_id: data.community.community_view.community.id,
|
||||||
@@ -66,7 +64,6 @@
|
|||||||
try {
|
try {
|
||||||
const res = await getClient().addModToCommunity({
|
const res = await getClient().addModToCommunity({
|
||||||
added: false,
|
added: false,
|
||||||
auth: $profile.jwt,
|
|
||||||
community_id: data.community.community_view.community.id,
|
community_id: data.community.community_view.community.id,
|
||||||
person_id: id,
|
person_id: id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import { get } from 'svelte/store'
|
|||||||
export async function load({ params, fetch }) {
|
export async function load({ params, fetch }) {
|
||||||
const comment = await getClient(undefined, fetch).getComment({
|
const comment = await getClient(undefined, fetch).getComment({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
throw redirect(
|
throw redirect(
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ export async function load({ url, fetch }) {
|
|||||||
type_: 'Communities',
|
type_: 'Communities',
|
||||||
listing_type: type,
|
listing_type: type,
|
||||||
q: query,
|
q: query,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})),
|
})),
|
||||||
type: type,
|
type: type,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
@@ -35,7 +34,6 @@ export async function load({ url, fetch }) {
|
|||||||
page: page,
|
page: page,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
type_: type,
|
type_: type,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})),
|
})),
|
||||||
type: type,
|
type: type,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().followCommunity({
|
const res = await getClient().followCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
community_id: id,
|
community_id: id,
|
||||||
follow: subscribed == 'NotSubscribed',
|
follow: subscribed == 'NotSubscribed',
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
export const load = ({ url }) => ({
|
import { getClient } from '$lib/lemmy.js'
|
||||||
crosspost: Boolean(url.searchParams.get('crosspost')) ?? false,
|
|
||||||
})
|
export const load = ({ url }) => {
|
||||||
|
return { crosspost: Boolean(url.searchParams.get('crosspost')) ?? false }
|
||||||
|
}
|
||||||
@@ -30,9 +30,7 @@
|
|||||||
|
|
||||||
markingAsRead = true
|
markingAsRead = true
|
||||||
|
|
||||||
const response = await getClient().markAllAsRead({
|
const response = await getClient().markAllAsRead()
|
||||||
auth: $profile.jwt!,
|
|
||||||
})
|
|
||||||
|
|
||||||
$profile.user.unreads = 0
|
$profile.user.unreads = 0
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ export async function load({ url, fetch }) {
|
|||||||
const params = {
|
const params = {
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
auth: auth.jwt,
|
|
||||||
unread_only: unreadOnly == 'true',
|
unread_only: unreadOnly == 'true',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().createPrivateMessage({
|
await getClient().createPrivateMessage({
|
||||||
auth: $profile.jwt,
|
|
||||||
content: reply,
|
content: reply,
|
||||||
recipient_id: message.creator.id,
|
recipient_id: message.creator.id,
|
||||||
})
|
})
|
||||||
@@ -68,13 +67,11 @@
|
|||||||
|
|
||||||
if (item.type == 'person_mention') {
|
if (item.type == 'person_mention') {
|
||||||
await getClient().markPersonMentionAsRead({
|
await getClient().markPersonMentionAsRead({
|
||||||
auth: $profile?.jwt,
|
|
||||||
person_mention_id: item.id,
|
person_mention_id: item.id,
|
||||||
read: isRead,
|
read: isRead,
|
||||||
})
|
})
|
||||||
} else if (item.type == 'comment_reply') {
|
} else if (item.type == 'comment_reply') {
|
||||||
await getClient().markCommentReplyAsRead({
|
await getClient().markCommentReplyAsRead({
|
||||||
auth: $profile?.jwt,
|
|
||||||
comment_reply_id: item.id,
|
comment_reply_id: item.id,
|
||||||
read: isRead,
|
read: isRead,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,9 +3,6 @@ import { getClient } from '$lib/lemmy.js'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ fetch }) {
|
export async function load({ fetch }) {
|
||||||
return (
|
return (await getClient(undefined, fetch).getFederatedInstances())
|
||||||
await getClient(undefined, fetch).getFederatedInstances({
|
.federated_instances
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
|
||||||
).federated_instances
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { setUser } from '$lib/auth.js'
|
import { setUser } from '$lib/auth.js'
|
||||||
import { toast } from 'mono-svelte'
|
import { Note, toast } from 'mono-svelte'
|
||||||
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
import { DEFAULT_INSTANCE_URL, LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { getClient, validateInstance } from '$lib/lemmy.js'
|
import { getClient, validateInstance } from '$lib/lemmy.js'
|
||||||
import { Button, TextInput } from 'mono-svelte'
|
import { Button, TextInput } from 'mono-svelte'
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
Identification,
|
Identification,
|
||||||
QuestionMarkCircle,
|
QuestionMarkCircle,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
import { DOMAIN_REGEX_FORMS } from '$lib/util.js'
|
||||||
|
import { MINIMUM_VERSION } from '$lib/version.js'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: DEFAULT_INSTANCE_URL,
|
||||||
@@ -36,10 +38,12 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (response?.jwt) {
|
if (response?.jwt) {
|
||||||
await setUser(response.jwt, data.instance, data.username)
|
const result = await setUser(response.jwt, data.instance, data.username)
|
||||||
|
|
||||||
|
if (result) {
|
||||||
toast({ content: 'Successfully logged in.', type: 'success' })
|
toast({ content: 'Successfully logged in.', type: 'success' })
|
||||||
goto('/')
|
goto('/')
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid credentials')
|
throw new Error('Invalid credentials')
|
||||||
}
|
}
|
||||||
@@ -62,6 +66,13 @@
|
|||||||
<div class="flex flex-col gap-2">
|
<div class="flex flex-col gap-2">
|
||||||
<h1 class="font-bold text-3xl">Log In</h1>
|
<h1 class="font-bold text-3xl">Log In</h1>
|
||||||
<p>Enter the fediverse</p>
|
<p>Enter the fediverse</p>
|
||||||
|
<Note>
|
||||||
|
This version of Photon supports instances running
|
||||||
|
<span style="font-family: monospace;">
|
||||||
|
v{MINIMUM_VERSION}
|
||||||
|
</span>
|
||||||
|
or higher.
|
||||||
|
</Note>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-row w-full items-center gap-2">
|
<div class="flex flex-row w-full items-center gap-2">
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -81,7 +92,7 @@
|
|||||||
bind:value={data.instance}
|
bind:value={data.instance}
|
||||||
class="flex-1"
|
class="flex-1"
|
||||||
required
|
required
|
||||||
pattern={'(?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*.[A-Za-z]{2,6}'}
|
pattern={DOMAIN_REGEX_FORMS}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export async function load({ url, fetch }) {
|
|||||||
const client = getClient(undefined, fetch)
|
const client = getClient(undefined, fetch)
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
auth: jwt,
|
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
unresolved_only: type == 'unread',
|
unresolved_only: type == 'unread',
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
switch (item.type) {
|
switch (item.type) {
|
||||||
case 'comment': {
|
case 'comment': {
|
||||||
const res = await getClient().resolveCommentReport({
|
const res = await getClient().resolveCommentReport({
|
||||||
auth: $profile.jwt,
|
|
||||||
report_id: item.id,
|
report_id: item.id,
|
||||||
resolved: !item.resolved,
|
resolved: !item.resolved,
|
||||||
})
|
})
|
||||||
@@ -44,7 +43,6 @@
|
|||||||
}
|
}
|
||||||
case 'post': {
|
case 'post': {
|
||||||
const res = await getClient().resolvePostReport({
|
const res = await getClient().resolvePostReport({
|
||||||
auth: $profile.jwt,
|
|
||||||
report_id: item.id,
|
report_id: item.id,
|
||||||
resolved: !item.resolved,
|
resolved: !item.resolved,
|
||||||
})
|
})
|
||||||
@@ -61,7 +59,6 @@
|
|||||||
}
|
}
|
||||||
case 'message': {
|
case 'message': {
|
||||||
const res = await getClient().resolvePrivateMessageReport({
|
const res = await getClient().resolvePrivateMessageReport({
|
||||||
auth: $profile.jwt,
|
|
||||||
report_id: item.id,
|
report_id: item.id,
|
||||||
resolved: !item.resolved,
|
resolved: !item.resolved,
|
||||||
})
|
})
|
||||||
@@ -79,9 +76,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reports = await getClient().getReportCount({
|
const reports = await getClient().getReportCount({})
|
||||||
auth: $profile?.jwt,
|
|
||||||
})
|
|
||||||
|
|
||||||
$profile.user.reports =
|
$profile.user.reports =
|
||||||
reports.comment_reports +
|
reports.comment_reports +
|
||||||
|
|||||||
@@ -207,7 +207,6 @@ export async function load({ url }) {
|
|||||||
(url.searchParams.get('type') as ModlogActionType) || 'All'
|
(url.searchParams.get('type') as ModlogActionType) || 'All'
|
||||||
|
|
||||||
const results = await getClient().getModlog({
|
const results = await getClient().getModlog({
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
community_id: community,
|
community_id: community,
|
||||||
limit: 40,
|
limit: 40,
|
||||||
type_: type,
|
type_: type,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { instance } from '$lib/instance.js'
|
import { instance } from '$lib/instance.js'
|
||||||
|
import { getInstance } from '$lib/lemmy.js'
|
||||||
import { error, redirect } from '@sveltejs/kit'
|
import { error, redirect } from '@sveltejs/kit'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
@@ -6,7 +7,7 @@ export function load({ params, url }) {
|
|||||||
if (Number(params.instance)) {
|
if (Number(params.instance)) {
|
||||||
const split = url.pathname.split('/')
|
const split = url.pathname.split('/')
|
||||||
|
|
||||||
split.splice(2, 0, `${get(instance)?.toLowerCase()}`)
|
split.splice(2, 0, `${getInstance()?.toLowerCase()}`)
|
||||||
|
|
||||||
const newUrl = new URL(url)
|
const newUrl = new URL(url)
|
||||||
newUrl.pathname = split.join('/')
|
newUrl.pathname = split.join('/')
|
||||||
|
|||||||
@@ -49,7 +49,6 @@
|
|||||||
$profile?.jwt
|
$profile?.jwt
|
||||||
) {
|
) {
|
||||||
getClient().markPostAsRead({
|
getClient().markPostAsRead({
|
||||||
auth: $profile.jwt,
|
|
||||||
read: $userSettings.markPostsAsRead,
|
read: $userSettings.markPostsAsRead,
|
||||||
post_id: post.post_view.post.id,
|
post_id: post.post_view.post.id,
|
||||||
})
|
})
|
||||||
@@ -80,7 +79,6 @@
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await getClient().resolveObject({
|
const res = await getClient().resolveObject({
|
||||||
auth: jwt,
|
|
||||||
q: post.post_view.post.ap_id,
|
q: post.post_view.post.ap_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -105,7 +103,6 @@
|
|||||||
commentsPage = 1
|
commentsPage = 1
|
||||||
|
|
||||||
data.streamed.comments = getClient().getComments({
|
data.streamed.comments = getClient().getComments({
|
||||||
auth: $profile?.jwt,
|
|
||||||
page: 1,
|
page: 1,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { get } from 'svelte/store'
|
|||||||
export async function load({ params, url, fetch }) {
|
export async function load({ params, url, fetch }) {
|
||||||
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
|
const post = await getClient(params.instance.toLowerCase(), fetch).getPost({
|
||||||
id: Number(params.id),
|
id: Number(params.id),
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
let max_depth = post.post_view.counts.comments > 100 ? 1 : 3
|
||||||
@@ -38,7 +37,6 @@ export async function load({ params, url, fetch }) {
|
|||||||
max_depth: max_depth,
|
max_depth: max_depth,
|
||||||
saved_only: false,
|
saved_only: false,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
data.person_blocks = data.person_blocks
|
data.person_blocks = data.person_blocks
|
||||||
|
|
||||||
await getClient().blockPerson({
|
await getClient().blockPerson({
|
||||||
auth: $profile.jwt,
|
|
||||||
block: false,
|
block: false,
|
||||||
person_id: item.target.id,
|
person_id: item.target.id,
|
||||||
})
|
})
|
||||||
@@ -50,7 +49,6 @@
|
|||||||
data.community_blocks = data.community_blocks
|
data.community_blocks = data.community_blocks
|
||||||
|
|
||||||
await getClient().blockCommunity({
|
await getClient().blockCommunity({
|
||||||
auth: $profile.jwt,
|
|
||||||
block: false,
|
block: false,
|
||||||
community_id: item.community.id,
|
community_id: item.community.id,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
import { deleteProfile, profile, setUser } from '$lib/auth.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient, site } from '$lib/lemmy.js'
|
||||||
import { trycatch } from '$lib/util.js'
|
import { trycatch } from '$lib/util.js'
|
||||||
import { Button, Snippet, TextInput, toast } from 'mono-svelte'
|
import { Button, Snippet, TextInput, toast } from 'mono-svelte'
|
||||||
import { instance as currentInstance } from '$lib/instance.js'
|
import { instance as currentInstance } from '$lib/instance.js'
|
||||||
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
|
import { feature } from '$lib/version.js'
|
||||||
|
|
||||||
export let data
|
export let data
|
||||||
|
|
||||||
@@ -15,14 +16,18 @@
|
|||||||
newPasswordVerify = ''
|
newPasswordVerify = ''
|
||||||
let loading = false
|
let loading = false
|
||||||
|
|
||||||
$: totpLink = data.my_user?.local_user_view?.local_user?.totp_2fa_url
|
let verify_totp = ''
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
let totpLink: string | undefined = undefined
|
||||||
|
$: totpEnabled =
|
||||||
|
data.my_user?.local_user_view.local_user.totp_2fa_enabled ?? totpLink
|
||||||
|
|
||||||
async function changePassword() {
|
async function changePassword() {
|
||||||
try {
|
try {
|
||||||
if (!$profile?.jwt) return
|
if (!$profile?.jwt) return
|
||||||
loading = true
|
loading = true
|
||||||
const res = await getClient().changePassword({
|
const res = await getClient().changePassword({
|
||||||
auth: $profile?.jwt,
|
|
||||||
new_password: newPassword,
|
new_password: newPassword,
|
||||||
new_password_verify: newPasswordVerify,
|
new_password_verify: newPasswordVerify,
|
||||||
old_password: oldPassword,
|
old_password: oldPassword,
|
||||||
@@ -49,16 +54,28 @@
|
|||||||
loading = false
|
loading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function twofa(enabled: boolean) {
|
async function twofa(enabled: boolean, update: boolean = false) {
|
||||||
if (!$profile?.jwt) return
|
if (!$profile?.jwt) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await getClient().saveUserSettings({
|
if (feature('newTotp', $site?.version)) {
|
||||||
|
if (update) {
|
||||||
|
await getClient().updateTotp({
|
||||||
|
enabled: enabled,
|
||||||
|
totp_token: verify_totp,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
const res = await getClient().generateTotpSecret()
|
||||||
|
totpLink = res.totp_secret_url
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const res = await getClient().saveUserSettings({
|
||||||
...data.my_user?.local_user_view.local_user,
|
...data.my_user?.local_user_view.local_user,
|
||||||
...data.my_user?.local_user_view.person,
|
...data.my_user?.local_user_view.person,
|
||||||
|
// @ts-ignore
|
||||||
generate_totp_2fa: enabled,
|
generate_totp_2fa: enabled,
|
||||||
auth: $profile?.jwt,
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
goto($page.url, { invalidateAll: true })
|
goto($page.url, { invalidateAll: true })
|
||||||
toast({
|
toast({
|
||||||
content: `Successfully ${enabled ? 'enabled' : 'disabled'} 2FA.`,
|
content: `Successfully ${enabled ? 'enabled' : 'disabled'} 2FA.`,
|
||||||
@@ -105,7 +122,14 @@
|
|||||||
<h1 class="font-bold text-2xl">2FA</h1>
|
<h1 class="font-bold text-2xl">2FA</h1>
|
||||||
<p>
|
<p>
|
||||||
2FA on Lemmy is unstable and you may lock yourself out of your account.
|
2FA on Lemmy is unstable and you may lock yourself out of your account.
|
||||||
|
{#if feature('newTotp', $site?.version)}
|
||||||
|
<strong>
|
||||||
|
You cannot disable 2FA if you lose access to your authenticator.
|
||||||
|
</strong>
|
||||||
|
{/if}
|
||||||
</p>
|
</p>
|
||||||
|
{#if totpEnabled}
|
||||||
|
<!--v0.18.0 2FA: Shows a TOTP code which you copy-->
|
||||||
{#if totpLink}
|
{#if totpLink}
|
||||||
<TextInput disabled type="password" value={totpLink} label="TOTP Link">
|
<TextInput disabled type="password" value={totpLink} label="TOTP Link">
|
||||||
<button
|
<button
|
||||||
@@ -123,9 +147,24 @@
|
|||||||
Paste this in your authenticator app.
|
Paste this in your authenticator app.
|
||||||
</span>
|
</span>
|
||||||
</TextInput>
|
</TextInput>
|
||||||
<Button on:click={() => twofa(false)} size="lg" color="primary">
|
{/if}
|
||||||
|
<p>To change your 2FA state, enter your code here.</p>
|
||||||
|
<form class="flex flex-col gap-2" on:submit|preventDefault={() => {}}>
|
||||||
|
<TextInput
|
||||||
|
bind:value={verify_totp}
|
||||||
|
placeholder="012345"
|
||||||
|
label="2FA Code"
|
||||||
|
/>
|
||||||
|
{#if totpEnabled}
|
||||||
|
<Button on:click={() => twofa(false, true)} size="lg" color="primary">
|
||||||
Disable
|
Disable
|
||||||
</Button>
|
</Button>
|
||||||
|
{:else}
|
||||||
|
<Button on:click={() => twofa(true, true)} size="lg" color="primary">
|
||||||
|
Enable
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
</form>
|
||||||
{:else}
|
{:else}
|
||||||
<Button on:click={() => twofa(true)} size="lg" color="primary">
|
<Button on:click={() => twofa(true)} size="lg" color="primary">
|
||||||
Setup
|
Setup
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const res = await getClient().saveUserSettings({
|
const res = await getClient().saveUserSettings({
|
||||||
auth: $profile.jwt,
|
|
||||||
...formData,
|
...formData,
|
||||||
avatar: pfp,
|
avatar: pfp,
|
||||||
})
|
})
|
||||||
@@ -56,6 +55,7 @@
|
|||||||
let deletion = {
|
let deletion = {
|
||||||
modal: false,
|
modal: false,
|
||||||
password: '',
|
password: '',
|
||||||
|
deleteContent: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteAccount(level: number) {
|
async function deleteAccount(level: number) {
|
||||||
@@ -102,11 +102,10 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { jwt } = $profile
|
|
||||||
|
|
||||||
await getClient().deleteAccount({
|
await getClient().deleteAccount({
|
||||||
auth: jwt,
|
|
||||||
password: deletion.password,
|
password: deletion.password,
|
||||||
|
|
||||||
|
delete_content: deletion.deleteContent,
|
||||||
})
|
})
|
||||||
|
|
||||||
profileData.update((pd) => {
|
profileData.update((pd) => {
|
||||||
@@ -148,6 +147,12 @@
|
|||||||
type="password"
|
type="password"
|
||||||
bind:value={deletion.password}
|
bind:value={deletion.password}
|
||||||
/>
|
/>
|
||||||
|
<Checkbox bind:checked={deletion.deleteContent}>
|
||||||
|
Delete content
|
||||||
|
<span slot="description">
|
||||||
|
This will delete ALL of your account's posts and comments.
|
||||||
|
</span>
|
||||||
|
</Checkbox>
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ import type { SortType } from 'lemmy-js-client'
|
|||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ params, url, fetch }) {
|
export async function load({ params, url, fetch }) {
|
||||||
const my_user = (await getClient().getSite({ auth: get(profile)?.jwt }))
|
const my_user = (await getClient().getSite()).my_user
|
||||||
.my_user
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
my_user: my_user,
|
my_user: my_user,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export async function load({ url, fetch, parent }) {
|
|||||||
page: page,
|
page: page,
|
||||||
username: my_user?.local_user_view.person.name,
|
username: my_user?.local_user_view.person.name,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = [...user.posts, ...user.comments]
|
const items = [...user.posts, ...user.comments]
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { getClient } from '$lib/lemmy.js'
|
||||||
import type { CommentSortType, CommentView, ListingType, PostView, SortType } from 'lemmy-js-client'
|
import type {
|
||||||
|
CommentSortType,
|
||||||
|
CommentView,
|
||||||
|
ListingType,
|
||||||
|
PostView,
|
||||||
|
SortType,
|
||||||
|
} from 'lemmy-js-client'
|
||||||
import { get } from 'svelte/store'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
function getSavedItemPublished(item: PostView | CommentView) {
|
function getSavedItemPublished(item: PostView | CommentView) {
|
||||||
@@ -18,12 +24,11 @@ export async function load({ url, fetch }) {
|
|||||||
const client = getClient(undefined, fetch)
|
const client = getClient(undefined, fetch)
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
auth: get(profile)!.jwt!,
|
|
||||||
saved_only: true,
|
saved_only: true,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
sort: 'New' as SortType & CommentSortType,
|
sort: 'New' as SortType & CommentSortType,
|
||||||
type_: 'All' as ListingType
|
type_: 'All' as ListingType,
|
||||||
}
|
}
|
||||||
|
|
||||||
const [posts, comments] = await Promise.all([
|
const [posts, comments] = await Promise.all([
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export async function load({ url, fetch }) {
|
|||||||
if (query) {
|
if (query) {
|
||||||
const results = await getClient(undefined, fetch).search({
|
const results = await getClient(undefined, fetch).search({
|
||||||
q: query,
|
q: query,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
community_id: community ?? undefined,
|
community_id: community ?? undefined,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: page,
|
||||||
@@ -52,7 +51,6 @@ export async function load({ url, fetch }) {
|
|||||||
streamed: {
|
streamed: {
|
||||||
object: get(profile)?.jwt
|
object: get(profile)?.jwt
|
||||||
? getClient(undefined, fetch).resolveObject({
|
? getClient(undefined, fetch).resolveObject({
|
||||||
auth: get(profile)!.jwt!,
|
|
||||||
q: query,
|
q: query,
|
||||||
})
|
})
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|||||||
@@ -11,7 +11,9 @@
|
|||||||
Calendar,
|
Calendar,
|
||||||
ChartBar,
|
ChartBar,
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
EllipsisHorizontal,
|
||||||
Envelope,
|
Envelope,
|
||||||
|
Fire,
|
||||||
Icon,
|
Icon,
|
||||||
NoSymbol,
|
NoSymbol,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
@@ -23,9 +25,9 @@
|
|||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { isCommentView } from '$lib/lemmy/item.js'
|
import { isCommentView } from '$lib/lemmy/item.js'
|
||||||
import { getClient } from '$lib/lemmy.js'
|
import { client, getClient } from '$lib/lemmy.js'
|
||||||
import { isBlocked } from '$lib/lemmy/user.js'
|
import { isBlocked } from '$lib/lemmy/user.js'
|
||||||
import { Menu, MenuButton, Popover, toast } from 'mono-svelte'
|
import { Menu, MenuButton, Popover, removeToast, toast } from 'mono-svelte'
|
||||||
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
import UserLink from '$lib/components/lemmy/user/UserLink.svelte'
|
||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
import { ban, isAdmin } from '$lib/components/lemmy/moderation/moderation.js'
|
||||||
@@ -49,7 +51,6 @@
|
|||||||
const blocked = isBlocked($profile.user, block)
|
const blocked = isBlocked($profile.user, block)
|
||||||
|
|
||||||
await getClient().blockPerson({
|
await getClient().blockPerson({
|
||||||
auth: $profile.jwt,
|
|
||||||
block: !blocked,
|
block: !blocked,
|
||||||
person_id: block,
|
person_id: block,
|
||||||
})
|
})
|
||||||
@@ -79,6 +80,30 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
let messaging = false
|
let messaging = false
|
||||||
|
|
||||||
|
let purgingUser = false
|
||||||
|
let purgeEnabled = false
|
||||||
|
$: if (purgingUser) {
|
||||||
|
purgeEnabled = false
|
||||||
|
setTimeout(() => {
|
||||||
|
purgeEnabled = true
|
||||||
|
}, 3000)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function purgeUser() {
|
||||||
|
purgingUser = false
|
||||||
|
const purgeToast = toast({ content: 'Purging user...', loading: true })
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client().purgePerson({
|
||||||
|
person_id: data.person_view.person.id,
|
||||||
|
})
|
||||||
|
removeToast(purgeToast)
|
||||||
|
toast({ content: 'Purged that user.', type: 'success' })
|
||||||
|
} catch (e) {
|
||||||
|
toast({ content: e as any, type: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -92,6 +117,34 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if purgingUser}
|
||||||
|
<Modal bind:open={purgingUser}>
|
||||||
|
<svelte:fragment slot="title">Purging User</svelte:fragment>
|
||||||
|
<p>
|
||||||
|
Purging user <span class="font-bold">
|
||||||
|
{data.person_view.person.name}
|
||||||
|
</span>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
Are you sure you want to do this? (The button will enable in 3 seconds.)
|
||||||
|
</p>
|
||||||
|
<div class="flex flex-row gap-2">
|
||||||
|
<Button size="lg" on:click={() => (purgingUser = false)} class="flex-1">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="lg"
|
||||||
|
color="danger"
|
||||||
|
on:click={purgeUser}
|
||||||
|
disabled={!purgeEnabled}
|
||||||
|
class="flex-1"
|
||||||
|
>
|
||||||
|
Purge
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
{/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">
|
||||||
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
<div class="flex flex-col gap-4 max-w-full w-full min-w-0">
|
||||||
<div class="flex flex-row gap-4 flex-wrap justify-between">
|
<div class="flex flex-row gap-4 flex-wrap justify-between">
|
||||||
@@ -130,7 +183,7 @@
|
|||||||
<div
|
<div
|
||||||
class="!divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
class="!divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col"
|
||||||
>
|
>
|
||||||
{#each data.items as item (item.counts.id)}
|
{#each data.items as item}
|
||||||
{#if isCommentView(item) && (data.type == 'all' || data.type == 'comments')}
|
{#if isCommentView(item) && (data.type == 'all' || data.type == 'comments')}
|
||||||
<CommentItem comment={item} />
|
<CommentItem comment={item} />
|
||||||
{:else if !isCommentView(item) && (data.type == 'all' || data.type == 'posts')}
|
{:else if !isCommentView(item) && (data.type == 'all' || data.type == 'posts')}
|
||||||
@@ -223,19 +276,7 @@
|
|||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<div class="flex flex-row gap-2 ml-auto">
|
||||||
size="lg"
|
|
||||||
color="danger"
|
|
||||||
loading={blocking}
|
|
||||||
disabled={blocking}
|
|
||||||
on:click={() => blockUser(data.person_view.person.id)}
|
|
||||||
>
|
|
||||||
<Icon slot="prefix" mini size="16" src={NoSymbol} />
|
|
||||||
{isBlocked($profile.user, data.person_view.person.id)
|
|
||||||
? 'Unblock'
|
|
||||||
: 'Block'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{#if isAdmin($profile?.user)}
|
{#if isAdmin($profile?.user)}
|
||||||
<Menu class="ml-auto" origin="bottom-right">
|
<Menu class="ml-auto" origin="bottom-right">
|
||||||
<Button size="square-md" slot="target">
|
<Button size="square-md" slot="target">
|
||||||
@@ -244,13 +285,39 @@
|
|||||||
<MenuButton
|
<MenuButton
|
||||||
color="danger-subtle"
|
color="danger-subtle"
|
||||||
on:click={() =>
|
on:click={() =>
|
||||||
ban(data.person_view.person.banned, data.person_view.person)}
|
ban(
|
||||||
|
data.person_view.person.banned,
|
||||||
|
data.person_view.person
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
<Icon slot="prefix" mini size="16" src={ShieldExclamation} />
|
<Icon slot="prefix" mini size="16" src={ShieldExclamation} />
|
||||||
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
{data.person_view.person.banned ? 'Unban' : 'Ban'}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => (purgingUser = !purgingUser)}
|
||||||
|
>
|
||||||
|
<Icon slot="prefix" mini size="16" src={Fire} />
|
||||||
|
Purge
|
||||||
|
</MenuButton>
|
||||||
</Menu>
|
</Menu>
|
||||||
{/if}
|
{/if}
|
||||||
|
<Menu origin="bottom-right">
|
||||||
|
<Button size="square-md" slot="target">
|
||||||
|
<Icon src={EllipsisHorizontal} slot="prefix" size="16" mini />
|
||||||
|
</Button>
|
||||||
|
<MenuButton
|
||||||
|
color="danger-subtle"
|
||||||
|
on:click={() => blockUser(data.person_view.person.id)}
|
||||||
|
>
|
||||||
|
<Icon slot="prefix" mini size="16" src={NoSymbol} />
|
||||||
|
{isBlocked($profile.user, data.person_view.person.id)
|
||||||
|
? 'Unblock'
|
||||||
|
: 'Block'}
|
||||||
|
</MenuButton>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<div>
|
<div>
|
||||||
<h1 class="font-bold text-lg">
|
<h1 class="font-bold text-lg">
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ export async function load({ params, url, fetch }) {
|
|||||||
page: page,
|
page: page,
|
||||||
username: params.name,
|
username: params.name,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
auth: get(profile)?.jwt,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const items = [...user.posts, ...user.comments]
|
const items = [...user.posts, ...user.comments]
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { versionIsSupported } from '../src/lib/version.js'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
describe('versionIsSupported()', () => {
|
||||||
|
it('checks minimum correctly', () => {
|
||||||
|
expect(versionIsSupported('0.1.0', '0.0.0')).toBeTruthy()
|
||||||
|
expect(versionIsSupported('0.0.0', '0.1.0')).toBeFalsy()
|
||||||
|
})
|
||||||
|
it('checks weird minimum versions correctly', () => {
|
||||||
|
expect(versionIsSupported('0.19.0-rc.2', '0.19.0')).toBeTruthy()
|
||||||
|
expect(versionIsSupported('0.19.0.rc.9', '0.19.1')).toBeFalsy()
|
||||||
|
})
|
||||||
|
it('checks major and patch versions correctly', () => {
|
||||||
|
expect(versionIsSupported('2.0.0', '1.0.0')).toBeTruthy()
|
||||||
|
expect(versionIsSupported('0.0.2', '0.0.1')).toBeTruthy()
|
||||||
|
})
|
||||||
|
it('handles other cases', () => {
|
||||||
|
expect(versionIsSupported('2.0.2', '1.0.5')).toBeTruthy()
|
||||||
|
expect(versionIsSupported('9.5.2', '7.6.3')).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -2821,10 +2821,10 @@ kleur@^4.1.5:
|
|||||||
resolved "https://registry.yarnpkg.com/kleur/-/kleur-4.1.5.tgz#95106101795f7050c6c650f350c683febddb1780"
|
resolved "https://registry.yarnpkg.com/kleur/-/kleur-4.1.5.tgz#95106101795f7050c6c650f350c683febddb1780"
|
||||||
integrity sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==
|
integrity sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==
|
||||||
|
|
||||||
lemmy-js-client@^0.18.1:
|
lemmy-js-client@^0.19.0-rc.13:
|
||||||
version "0.18.1"
|
version "0.19.0-rc.13"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.18.1.tgz#28df266eded0ef4a72b05ee6eabebddadfd81a27"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.13.tgz#e0e15ba6fe3a08cb85130eea7eec4bd2773999f9"
|
||||||
integrity sha512-maafUZ9ZJkXthRZmM0+limJmymF2kmN/8SiKufS3V4OVNM72s+wUFFiyhKmA370g23iZRW6SUagE7jNKnqNyYQ==
|
integrity sha512-JP9oEh1+Wfttqx5O5EMAVIR/hFVS66iVKmEo8/Uxw8fJfyUeQo7BhKvG8LTYegBE39Womgyu3KxXb7Jy9DRI5A==
|
||||||
dependencies:
|
dependencies:
|
||||||
cross-fetch "^3.1.5"
|
cross-fetch "^3.1.5"
|
||||||
form-data "^4.0.0"
|
form-data "^4.0.0"
|
||||||
|
|||||||
Reference in new issue
Block a user