diff --git a/megalodon/src/entities/account.ts b/megalodon/src/entities/account.ts index 0d8f34c59..ff40f75d2 100644 --- a/megalodon/src/entities/account.ts +++ b/megalodon/src/entities/account.ts @@ -31,4 +31,5 @@ export type Account = { source?: Source role?: Role mute_expires_at?: string + always_mark_nsfw?: boolean } diff --git a/megalodon/src/firefish.ts b/megalodon/src/firefish.ts index fa511c4d4..be4edcc5c 100644 --- a/megalodon/src/firefish.ts +++ b/megalodon/src/firefish.ts @@ -953,12 +953,26 @@ export default class Firefish implements MegalodonInterface { // accounts/preferences // ====================================== public async getPreferences(): Promise> { - return new Promise((_, reject) => { - const err = new NotImplementedError('Firefish does not support this method') - reject(err) + return this.client.post('/api/i').then(async res => { + return Object.assign(res, { + data: FirefishAPI.Converter.userPreferences(res.data, await this.getDefaultPostPrivacy()) + }) }) } + public async getDefaultPostPrivacy(): Promise { + return this.client + .post('/api/i/registry/get-unsecure', { + key: 'defaultNoteVisibility', + scope: ['client', 'base'] + }) + .then(res => { + if (!res.data || (res.data != 'public' && res.data != 'home' && res.data != 'followers' && res.data != 'specified')) return 'public' + return FirefishAPI.Converter.visibility(res.data) + }) + .catch(_ => 'public') + } + // ====================================== // accounts/followed_tags // ====================================== diff --git a/megalodon/src/firefish/api_client.ts b/megalodon/src/firefish/api_client.ts index ac96fdd32..b5e8e4559 100644 --- a/megalodon/src/firefish/api_client.ts +++ b/megalodon/src/firefish/api_client.ts @@ -34,6 +34,7 @@ namespace FirefishAPI { export type Relation = FirefishEntity.Relation export type User = FirefishEntity.User export type UserDetail = FirefishEntity.UserDetail + export type UserDetailMe = FirefishEntity.UserDetailMe export type Session = FirefishEntity.Session export type Stats = FirefishEntity.Stats export type Instance = FirefishEntity.Instance @@ -133,6 +134,25 @@ namespace FirefishAPI { } } + export const userDetailMe = (u: Entity.UserDetailMe): MegalodonEntity.Account => { + const account = userDetail(u) + account.always_mark_nsfw = u.alwaysMarkNsfw + return account + } + + export const userPreferences = ( + u: FirefishAPI.Entity.UserDetailMe, + v: 'public' | 'unlisted' | 'private' | 'direct' + ): MegalodonEntity.Preferences => { + return { + 'reading:expand:media': 'default', + 'reading:expand:spoilers': false, + 'posting:default:language': u.lang, + 'posting:default:sensitive': u.alwaysMarkNsfw, + 'posting:default:visibility': v + } + } + export const visibility = ( v: 'public' | 'home' | 'followers' | 'specified' | 'hidden' ): 'public' | 'unlisted' | 'private' | 'direct' => { diff --git a/megalodon/src/firefish/entities/userDetail.ts b/megalodon/src/firefish/entities/userDetail.ts index 8f185ac77..3df5be1f0 100644 --- a/megalodon/src/firefish/entities/userDetail.ts +++ b/megalodon/src/firefish/entities/userDetail.ts @@ -45,3 +45,7 @@ export type UserDetail = { isMuted?: boolean isRenoteMuted?: boolean } + +export type UserDetailMe = UserDetail & { + alwaysMarkNsfw: boolean +} diff --git a/megalodon/src/firefish/entity.ts b/megalodon/src/firefish/entity.ts index 07f277e29..6ea5cccd5 100644 --- a/megalodon/src/firefish/entity.ts +++ b/megalodon/src/firefish/entity.ts @@ -51,6 +51,7 @@ export namespace Entity { export type Stats = stats.Stats export type User = user.User export type UserDetail = user_detail.UserDetail + export type UserDetailMe = user_detail.UserDetailMe } export default Entity diff --git a/megalodon/src/friendica.ts b/megalodon/src/friendica.ts index aa3c44548..a60c1c4fb 100644 --- a/megalodon/src/friendica.ts +++ b/megalodon/src/friendica.ts @@ -1145,6 +1145,13 @@ export default class Friendica implements MegalodonInterface { }) } + public async getDefaultPostPrivacy(): Promise { + return new Promise((_, reject) => { + const err = new NotImplementedError('Friendica does not support this method') + reject(err) + }) + } + // ====================================== // accounts/followed_tags // ====================================== diff --git a/megalodon/src/mastodon.ts b/megalodon/src/mastodon.ts index 98437c2fd..89c58ec20 100644 --- a/megalodon/src/mastodon.ts +++ b/megalodon/src/mastodon.ts @@ -1403,6 +1403,13 @@ export default class Mastodon implements MegalodonInterface { }) } + public async getDefaultPostPrivacy(): Promise { + return new Promise((_, reject) => { + const err = new NotImplementedError('Mastodon does not support this method') + reject(err) + }) + } + // ====================================== // accounts/followed_tags // ====================================== diff --git a/megalodon/src/megalodon.ts b/megalodon/src/megalodon.ts index fc9a158fe..a38c67365 100644 --- a/megalodon/src/megalodon.ts +++ b/megalodon/src/megalodon.ts @@ -601,6 +601,13 @@ export interface MegalodonInterface { * @return Preferences. */ getPreferences(): Promise> + + /** + * Get the default post privacy defined by the user in their account settings. Firefish only. + * + * @return Preferences. + */ + getDefaultPostPrivacy(): Promise // ====================================== // accounts/followed_tags // ====================================== diff --git a/megalodon/src/pleroma.ts b/megalodon/src/pleroma.ts index d0ad245cf..b2dee684a 100644 --- a/megalodon/src/pleroma.ts +++ b/megalodon/src/pleroma.ts @@ -1400,6 +1400,13 @@ export default class Pleroma implements MegalodonInterface { }) } + public async getDefaultPostPrivacy(): Promise { + return new Promise((_, reject) => { + const err = new NotImplementedError('Pleroma does not support this method') + reject(err) + }) + } + // ====================================== // accounts/followed_tags // ======================================