import m, {MithrilComponent} from '@garage44/mithril' import {Alert, Button} from '@garage44/mithril/components' import type {CommunityLink} from '@/types' import {$s} from '@/app' import {ProviderLogo} from '@/components/elements/providers/providers' import {begin, loadCommunityLinks, unlinkGroup} from '@/lib/auth' import {local} from '@/lib/reactive' import {formatUnix} from '@/lib/tokens' interface LinkedGroupsAttrs { id: string } /** * A community's linked Discord servers and subreddits, in its settings * (`docs/mockups/external-sign-in/v3-communities.html`, section 4): whoever * signs in through one is offered to join this community. * * For owners and moderators only, which the caller decides; the server checks * again. Linking is a round trip to the provider, because only the provider can * say which servers this person manages or which subreddits they moderate — so * the buttons leave the page, and `/welcome` brings the person back here. */ export class LinkedGroups extends MithrilComponent { s = local({busy: false, links: null as CommunityLink[] | null}) load = async (id: string) => { this.s.links = (await loadCommunityLinks(id)) ?? [] } oninit(vnode: m.Vnode) { void this.load(vnode.attrs.id) } view(vnode: m.Vnode) { const s = this.s const id = vnode.attrs.id // Only the providers the server has switched on can be linked. const linkable = ($s.registration?.providers ?? []).filter((p) => p.kind === 'discord' || p.kind === 'reddit') const links = s.links if (!linkable.length && !links?.length) return null return (

Linked groups

Members of these can join this community straight from sign-in.

{links === null &&

Loading…

} {links?.map((link) => (
{ProviderLogo({id: link.provider}, 20)}
{link.group_name} {link.provider === 'reddit' ? 'Subreddit' : `${link.provider_name} server`} · linked by{' '} {link.linked_by} · {formatUnix(link.linked_at, '')}
))} {linkable.length > 0 && (
{linkable.map((p) => ( ))}
)} {linkable.length > 0 && ( You can only link a Discord server you manage, or a subreddit you moderate. )}
) } }