feat: add remote instance subscribing

This commit is contained in:
James Xylight committed 2025-07-26 17:12:44 -07:00
1 parent 5e1d34cf2a
commit 9361dfb8a6
2 files changed
+20 -2

No files matched your search

@@ -22,6 +22,7 @@
import Subscribe from '../../../../routes/communities/Subscribe.svelte' import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import { settings } from '$lib/settings.svelte' import { settings } from '$lib/settings.svelte'
import type { Snippet } from 'svelte' import type { Snippet } from 'svelte'
import { client } from '$lib/lemmy.svelte'
let showInfo = $state(false) let showInfo = $state(false)
interface Props { interface Props {
@@ -31,6 +32,7 @@
class?: string class?: string
icon?: import('svelte').Snippet icon?: import('svelte').Snippet
children?: Snippet children?: Snippet
resolveObject?: boolean
} }
let { let {
@@ -40,6 +42,7 @@
class: clazz = 'flex flex-col gap-4 text-sm max-w-full relative', class: clazz = 'flex flex-col gap-4 text-sm max-w-full relative',
icon, icon,
children, children,
resolveObject,
}: Props = $props() }: Props = $props()
</script> </script>
@@ -160,7 +163,18 @@
disabled={subscribing || !profile.current?.jwt} disabled={subscribing || !profile.current?.jwt}
loading={subscribing} loading={subscribing}
onclick={async () => { onclick={async () => {
const res = await subscribe() const object =
resolveObject &&
(await client().resolveObject({
q: `!${community.community.name}@${new URL(community.community.actor_id).hostname}`,
}))
const res = object
? await subscribe(
object.community?.community.id,
'NotSubscribed',
)
: await subscribe()
if (res) { if (res) {
const newSubscribed = const newSubscribed =
+5 -1
View File
@@ -177,7 +177,11 @@
{@const sliced = data.communities.value.slice(showTop ? 3 : 0)} {@const sliced = data.communities.value.slice(showTop ? 3 : 0)}
<CommonList items={sliced}> <CommonList items={sliced}>
{#snippet item(community)} {#snippet item(community)}
<CommunityItem {community} showCounts={false} /> <CommunityItem
{community}
resolveObject={data.type.startsWith('instance-')}
showCounts={false}
/>
{/snippet} {/snippet}
</CommonList> </CommonList>
{/if} {/if}