Skip to content

Commit

Permalink
Add "should show badges" feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Nov 9, 2021
1 parent c76b5df commit 65b21be
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions ts/RemoteConfig.ts
Expand Up @@ -24,6 +24,7 @@ export type ConfigKeyType =
| 'desktop.senderKey.send'
| 'desktop.senderKey.retry'
| 'desktop.sendSenderKey3'
| 'desktop.showUserBadges'
| 'desktop.storage'
| 'desktop.storageWrite3'
| 'desktop.usernames'
Expand Down
16 changes: 16 additions & 0 deletions 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)
);
}
3 changes: 2 additions & 1 deletion ts/components/Avatar.tsx
Expand Up @@ -23,6 +23,7 @@ import { assert } from '../util/assert';
import { shouldBlurAvatar } from '../util/shouldBlurAvatar';
import { getBadgeImageFileLocalPath } from '../badges/getBadgeImageFileLocalPath';
import { BadgeImageTheme } from '../badges/BadgeImageTheme';
import { shouldShowBadges } from '../badges/shouldShowBadges';

export enum AvatarBlur {
NoBlur,
Expand Down Expand Up @@ -212,7 +213,7 @@ export const Avatar: FunctionComponent<Props> = ({
}

let badgeNode: ReactNode;
if (badge && theme && !isMe) {
if (badge && theme && !isMe && shouldShowBadges()) {
const badgeSize = Math.ceil(size * 0.425);
const badgeTheme =
theme === ThemeType.light ? BadgeImageTheme.Light : BadgeImageTheme.Dark;
Expand Down
3 changes: 2 additions & 1 deletion ts/components/conversation/ContactModal.tsx
Expand Up @@ -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;
Expand Down Expand Up @@ -105,7 +106,7 @@ export const ContactModal = ({
unblurredAvatarPath={contact.unblurredAvatarPath}
onClick={() => {
setView(
preferredBadge
preferredBadge && shouldShowBadges()
? ContactModalView.ShowingBadges
: ContactModalView.ShowingAvatar
);
Expand Down
Expand Up @@ -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<BadgeType>;
Expand Down Expand Up @@ -92,7 +93,7 @@ export const ConversationDetailsHeader: React.ComponentType<Props> = ({
noteToSelf={isMe}
onClick={() => {
setActiveModal(
preferredBadge
preferredBadge && shouldShowBadges()
? ConversationDetailsHeaderActiveModal.ShowingBadges
: ConversationDetailsHeaderActiveModal.ShowingAvatar
);
Expand Down

0 comments on commit 65b21be

Please sign in to comment.