From 1dc633b07cfe230e08ebee8d605ce112752cf8ff Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Sun, 7 May 2023 21:25:59 -0500 Subject: [PATCH] Show which list caused a mute --- src/lib/labeling/helpers.ts | 27 +++++++++++++++-- src/lib/labeling/types.ts | 3 +- src/lib/strings/url-helpers.ts | 9 ++++++ src/state/models/content/post-thread.ts | 4 +++ src/state/models/content/profile.ts | 2 ++ src/state/models/feeds/notifications.ts | 1 + src/state/models/feeds/posts.ts | 4 +++ src/view/com/lists/ListItems.tsx | 2 +- src/view/com/profile/ProfileHeader.tsx | 39 ++++++++++++++++--------- 9 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/lib/labeling/helpers.ts b/src/lib/labeling/helpers.ts index 71ea43c087..90f69a21d8 100644 --- a/src/lib/labeling/helpers.ts +++ b/src/lib/labeling/helpers.ts @@ -1,5 +1,6 @@ import { AppBskyActorDefs, + AppBskyGraphDefs, AppBskyEmbedRecordWithMedia, AppBskyEmbedRecord, AppBskyEmbedImages, @@ -127,11 +128,15 @@ export function getPostModeration( // muting if (postInfo.isMuted) { + let msg = 'Post from an account you muted.' + if (postInfo.mutedByList) { + msg = `Muted by ${postInfo.mutedByList.name}` + } return { avatar, - list: hide('Post from an account you muted.'), - thread: warn('Post from an account you muted.'), - view: warn('Post from an account you muted.'), + list: hide(msg), + thread: warn(msg), + view: warn(msg), } } @@ -273,6 +278,7 @@ export function getProfileViewBasicLabelInfo( profileLabels: filterProfileLabels(profile.labels), isMuted: profile.viewer?.muted || false, isBlocking: !!profile.viewer?.blocking || false, + isBlockedBy: !!profile.viewer?.blockedBy || false, } } @@ -302,6 +308,21 @@ export function getEmbedMuted(embed?: Embed): boolean { return false } +export function getEmbedMutedByList( + embed?: Embed, +): AppBskyGraphDefs.ListViewBasic | undefined { + if (!embed) { + return undefined + } + if ( + AppBskyEmbedRecord.isView(embed) && + AppBskyEmbedRecord.isViewRecord(embed.record) + ) { + return embed.record.author.viewer?.mutedByList + } + return undefined +} + export function getEmbedBlocking(embed?: Embed): boolean { if (!embed) { return false diff --git a/src/lib/labeling/types.ts b/src/lib/labeling/types.ts index 123c5d1f38..bb6b619800 100644 --- a/src/lib/labeling/types.ts +++ b/src/lib/labeling/types.ts @@ -1,4 +1,4 @@ -import {ComAtprotoLabelDefs} from '@atproto/api' +import {ComAtprotoLabelDefs, AppBskyGraphDefs} from '@atproto/api' import {LabelPreferencesModel} from 'state/models/ui/preferences' export type Label = ComAtprotoLabelDefs.Label @@ -22,6 +22,7 @@ export interface PostLabelInfo { accountLabels: Label[] profileLabels: Label[] isMuted: boolean + mutedByList?: AppBskyGraphDefs.ListViewBasic isBlocking: boolean isBlockedBy: boolean } diff --git a/src/lib/strings/url-helpers.ts b/src/lib/strings/url-helpers.ts index 17a49fb265..4327305cb7 100644 --- a/src/lib/strings/url-helpers.ts +++ b/src/lib/strings/url-helpers.ts @@ -90,6 +90,15 @@ export function convertBskyAppUrlIfNeeded(url: string): string { return url } +export function listUriToHref(url: string): string { + try { + const {hostname, rkey} = new AtUri(url) + return `/profile/${hostname}/lists/${rkey}` + } catch { + return '' + } +} + export function getYoutubeVideoId(link: string): string | undefined { let url try { diff --git a/src/state/models/content/post-thread.ts b/src/state/models/content/post-thread.ts index a0f75493ac..74a75d803c 100644 --- a/src/state/models/content/post-thread.ts +++ b/src/state/models/content/post-thread.ts @@ -14,6 +14,7 @@ import {PostLabelInfo, PostModeration} from 'lib/labeling/types' import { getEmbedLabels, getEmbedMuted, + getEmbedMutedByList, getEmbedBlocking, getEmbedBlockedBy, filterAccountLabels, @@ -70,6 +71,9 @@ export class PostThreadItemModel { this.post.author.viewer?.muted || getEmbedMuted(this.post.embed) || false, + mutedByList: + this.post.author.viewer?.mutedByList || + getEmbedMutedByList(this.post.embed), isBlocking: !!this.post.author.viewer?.blocking || getEmbedBlocking(this.post.embed) || diff --git a/src/state/models/content/profile.ts b/src/state/models/content/profile.ts index a84476575c..9d8378f795 100644 --- a/src/state/models/content/profile.ts +++ b/src/state/models/content/profile.ts @@ -2,6 +2,7 @@ import {makeAutoObservable, runInAction} from 'mobx' import { AtUri, ComAtprotoLabelDefs, + AppBskyGraphDefs, AppBskyActorGetProfile as GetProfile, AppBskyActorProfile, RichText, @@ -20,6 +21,7 @@ import { export class ProfileViewerModel { muted?: boolean + mutedByList?: AppBskyGraphDefs.ListViewBasic following?: string followedBy?: string blockedBy?: boolean diff --git a/src/state/models/feeds/notifications.ts b/src/state/models/feeds/notifications.ts index 3ffd10b99e..4b8f35b264 100644 --- a/src/state/models/feeds/notifications.ts +++ b/src/state/models/feeds/notifications.ts @@ -111,6 +111,7 @@ export class NotificationsFeedItemModel { addedInfo?.profileLabels || [], ), isMuted: this.author.viewer?.muted || addedInfo?.isMuted || false, + mutedByList: this.author.viewer?.mutedByList || addedInfo.mutedByList, isBlocking: !!this.author.viewer?.blocking || addedInfo?.isBlocking || false, isBlockedBy: diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts index 44cec3af7f..b2dffdc694 100644 --- a/src/state/models/feeds/posts.ts +++ b/src/state/models/feeds/posts.ts @@ -24,6 +24,7 @@ import {PostLabelInfo, PostModeration} from 'lib/labeling/types' import { getEmbedLabels, getEmbedMuted, + getEmbedMutedByList, getEmbedBlocking, getEmbedBlockedBy, getPostModeration, @@ -105,6 +106,9 @@ export class PostsFeedItemModel { this.post.author.viewer?.muted || getEmbedMuted(this.post.embed) || false, + mutedByList: + this.post.author.viewer?.mutedByList || + getEmbedMutedByList(this.post.embed), isBlocking: !!this.post.author.viewer?.blocking || getEmbedBlocking(this.post.embed) || diff --git a/src/view/com/lists/ListItems.tsx b/src/view/com/lists/ListItems.tsx index 9355510858..0dda1a56f3 100644 --- a/src/view/com/lists/ListItems.tsx +++ b/src/view/com/lists/ListItems.tsx @@ -156,7 +156,7 @@ export const ListItems = observer( } return } else if (item === HEADER_ITEM) { - return list.hasLoaded ? ( + return list.list ? ( - - + style={[styles.moderationNotice, pal.viewLight]}> + + Account blocked ) : view.viewer.muted ? ( + style={[styles.moderationNotice, pal.viewLight]}> - - Account muted + + Account muted{' '} + {view.viewer.mutedByList && ( + + by{' '} + + + )} ) : undefined} {view.viewer.blockedBy && ( - - + style={[styles.moderationNotice, pal.viewLight]}> + + This account has blocked you @@ -600,10 +613,10 @@ const styles = StyleSheet.create({ moderationNotice: { flexDirection: 'row', alignItems: 'center', - borderWidth: 1, borderRadius: 8, - paddingHorizontal: 12, - paddingVertical: 10, + paddingHorizontal: 16, + paddingVertical: 14, + gap: 8, }, br40: {borderRadius: 40},