feat: automatically load cross-server content on home instance
This commit is contained in:
8 files changed
+149
-183
No files matched your search
@@ -342,8 +342,9 @@
|
||||
"switch": "Switch to an account on {{destInstance}}"
|
||||
},
|
||||
"automatic": {
|
||||
"title": "Locating post",
|
||||
"description": "That content does not originate on your account's server."
|
||||
"title": "Locating content",
|
||||
"description": "Locating that content on your home server...",
|
||||
"found": "Redirecting"
|
||||
}
|
||||
},
|
||||
"inbox": {
|
||||
@@ -981,7 +982,8 @@
|
||||
"unsupported": "That function is not supported by your account's server software.",
|
||||
"not_live_supported": "That server is not running supported software, or is offline.",
|
||||
"token_not_found": "That email verification link expired, or never existed.",
|
||||
"invalid_password": "Invalid password."
|
||||
"invalid_password": "Invalid password.",
|
||||
"cant_find_object": "That content couldn't be found on your home server."
|
||||
},
|
||||
"aria": {
|
||||
"pagination": {
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props {
|
||||
children: Snippet
|
||||
class?: ClassValue
|
||||
}
|
||||
|
||||
let { children }: Props = $props()
|
||||
let { children, class: clazz }: Props = $props()
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="text-loader font-medium text-lg tracking-tight"
|
||||
class={['text-loader font-medium text-lg tracking-tight', clazz]}
|
||||
aria-busy="true"
|
||||
aria-live="polite"
|
||||
>
|
||||
|
||||
File renamed without changes.
@@ -0,0 +1,5 @@
|
||||
<script lang="ts">
|
||||
import PostConfirmPage from '../../../../post/[instance]/[id=integer]/confirm/+page.svelte'
|
||||
</script>
|
||||
|
||||
<PostConfirmPage type="comment" />
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { profile } from '$lib/app/auth'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
export async function load({ params }) {
|
||||
if (profile.current.instance == params.instance)
|
||||
redirect(302, `/comment/${params.instance}/${params.id}`)
|
||||
goto(`/comment/${params.instance}/${params.id}`, { replaceState: true })
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation'
|
||||
import { resolve } from '$app/paths'
|
||||
import { page } from '$app/state'
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { profile } from '$lib/app/auth'
|
||||
import { errorMessage } from '$lib/app/error'
|
||||
import { t } from '$lib/app/i18n'
|
||||
import ProfileButton from '$lib/feature/user/ProfileButton.svelte'
|
||||
import { Header } from '$lib/ui/layout'
|
||||
import SidebarButton from '$lib/ui/sidebar/SidebarButton.svelte'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Plus } from 'svelte-hero-icons/dist'
|
||||
|
||||
let loading = $state(false)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
try {
|
||||
const res = await client().resolveObject({
|
||||
q: `https://${page.params.instance}/comment/${page.params.id}`,
|
||||
})
|
||||
|
||||
if (res.comment) {
|
||||
goto(
|
||||
resolve(`/comment/[instance]/[id]`, {
|
||||
instance: profile.current.instance,
|
||||
id: res.comment.comment.id.toString(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
} catch (err) {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full flex flex-col justify-center mx-auto max-w-xl gap-6">
|
||||
<header class="space-y-1">
|
||||
<div
|
||||
class="font-mono bg-slate-100 dark:bg-zinc-950 rounded-xs p-0.5 px-1 w-max"
|
||||
>
|
||||
{page.params.instance}/comment/{page.params.id}
|
||||
</div>
|
||||
<Header>
|
||||
{$t('routes.postRedirect.title')}
|
||||
</Header>
|
||||
<p>
|
||||
{$t('routes.postRedirect.description', {
|
||||
homeInstance: fetched,
|
||||
})}
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
size="md"
|
||||
rounding="pill"
|
||||
color="primary"
|
||||
onclick={fetchOnHome}
|
||||
>
|
||||
{$t('routes.postRedirect.actions.fetch', {
|
||||
homeInstance: fetched,
|
||||
})}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button size="md" rounding="pill" onclick={() => history.back()}>
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
{#if profile.meta.profiles}
|
||||
{@const filtered = profile.meta.profiles.filter(
|
||||
(i) => i.instance == page.params.instance,
|
||||
)}
|
||||
<div class="space-y-1">
|
||||
<div class="font-medium text-sm">
|
||||
{$t('routes.postRedirect.actions.switch', {
|
||||
destInstance: page.params.instance,
|
||||
})}
|
||||
</div>
|
||||
<Material
|
||||
color="uniform"
|
||||
padding="sm"
|
||||
rounding="2xl"
|
||||
class="dark:bg-zinc-950 max-h-96 overflow-auto"
|
||||
>
|
||||
{#each filtered as profile (profile.id)}
|
||||
<ProfileButton prof={profile} />
|
||||
{/each}
|
||||
<SidebarButton
|
||||
href="/accounts/login/guest?redirect={page.url}"
|
||||
icon={Plus}
|
||||
class="rounded-lg"
|
||||
>
|
||||
{$t('account.addGuest')}
|
||||
</SidebarButton>
|
||||
</Material>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -1,3 +1,4 @@
|
||||
import { goto } from '$app/navigation'
|
||||
import { resolve } from '$app/paths'
|
||||
import { client } from '$lib/api/client.svelte'
|
||||
import { profile } from '$lib/app/auth'
|
||||
@@ -10,7 +11,6 @@ import {
|
||||
feeds,
|
||||
type FeedTypes,
|
||||
} from '$lib/feature/feeds/feed.svelte'
|
||||
import { redirect } from '@sveltejs/kit'
|
||||
|
||||
function buildContext(thread?: string) {
|
||||
let parentId: number | undefined
|
||||
@@ -50,8 +50,11 @@ async function findInFeed(id: '/' | '/c/[name]' | '/f/[id]', postId: string) {
|
||||
}
|
||||
|
||||
export async function load({ params, url, route }) {
|
||||
if (profile.current.instance != params.instance)
|
||||
redirect(302, resolve('/post/[instance]/[id=integer]/confirm', params))
|
||||
if (profile.current.instance != params.instance) {
|
||||
goto(resolve('/post/[instance]/[id=integer]/confirm', params), {
|
||||
replaceState: true,
|
||||
})
|
||||
}
|
||||
|
||||
// TODO use Lemmy profile default settings
|
||||
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
||||
|
||||
@@ -9,95 +9,153 @@
|
||||
import ProfileButton from '$lib/feature/user/ProfileButton.svelte'
|
||||
import { Header } from '$lib/ui/layout'
|
||||
import SidebarButton from '$lib/ui/sidebar/SidebarButton.svelte'
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Button, Material, TextLoader, toast } from 'mono-svelte'
|
||||
import { Plus } from 'svelte-hero-icons/dist'
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
let loading = $state(false)
|
||||
interface Props {
|
||||
type?: 'post' | 'comment'
|
||||
}
|
||||
|
||||
let { type = 'post' }: Props = $props()
|
||||
|
||||
let _state = $state<'loading' | 'found' | 'error' | 'none'>('loading')
|
||||
let manual = $state(false)
|
||||
const fetched = $state.snapshot(profile.current.instance)
|
||||
|
||||
$effect(() => {
|
||||
if (!manual) fetchOnHome()
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (_state == 'error') manual = true
|
||||
})
|
||||
|
||||
async function fetchOnHome() {
|
||||
loading = true
|
||||
const initialManual = manual
|
||||
_state = 'loading'
|
||||
try {
|
||||
const res = await client().resolveObject({
|
||||
q: `https://${page.params.instance}/post/${page.params.id}`,
|
||||
q: `https://${page.params.instance}/${type}/${page.params.id}`,
|
||||
})
|
||||
|
||||
if (res.post) {
|
||||
goto(
|
||||
resolve(`/post/[instance]/[id=integer]`, {
|
||||
instance: profile.current.instance,
|
||||
id: res.post.post.id.toString(),
|
||||
}),
|
||||
)
|
||||
}
|
||||
if ((type == 'post' && !res.post) || (type == 'comment' && !res.comment))
|
||||
throw new Error('cant_find_object')
|
||||
if (initialManual != manual) return
|
||||
|
||||
goto(
|
||||
resolve(`/${type}/[instance]/[id=integer]`, {
|
||||
instance: profile.current.instance,
|
||||
id:
|
||||
type == 'post'
|
||||
? res.post!.post.id.toString()
|
||||
: res.comment!.comment.id.toString(),
|
||||
}),
|
||||
{ replaceState: true },
|
||||
)
|
||||
_state = 'found'
|
||||
} catch (err) {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
manual = true
|
||||
_state = 'error'
|
||||
}
|
||||
loading = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="w-full h-full flex flex-col justify-center mx-auto max-w-xl gap-6">
|
||||
<header class="space-y-1">
|
||||
<div
|
||||
class="font-mono bg-slate-100 dark:bg-zinc-950 rounded-xs p-0.5 px-1 w-max"
|
||||
>
|
||||
{page.params.instance}/post/{page.params.id}
|
||||
</div>
|
||||
<Header>
|
||||
{$t('routes.postRedirect.title')}
|
||||
</Header>
|
||||
<p>
|
||||
{$t('routes.postRedirect.description', {
|
||||
homeInstance: fetched,
|
||||
})}
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
{loading}
|
||||
disabled={loading}
|
||||
size="lg"
|
||||
color="primary"
|
||||
onclick={fetchOnHome}
|
||||
{#if !manual}
|
||||
<header class="space-y-1">
|
||||
<Header>
|
||||
<div class="grid w-full">
|
||||
{#if _state == 'loading'}
|
||||
<div
|
||||
in:fly={{ easing: expoOut, duration: 300, y: 16 }}
|
||||
out:fly={{ easing: expoOut, duration: 300, x: 16 }}
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
>
|
||||
<TextLoader class="text-3xl!">
|
||||
{$t('routes.postRedirect.automatic.title')}
|
||||
</TextLoader>
|
||||
</div>
|
||||
{:else if _state == 'found'}
|
||||
<div
|
||||
in:fly={{ easing: expoOut, duration: 300, x: -16 }}
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
>
|
||||
<TextLoader class="text-3xl!">
|
||||
{$t('routes.postRedirect.automatic.found')}
|
||||
</TextLoader>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</Header>
|
||||
<p></p>
|
||||
<Button color="secondary" size="lg" onclick={() => (manual = true)}>
|
||||
{$t('common.cancel')}
|
||||
</Button>
|
||||
</header>
|
||||
{:else}
|
||||
<header class="space-y-1">
|
||||
<div
|
||||
class="font-mono bg-slate-100 dark:bg-zinc-950 rounded-xs p-0.5 px-1 w-max"
|
||||
>
|
||||
{$t('routes.postRedirect.actions.fetch', {
|
||||
{page.params.instance}/{type}/{page.params.id}
|
||||
</div>
|
||||
<Header>
|
||||
{$t('routes.postRedirect.title')}
|
||||
</Header>
|
||||
<p>
|
||||
{$t('routes.postRedirect.description', {
|
||||
homeInstance: fetched,
|
||||
})}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button size="lg" onclick={() => history.back()}>
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
{#if profile.meta.profiles}
|
||||
{@const filtered = profile.meta.profiles.filter(
|
||||
(i) => i.instance == page.params.instance,
|
||||
)}
|
||||
<div class="space-y-1">
|
||||
<div class="font-medium text-sm">
|
||||
{$t('routes.postRedirect.actions.switch', {
|
||||
destInstance: page.params.instance,
|
||||
})}
|
||||
</div>
|
||||
<Material
|
||||
color="uniform"
|
||||
padding="sm"
|
||||
rounding="2xl"
|
||||
class="dark:bg-zinc-950 max-h-96 overflow-auto"
|
||||
>
|
||||
{#each filtered as profile (profile.id)}
|
||||
<ProfileButton prof={profile} />
|
||||
{/each}
|
||||
<SidebarButton
|
||||
href="/accounts/login/guest?redirect={page.url}"
|
||||
icon={Plus}
|
||||
class="rounded-lg"
|
||||
</p>
|
||||
</header>
|
||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||
{#if profile.current.jwt}
|
||||
<Button
|
||||
loading={_state == 'loading'}
|
||||
size="lg"
|
||||
color="primary"
|
||||
onclick={fetchOnHome}
|
||||
>
|
||||
{$t('account.addGuest')}
|
||||
</SidebarButton>
|
||||
</Material>
|
||||
{$t('routes.postRedirect.actions.fetch', {
|
||||
homeInstance: fetched,
|
||||
})}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button size="lg" onclick={() => history.back()}>
|
||||
{$t('routes.postRedirect.actions.back')}
|
||||
</Button>
|
||||
</div>
|
||||
{#if profile.meta.profiles}
|
||||
{@const filtered = profile.meta.profiles.filter(
|
||||
(i) => i.instance == page.params.instance,
|
||||
)}
|
||||
<div class="space-y-1">
|
||||
<div class="font-medium text-sm">
|
||||
{$t('routes.postRedirect.actions.switch', {
|
||||
destInstance: page.params.instance,
|
||||
})}
|
||||
</div>
|
||||
<Material
|
||||
color="uniform"
|
||||
padding="sm"
|
||||
rounding="2xl"
|
||||
class="dark:bg-zinc-950 max-h-96 overflow-auto"
|
||||
>
|
||||
{#each filtered as profile (profile.id)}
|
||||
<ProfileButton prof={profile} />
|
||||
{/each}
|
||||
<SidebarButton
|
||||
href="/accounts/login/guest?redirect={page.url}"
|
||||
icon={Plus}
|
||||
class="rounded-lg"
|
||||
>
|
||||
{$t('account.addGuest')}
|
||||
</SidebarButton>
|
||||
</Material>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
Reference in new issue
Block a user