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}}"
|
"switch": "Switch to an account on {{destInstance}}"
|
||||||
},
|
},
|
||||||
"automatic": {
|
"automatic": {
|
||||||
"title": "Locating post",
|
"title": "Locating content",
|
||||||
"description": "That content does not originate on your account's server."
|
"description": "Locating that content on your home server...",
|
||||||
|
"found": "Redirecting"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"inbox": {
|
"inbox": {
|
||||||
@@ -981,7 +982,8 @@
|
|||||||
"unsupported": "That function is not supported by your account's server software.",
|
"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.",
|
"not_live_supported": "That server is not running supported software, or is offline.",
|
||||||
"token_not_found": "That email verification link expired, or never existed.",
|
"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": {
|
"aria": {
|
||||||
"pagination": {
|
"pagination": {
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
|
import type { ClassValue } from 'svelte/elements'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: Snippet
|
children: Snippet
|
||||||
|
class?: ClassValue
|
||||||
}
|
}
|
||||||
|
|
||||||
let { children }: Props = $props()
|
let { children, class: clazz }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="text-loader font-medium text-lg tracking-tight"
|
class={['text-loader font-medium text-lg tracking-tight', clazz]}
|
||||||
aria-busy="true"
|
aria-busy="true"
|
||||||
aria-live="polite"
|
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 { profile } from '$lib/app/auth'
|
||||||
import { redirect } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ params }) {
|
||||||
if (profile.current.instance == params.instance)
|
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 { resolve } from '$app/paths'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
@@ -10,7 +11,6 @@ import {
|
|||||||
feeds,
|
feeds,
|
||||||
type FeedTypes,
|
type FeedTypes,
|
||||||
} from '$lib/feature/feeds/feed.svelte'
|
} from '$lib/feature/feeds/feed.svelte'
|
||||||
import { redirect } from '@sveltejs/kit'
|
|
||||||
|
|
||||||
function buildContext(thread?: string) {
|
function buildContext(thread?: string) {
|
||||||
let parentId: number | undefined
|
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 }) {
|
export async function load({ params, url, route }) {
|
||||||
if (profile.current.instance != params.instance)
|
if (profile.current.instance != params.instance) {
|
||||||
redirect(302, resolve('/post/[instance]/[id=integer]/confirm', params))
|
goto(resolve('/post/[instance]/[id=integer]/confirm', params), {
|
||||||
|
replaceState: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO use Lemmy profile default settings
|
// TODO use Lemmy profile default settings
|
||||||
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
const sort = settings?.defaultSort?.comments ?? 'Hot'
|
||||||
|
|||||||
@@ -9,95 +9,153 @@
|
|||||||
import ProfileButton from '$lib/feature/user/ProfileButton.svelte'
|
import ProfileButton from '$lib/feature/user/ProfileButton.svelte'
|
||||||
import { Header } from '$lib/ui/layout'
|
import { Header } from '$lib/ui/layout'
|
||||||
import SidebarButton from '$lib/ui/sidebar/SidebarButton.svelte'
|
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 { 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)
|
const fetched = $state.snapshot(profile.current.instance)
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!manual) fetchOnHome()
|
||||||
|
})
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (_state == 'error') manual = true
|
||||||
|
})
|
||||||
|
|
||||||
async function fetchOnHome() {
|
async function fetchOnHome() {
|
||||||
loading = true
|
const initialManual = manual
|
||||||
|
_state = 'loading'
|
||||||
try {
|
try {
|
||||||
const res = await client().resolveObject({
|
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) {
|
if ((type == 'post' && !res.post) || (type == 'comment' && !res.comment))
|
||||||
goto(
|
throw new Error('cant_find_object')
|
||||||
resolve(`/post/[instance]/[id=integer]`, {
|
if (initialManual != manual) return
|
||||||
instance: profile.current.instance,
|
|
||||||
id: res.post.post.id.toString(),
|
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) {
|
} catch (err) {
|
||||||
toast({ content: errorMessage(err), type: 'error' })
|
toast({ content: errorMessage(err), type: 'error' })
|
||||||
|
manual = true
|
||||||
|
_state = 'error'
|
||||||
}
|
}
|
||||||
loading = false
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-full h-full flex flex-col justify-center mx-auto max-w-xl gap-6">
|
<div class="w-full h-full flex flex-col justify-center mx-auto max-w-xl gap-6">
|
||||||
<header class="space-y-1">
|
{#if !manual}
|
||||||
<div
|
<header class="space-y-1">
|
||||||
class="font-mono bg-slate-100 dark:bg-zinc-950 rounded-xs p-0.5 px-1 w-max"
|
<Header>
|
||||||
>
|
<div class="grid w-full">
|
||||||
{page.params.instance}/post/{page.params.id}
|
{#if _state == 'loading'}
|
||||||
</div>
|
<div
|
||||||
<Header>
|
in:fly={{ easing: expoOut, duration: 300, y: 16 }}
|
||||||
{$t('routes.postRedirect.title')}
|
out:fly={{ easing: expoOut, duration: 300, x: 16 }}
|
||||||
</Header>
|
style="grid-column: 1; grid-row: 1;"
|
||||||
<p>
|
>
|
||||||
{$t('routes.postRedirect.description', {
|
<TextLoader class="text-3xl!">
|
||||||
homeInstance: fetched,
|
{$t('routes.postRedirect.automatic.title')}
|
||||||
})}
|
</TextLoader>
|
||||||
</p>
|
</div>
|
||||||
</header>
|
{:else if _state == 'found'}
|
||||||
<div class="flex flex-row items-center gap-2 flex-wrap">
|
<div
|
||||||
{#if profile.current.jwt}
|
in:fly={{ easing: expoOut, duration: 300, x: -16 }}
|
||||||
<Button
|
style="grid-column: 1; grid-row: 1;"
|
||||||
{loading}
|
>
|
||||||
disabled={loading}
|
<TextLoader class="text-3xl!">
|
||||||
size="lg"
|
{$t('routes.postRedirect.automatic.found')}
|
||||||
color="primary"
|
</TextLoader>
|
||||||
onclick={fetchOnHome}
|
</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,
|
homeInstance: fetched,
|
||||||
})}
|
})}
|
||||||
</Button>
|
</p>
|
||||||
{/if}
|
</header>
|
||||||
<Button size="lg" onclick={() => history.back()}>
|
<div class="flex flex-row items-center gap-2 flex-wrap">
|
||||||
{$t('routes.postRedirect.actions.back')}
|
{#if profile.current.jwt}
|
||||||
</Button>
|
<Button
|
||||||
</div>
|
loading={_state == 'loading'}
|
||||||
{#if profile.meta.profiles}
|
size="lg"
|
||||||
{@const filtered = profile.meta.profiles.filter(
|
color="primary"
|
||||||
(i) => i.instance == page.params.instance,
|
onclick={fetchOnHome}
|
||||||
)}
|
|
||||||
<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')}
|
{$t('routes.postRedirect.actions.fetch', {
|
||||||
</SidebarButton>
|
homeInstance: fetched,
|
||||||
</Material>
|
})}
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
<Button size="lg" onclick={() => history.back()}>
|
||||||
|
{$t('routes.postRedirect.actions.back')}
|
||||||
|
</Button>
|
||||||
</div>
|
</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}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
Reference in new issue
Block a user