From ab543aea938f899f14a66a9fd2fcfd4d55e9b991 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 9 Nov 2021 09:51:56 -0600 Subject: [PATCH] Add "should show badges" feature flag --- ts/RemoteConfig.ts | 1 + ts/badges/shouldShowBadges.ts | 16 ++++++++++++++++ ts/components/Avatar.tsx | 9 ++++++++- ts/components/conversation/ContactModal.tsx | 3 ++- .../ConversationDetailsHeader.tsx | 3 ++- 5 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 ts/badges/shouldShowBadges.ts diff --git a/ts/RemoteConfig.ts b/ts/RemoteConfig.ts index 6a586a7ab..a2e037767 100644 --- a/ts/RemoteConfig.ts +++ b/ts/RemoteConfig.ts @@ -24,6 +24,7 @@ export type ConfigKeyType = | 'desktop.senderKey.send' | 'desktop.senderKey.retry' | 'desktop.sendSenderKey3' + | 'desktop.showUserBadges' | 'desktop.storage' | 'desktop.storageWrite3' | 'desktop.usernames' diff --git a/ts/badges/shouldShowBadges.ts b/ts/badges/shouldShowBadges.ts new file mode 100644 index 000000000..2c2112647 --- /dev/null +++ b/ts/badges/shouldShowBadges.ts @@ -0,0 +1,16 @@ +// Copyright 2021 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { isEnabled } from '../RemoteConfig'; +import { getEnvironment, Environment } from '../environment'; + +export function shouldShowBadges(): boolean { + return ( + isEnabled('desktop.showUserBadges') || + isEnabled('desktop.internalUser') || + getEnvironment() === Environment.Staging || + getEnvironment() === Environment.Development || + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Boolean((window as any).STORYBOOK_ENV) + ); +} diff --git a/ts/components/Avatar.tsx b/ts/components/Avatar.tsx index c25f35bb4..582b3c580 100644 --- a/ts/components/Avatar.tsx +++ b/ts/components/Avatar.tsx @@ -24,6 +24,7 @@ import { shouldBlurAvatar } from '../util/shouldBlurAvatar'; import { getBadgeImageFileLocalPath } from '../badges/getBadgeImageFileLocalPath'; import { isBadgeVisible } from '../badges/isBadgeVisible'; import { BadgeImageTheme } from '../badges/BadgeImageTheme'; +import { shouldShowBadges } from '../badges/shouldShowBadges'; export enum AvatarBlur { NoBlur, @@ -213,7 +214,13 @@ export const Avatar: FunctionComponent = ({ } let badgeNode: ReactNode; - if (badge && theme && !noteToSelf && isBadgeVisible(badge)) { + if ( + badge && + theme && + !noteToSelf && + isBadgeVisible(badge) && + shouldShowBadges() + ) { const badgeSize = Math.ceil(size * 0.425); const badgeTheme = theme === ThemeType.light ? BadgeImageTheme.Light : BadgeImageTheme.Dark; diff --git a/ts/components/conversation/ContactModal.tsx b/ts/components/conversation/ContactModal.tsx index 146a1101f..29f746b35 100644 --- a/ts/components/conversation/ContactModal.tsx +++ b/ts/components/conversation/ContactModal.tsx @@ -14,6 +14,7 @@ import { BadgeDialog } from '../BadgeDialog'; import type { BadgeType } from '../../badges/types'; import { SharedGroupNames } from '../SharedGroupNames'; import { ConfirmationDialog } from '../ConfirmationDialog'; +import { shouldShowBadges } from '../../badges/shouldShowBadges'; export type PropsDataType = { areWeAdmin: boolean; @@ -105,7 +106,7 @@ export const ContactModal = ({ unblurredAvatarPath={contact.unblurredAvatarPath} onClick={() => { setView( - preferredBadge + preferredBadge && shouldShowBadges() ? ContactModalView.ShowingBadges : ContactModalView.ShowingAvatar ); diff --git a/ts/components/conversation/conversation-details/ConversationDetailsHeader.tsx b/ts/components/conversation/conversation-details/ConversationDetailsHeader.tsx index ca8e4a1f3..1acb14702 100644 --- a/ts/components/conversation/conversation-details/ConversationDetailsHeader.tsx +++ b/ts/components/conversation/conversation-details/ConversationDetailsHeader.tsx @@ -15,6 +15,7 @@ import type { LocalizerType, ThemeType } from '../../../types/Util'; import { bemGenerator } from './util'; import { BadgeDialog } from '../../BadgeDialog'; import type { BadgeType } from '../../../badges/types'; +import { shouldShowBadges } from '../../../badges/shouldShowBadges'; export type Props = { badges?: ReadonlyArray; @@ -92,7 +93,7 @@ export const ConversationDetailsHeader: React.ComponentType = ({ noteToSelf={isMe} onClick={() => { setActiveModal( - preferredBadge + preferredBadge && shouldShowBadges() ? ConversationDetailsHeaderActiveModal.ShowingBadges : ConversationDetailsHeaderActiveModal.ShowingAvatar );