diff --git a/app/version.js b/app/version.js deleted file mode 100644 index 74edb9a64..000000000 --- a/app/version.js +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2020 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -const semver = require('semver'); - -exports.isBeta = version => semver.parse(version).prerelease[0] === 'beta'; diff --git a/main.js b/main.js index efc776f15..be571a105 100644 --- a/main.js +++ b/main.js @@ -18,7 +18,6 @@ const electron = require('electron'); const packageJson = require('./package.json'); const GlobalErrors = require('./app/global_errors'); -const { isBeta } = require('./app/version'); const { setup: setupSpellChecker } = require('./app/spell_check'); GlobalErrors.addHandler(); @@ -98,6 +97,7 @@ const { installWebHandler, } = require('./app/protocol_filter'); const { installPermissionsHandler } = require('./app/permissions'); +const { isBeta } = require('./ts/util/version'); const { isSgnlHref, parseSgnlHref } = require('./ts/util/sgnlHref'); let appStartInitialSpellcheckSetting = true; diff --git a/preload.js b/preload.js index ea413a924..13bf0bb3a 100644 --- a/preload.js +++ b/preload.js @@ -382,6 +382,7 @@ try { const { autoOrientImage } = require('./js/modules/auto_orient_image'); const { imageToBlurHash } = require('./ts/util/imageToBlurHash'); + const { isGroupCallingEnabled } = require('./ts/util/isGroupCallingEnabled'); window.autoOrientImage = autoOrientImage; window.dataURLToBlobSync = require('blueimp-canvas-to-blob'); @@ -392,6 +393,7 @@ try { window.libphonenumber.PhoneNumberFormat = require('google-libphonenumber').PhoneNumberFormat; window.loadImage = require('blueimp-load-image'); window.getGuid = require('uuid/v4'); + window.isGroupCallingEnabled = isGroupCallingEnabled; window.isValidGuid = maybeGuid => /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i.test( @@ -428,7 +430,6 @@ try { const Signal = require('./js/modules/signal'); const i18n = require('./js/modules/i18n'); const Attachments = require('./app/attachments'); - const { isBeta } = require('./app/version'); const { locale } = config; window.i18n = i18n.setup(locale, localeMessages); @@ -587,8 +588,6 @@ try { }; /* eslint-enable global-require, import/no-extraneous-dependencies */ } - - window.GROUP_CALLING = isBeta(config.version); } catch (error) { /* eslint-disable no-console */ if (console._log) { diff --git a/prepare_beta_build.js b/prepare_beta_build.js index 645a913ca..2540d92df 100644 --- a/prepare_beta_build.js +++ b/prepare_beta_build.js @@ -7,7 +7,7 @@ const fs = require('fs'); const _ = require('lodash'); const packageJson = require('./package.json'); -const { isBeta } = require('./app/version'); +const { isBeta } = require('./ts/util/version'); const { version } = packageJson; diff --git a/ts/RemoteConfig.ts b/ts/RemoteConfig.ts index 4fd7e2405..f75866834 100644 --- a/ts/RemoteConfig.ts +++ b/ts/RemoteConfig.ts @@ -8,6 +8,7 @@ type ConfigKeyType = | 'desktop.cds' | 'desktop.clientExpiration' | 'desktop.disableGV1' + | 'desktop.groupCalling' | 'desktop.gv2' | 'desktop.mandatoryProfileSharing' | 'desktop.messageRequests' diff --git a/ts/background.ts b/ts/background.ts index 3559cdd0a..5f4337f30 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -2658,7 +2658,7 @@ type WhatIsThis = import('./window.d').WhatIsThis; if (data.message.groupCallUpdate) { if (data.message.groupV2 && messageDescriptor.type === Message.GROUP) { - if (window.GROUP_CALLING) { + if (window.isGroupCallingEnabled()) { window.reduxActions.calling.peekNotConnectedGroupCall({ conversationId: messageDescriptor.id, }); diff --git a/ts/state/smart/ConversationHeader.tsx b/ts/state/smart/ConversationHeader.tsx index fd2ff0dd2..0141c274f 100644 --- a/ts/state/smart/ConversationHeader.tsx +++ b/ts/state/smart/ConversationHeader.tsx @@ -18,6 +18,7 @@ import { getActiveCall, isAnybodyElseInGroupCall } from '../ducks/calling'; import { getUserConversationId, getIntl } from '../selectors/user'; import { getOwn } from '../../util/getOwn'; import { missingCaseError } from '../../util/missingCaseError'; +import { isGroupCallingEnabled } from '../../util/isGroupCallingEnabled'; export interface OwnProps { id: string; @@ -57,7 +58,7 @@ const getOutgoingCallButtonStyle = ( case CallMode.Direct: return OutgoingCallButtonStyle.Both; case CallMode.Group: { - if (!window.GROUP_CALLING) { + if (!isGroupCallingEnabled()) { return OutgoingCallButtonStyle.None; } const call = getOwn(calling.callsByConversation, conversation.id); diff --git a/ts/test-both/util/version_test.ts b/ts/test-both/util/version_test.ts new file mode 100644 index 000000000..f21cb1380 --- /dev/null +++ b/ts/test-both/util/version_test.ts @@ -0,0 +1,22 @@ +// Copyright 2020 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { assert } from 'chai'; + +import { isBeta } from '../../util/version'; + +describe('version utilities', () => { + describe('isBeta', () => { + it('returns false for non-beta version strings', () => { + assert.isFalse(isBeta('1.2.3')); + assert.isFalse(isBeta('1.2.3-alpha')); + assert.isFalse(isBeta('1.2.3-alpha.1')); + assert.isFalse(isBeta('1.2.3-rc.1')); + }); + + it('returns true for beta version strings', () => { + assert.isTrue(isBeta('1.2.3-beta')); + assert.isTrue(isBeta('1.2.3-beta.1')); + }); + }); +}); diff --git a/ts/util/isGroupCallingEnabled.ts b/ts/util/isGroupCallingEnabled.ts new file mode 100644 index 000000000..2ee31b96a --- /dev/null +++ b/ts/util/isGroupCallingEnabled.ts @@ -0,0 +1,13 @@ +// Copyright 2020 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { isBeta } from './version'; +import * as RemoteConfig from '../RemoteConfig'; + +// We can remove this function once group calling has been turned on for everyone. +export function isGroupCallingEnabled(): boolean { + return ( + RemoteConfig.isEnabled('desktop.groupCalling') || + isBeta(window.getVersion()) + ); +} diff --git a/ts/util/version.ts b/ts/util/version.ts new file mode 100644 index 000000000..0f2b0a7d0 --- /dev/null +++ b/ts/util/version.ts @@ -0,0 +1,7 @@ +// Copyright 2020 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import * as semver from 'semver'; + +export const isBeta = (version: string): boolean => + semver.parse(version)?.prerelease[0] === 'beta'; diff --git a/ts/window.d.ts b/ts/window.d.ts index 14a35155c..99114c0e8 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -486,7 +486,7 @@ declare global { readyForUpdates: () => void; // Flags - GROUP_CALLING: boolean; + isGroupCallingEnabled: () => boolean; } interface Error {