diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/labeling/helpers.ts | 94 | ||||
-rw-r--r-- | src/lib/labeling/types.ts | 4 | ||||
-rw-r--r-- | src/lib/routes/types.ts | 1 |
3 files changed, 94 insertions, 5 deletions
diff --git a/src/lib/labeling/helpers.ts b/src/lib/labeling/helpers.ts index 0092b99e4..5ec591cfb 100644 --- a/src/lib/labeling/helpers.ts +++ b/src/lib/labeling/helpers.ts @@ -57,6 +57,7 @@ export function getPostModeration( let avatar = { warn: accountPref.pref === 'hide' || accountPref.pref === 'warn', blur: + postInfo.isBlocking || accountPref.pref === 'hide' || accountPref.pref === 'warn' || profilePref.pref === 'hide' || @@ -75,6 +76,22 @@ export function getPostModeration( } // hide cases + if (postInfo.isBlocking) { + return { + avatar, + list: hide('Post from an account you blocked.'), + thread: hide('Post from an account you blocked.'), + view: warn('Post from an account you blocked.'), + } + } + if (postInfo.isBlockedBy) { + return { + avatar, + list: hide('Post from an account that has blocked you.'), + thread: hide('Post from an account that has blocked you.'), + view: warn('Post from an account that has blocked you.'), + } + } if (accountPref.pref === 'hide') { return { avatar, @@ -144,21 +161,45 @@ export function getPostModeration( } } +export function mergePostModerations( + moderations: PostModeration[], +): PostModeration { + const merged: PostModeration = { + avatar: {warn: false, blur: false}, + list: show(), + thread: show(), + view: show(), + } + for (const mod of moderations) { + if (mod.list.behavior === ModerationBehaviorCode.Hide) { + merged.list = mod.list + } + if (mod.thread.behavior === ModerationBehaviorCode.Hide) { + merged.thread = mod.thread + } + if (mod.view.behavior === ModerationBehaviorCode.Hide) { + merged.view = mod.view + } + } + return merged +} + export function getProfileModeration( store: RootStoreModel, - profileLabels: ProfileLabelInfo, + profileInfo: ProfileLabelInfo, ): ProfileModeration { const accountPref = store.preferences.getLabelPreference( - profileLabels.accountLabels, + profileInfo.accountLabels, ) const profilePref = store.preferences.getLabelPreference( - profileLabels.profileLabels, + profileInfo.profileLabels, ) // avatar let avatar = { warn: accountPref.pref === 'hide' || accountPref.pref === 'warn', blur: + profileInfo.isBlocking || accountPref.pref === 'hide' || accountPref.pref === 'warn' || profilePref.pref === 'hide' || @@ -193,7 +234,10 @@ export function getProfileModeration( if (accountPref.pref === 'warn') { return { avatar, - list: warn(accountPref.desc.warning), + list: + profileInfo.isBlocking || profileInfo.isBlockedBy + ? hide('Blocked account') + : warn(accountPref.desc.warning), view: warn(accountPref.desc.warning), } } @@ -208,7 +252,7 @@ export function getProfileModeration( return { avatar, - list: show(), + list: profileInfo.isBlocking ? hide('Blocked account') : show(), view: show(), } } @@ -220,6 +264,7 @@ export function getProfileViewBasicLabelInfo( accountLabels: filterAccountLabels(profile.labels), profileLabels: filterProfileLabels(profile.labels), isMuted: profile.viewer?.muted || false, + isBlocking: !!profile.viewer?.blocking || false, } } @@ -236,6 +281,45 @@ export function getEmbedLabels(embed?: Embed): Label[] { return [] } +export function getEmbedMuted(embed?: Embed): boolean { + if (!embed) { + return false + } + if ( + AppBskyEmbedRecord.isView(embed) && + AppBskyEmbedRecord.isViewRecord(embed.record) + ) { + return !!embed.record.author.viewer?.muted + } + return false +} + +export function getEmbedBlocking(embed?: Embed): boolean { + if (!embed) { + return false + } + if ( + AppBskyEmbedRecord.isView(embed) && + AppBskyEmbedRecord.isViewRecord(embed.record) + ) { + return !!embed.record.author.viewer?.blocking + } + return false +} + +export function getEmbedBlockedBy(embed?: Embed): boolean { + if (!embed) { + return false + } + if ( + AppBskyEmbedRecord.isView(embed) && + AppBskyEmbedRecord.isViewRecord(embed.record) + ) { + return !!embed.record.author.viewer?.blockedBy + } + return false +} + export function filterAccountLabels(labels?: Label[]): Label[] { if (!labels) { return [] diff --git a/src/lib/labeling/types.ts b/src/lib/labeling/types.ts index d4efb499a..20ecaa5b5 100644 --- a/src/lib/labeling/types.ts +++ b/src/lib/labeling/types.ts @@ -17,12 +17,16 @@ export interface PostLabelInfo { accountLabels: Label[] profileLabels: Label[] isMuted: boolean + isBlocking: boolean + isBlockedBy: boolean } export interface ProfileLabelInfo { accountLabels: Label[] profileLabels: Label[] isMuted: boolean + isBlocking: boolean + isBlockedBy: boolean } export enum ModerationBehaviorCode { diff --git a/src/lib/routes/types.ts b/src/lib/routes/types.ts index eeb97ba7a..3aff82117 100644 --- a/src/lib/routes/types.ts +++ b/src/lib/routes/types.ts @@ -20,6 +20,7 @@ export type CommonNavigatorParams = { CommunityGuidelines: undefined CopyrightPolicy: undefined AppPasswords: undefined + BlockedAccounts: undefined } export type BottomTabNavigatorParams = CommonNavigatorParams & { |