feat: respect Media Display preferences (#2065)

This commit is contained in:
Ayo Ayco 2023-05-05 18:12:07 +02:00 committed by GitHub
parent a3116e703a
commit d9e7a09d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 10 deletions

View file

@ -170,10 +170,28 @@ export async function loginTo(masto: ElkMasto, user: Overwrite<UserLogin, { acco
}
const accountPreferencesMap = new Map<string, mastodon.v1.Preference>()
/**
* @returns `true` when user ticked the preference to always expand posts with content warnings
*/
export function getExpandSpoilersByDefault(account: mastodon.v1.AccountCredentials) {
return accountPreferencesMap.get(account.acct)?.['reading:expand:spoilers'] ?? false
}
/**
* @returns `true` when user selected "Always show media" as Media Display preference
*/
export function getExpandMediaByDefault(account: mastodon.v1.AccountCredentials) {
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'show_all' ?? false
}
/**
* @returns `true` when user selected "Always hide media" as Media Display preference
*/
export function getHideMediaByDefault(account: mastodon.v1.AccountCredentials) {
return accountPreferencesMap.get(account.acct)?.['reading:expand:media'] === 'hide_all' ?? false
}
export async function fetchAccountInfo(client: mastodon.Client, server: string) {
const [account, preferences] = await Promise.all([
client.v1.accounts.verifyCredentials(),