diff --git a/composables/cache.ts b/composables/cache.ts index 05aa7d4d..e080ce11 100644 --- a/composables/cache.ts +++ b/composables/cache.ts @@ -43,7 +43,7 @@ export function fetchAccountById(id?: string | null): Promise<mastodon.v1.Accoun const cached = cache.get(key) if (cached) return cached - const domain = currentInstance.value?.uri + const domain = currentInstance.value ? getInstanceDomain(currentInstance.value) : null const promise = useMastoClient().v1.accounts.fetch(id) .then((r) => { if (r.acct && !r.acct.includes('@') && domain) @@ -63,7 +63,7 @@ export async function fetchAccountByHandle(acct: string): Promise<mastodon.v1.Ac const cached = cache.get(key) if (cached) return cached - const domain = currentInstance.value?.uri + const domain = currentInstance.value ? getInstanceDomain(currentInstance.value) : undefined async function lookupAccount() { const client = useMastoClient() diff --git a/composables/masto/account.ts b/composables/masto/account.ts index a5736a08..2abb5a43 100644 --- a/composables/masto/account.ts +++ b/composables/masto/account.ts @@ -17,7 +17,7 @@ export function getServerName(account: mastodon.v1.Account) { if (account.acct?.includes('@')) return account.acct.split('@')[1] // We should only lack the server name if we're on the same server as the account - return currentInstance.value?.uri || '' + return currentInstance.value ? getInstanceDomain(currentInstance.value) : '' } export function getFullHandle(account: mastodon.v1.Account) { @@ -38,7 +38,7 @@ export function toShortHandle(fullHandle: string) { export function extractAccountHandle(account: mastodon.v1.Account) { let handle = getFullHandle(account).slice(1) - const uri = currentInstance.value?.uri ?? currentServer.value + const uri = currentInstance.value ? getInstanceDomain(currentInstance.value) : currentServer.value if (currentInstance.value && handle.endsWith(`@${uri}`)) handle = handle.slice(0, -uri.length - 1) diff --git a/composables/masto/masto.ts b/composables/masto/masto.ts index 1fd8b54b..c9726830 100644 --- a/composables/masto/masto.ts +++ b/composables/masto/masto.ts @@ -34,7 +34,7 @@ export function mastoLogin(masto: ElkMasto, user: Pick<UserLogin, 'server' | 'to const server = user.server const url = `https://${server}` - const instance: ElkInstance = reactive(getInstanceCache(server) || { uri: server }) + const instance: ElkInstance = reactive(getInstanceCache(server) || { uri: server, accountDomain: server }) setParams({ url, accessToken: user?.token, diff --git a/composables/users.ts b/composables/users.ts index 2a9d8a60..59e127f2 100644 --- a/composables/users.ts +++ b/composables/users.ts @@ -47,7 +47,11 @@ export const instances = useLocalStorage<Record<string, mastodon.v1.Instance>>(S export const nodes = useLocalStorage<Record<string, any>>(STORAGE_KEY_NODES, {}, { deep: true }) const currentUserId = useLocalStorage<string>(STORAGE_KEY_CURRENT_USER, mock ? mock.user.account.id : '') -export type ElkInstance = Partial<mastodon.v1.Instance> & { uri: string } +export type ElkInstance = Partial<mastodon.v1.Instance> & { + uri: string + /** support GoToSocial */ + accountDomain?: string | null +} export const getInstanceCache = (server: string): mastodon.v1.Instance | undefined => instances.value[server] export const currentUser = computed<UserLogin | undefined>(() => { @@ -63,6 +67,10 @@ export const currentUser = computed<UserLogin | undefined>(() => { const publicInstance = ref<ElkInstance | null>(null) export const currentInstance = computed<null | ElkInstance>(() => currentUser.value ? instances.value[currentUser.value.server] ?? null : publicInstance.value) +export function getInstanceDomain(instance: ElkInstance) { + return instance.accountDomain || instance.uri +} + export const publicServer = ref('') export const currentServer = computed<string>(() => currentUser.value?.server || publicServer.value)