mirror of
https://github.com/elk-zone/elk
synced 2024-11-23 22:56:09 +09:00
fix: Handle failure when fetching user preferences (#2069)
This commit is contained in:
parent
d9e7a09d24
commit
1487932c1d
@ -169,7 +169,7 @@ export async function loginTo(masto: ElkMasto, user: Overwrite<UserLogin, { acco
|
||||
currentUserHandle.value = me.acct
|
||||
}
|
||||
|
||||
const accountPreferencesMap = new Map<string, mastodon.v1.Preference>()
|
||||
const accountPreferencesMap = new Map<string, Partial<mastodon.v1.Preference>>()
|
||||
|
||||
/**
|
||||
* @returns `true` when user ticked the preference to always expand posts with content warnings
|
||||
@ -193,9 +193,20 @@ export function getHideMediaByDefault(account: mastodon.v1.AccountCredentials) {
|
||||
}
|
||||
|
||||
export async function fetchAccountInfo(client: mastodon.Client, server: string) {
|
||||
// Try to fetch user preferences if the backend supports it.
|
||||
const fetchPrefs = async (): Promise<Partial<mastodon.v1.Preference>> => {
|
||||
try {
|
||||
return await client.v1.preferences.fetch()
|
||||
}
|
||||
catch (e) {
|
||||
console.warn(`Cannot fetch preferences: ${e}`)
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
const [account, preferences] = await Promise.all([
|
||||
client.v1.accounts.verifyCredentials(),
|
||||
client.v1.preferences.fetch(),
|
||||
fetchPrefs(),
|
||||
])
|
||||
|
||||
if (!account.acct.includes('@'))
|
||||
|
Loading…
Reference in New Issue
Block a user