fix: user acct not respecting domain (#2088)
This commit is contained in:
parent
f28c90498b
commit
29f6a73de1
2 changed files with 31 additions and 5 deletions
|
@ -209,8 +209,10 @@ export async function fetchAccountInfo(client: mastodon.Client, server: string)
|
|||
fetchPrefs(),
|
||||
])
|
||||
|
||||
if (!account.acct.includes('@'))
|
||||
account.acct = `${account.acct}@${server}`
|
||||
if (!account.acct.includes('@')) {
|
||||
const webDomain = getInstanceDomainFromServer(server)
|
||||
account.acct = `${account.acct}@${webDomain}`
|
||||
}
|
||||
|
||||
// TODO: lazy load preferences
|
||||
accountPreferencesMap.set(account.acct, preferences)
|
||||
|
@ -219,6 +221,12 @@ export async function fetchAccountInfo(client: mastodon.Client, server: string)
|
|||
return account
|
||||
}
|
||||
|
||||
export function getInstanceDomainFromServer(server: string) {
|
||||
const instance = getInstanceCache(server)
|
||||
const webDomain = instance ? getInstanceDomain(instance) : server
|
||||
return webDomain
|
||||
}
|
||||
|
||||
export async function refreshAccountInfo() {
|
||||
const account = await fetchAccountInfo(useMastoClient(), currentServer.value)
|
||||
currentUser.value!.account = account
|
||||
|
@ -340,10 +348,28 @@ export function useUserLocalStorage<T extends object>(key: string, initial: () =
|
|||
const scope = effectScope(true)
|
||||
const value = scope.run(() => {
|
||||
const all = useLocalStorage<Record<string, T>>(key, {}, { deep: true })
|
||||
|
||||
return computed(() => {
|
||||
const id = currentUser.value?.account.id
|
||||
? currentUser.value.account.acct
|
||||
: '[anonymous]'
|
||||
|
||||
// Backward compatibility, respect webDomain in acct
|
||||
// In previous versions, acct was username@server instead of username@webDomain
|
||||
// for example: elk@m.webtoo.ls instead of elk@webtoo.ls
|
||||
if (!all.value[id]) {
|
||||
const [username, webDomain] = id.split('@')
|
||||
const server = currentServer.value
|
||||
if (webDomain && server && server !== webDomain) {
|
||||
const oldId = `${username}@${server}`
|
||||
const outdatedSettings = all.value[oldId]
|
||||
if (outdatedSettings) {
|
||||
const newAllValue = { ...all.value, [id]: outdatedSettings }
|
||||
delete newAllValue[oldId]
|
||||
all.value = newAllValue
|
||||
}
|
||||
}
|
||||
}
|
||||
all.value[id] = Object.assign(initial(), all.value[id] || {})
|
||||
return all.value[id]
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue