diff --git a/app/products/calls/components/channel_info_enable_calls/index.tsx b/app/products/calls/components/channel_info_enable_calls/index.tsx index ac3883f58..24779c749 100644 --- a/app/products/calls/components/channel_info_enable_calls/index.tsx +++ b/app/products/calls/components/channel_info_enable_calls/index.tsx @@ -6,6 +6,7 @@ import {useIntl} from 'react-intl'; import {enableChannelCalls} from '@calls/actions'; import {useTryCallsFunction} from '@calls/hooks'; +import {getCallsConfig} from '@calls/state'; import OptionItem from '@components/option_item'; import {useServerUrl} from '@context/server'; import {preventDoubleTap} from '@utils/tap'; @@ -28,6 +29,11 @@ const ChannelInfoEnableCalls = ({channelId, enabled}: Props) => { const disableText = formatMessage({id: 'mobile.calls_disable', defaultMessage: 'Disable calls'}); const enableText = formatMessage({id: 'mobile.calls_enable', defaultMessage: 'Enable calls'}); + const config = getCallsConfig(serverUrl); + if (!config.pluginEnabled) { + return null; + } + return ( ) => { + const callsPluginEnabled = observeCallsConfig(serverUrl).pipe( + switchMap((config) => of$(config.pluginEnabled)), + distinctUntilChanged(), + ); const callsDefaultEnabled = observeCallsConfig(serverUrl).pipe( switchMap((config) => of$(config.DefaultEnabled)), distinctUntilChanged(), @@ -40,8 +44,12 @@ export const observeIsCallsEnabledInChannel = (database: Database, serverUrl: st const callsGAServer = observeConfigValue(database, 'Version').pipe( switchMap((v) => of$(isMinimumServerVersion(v || '', 7, 6))), ); - return combineLatest([channelId, callsStateEnabledDict, callsDefaultEnabled, callsGAServer]).pipe( - switchMap(([id, enabled, defaultEnabled, gaServer]) => { + return combineLatest([callsPluginEnabled, channelId, callsStateEnabledDict, callsDefaultEnabled, callsGAServer]).pipe( + switchMap(([pluginEnabled, id, enabled, defaultEnabled, gaServer]) => { + if (!pluginEnabled) { + return of$(false); + } + const explicitlyEnabled = enabled.hasOwnProperty(id as string) && enabled[id]; const explicitlyDisabled = enabled.hasOwnProperty(id as string) && !enabled[id]; return of$(explicitlyEnabled || (!explicitlyDisabled && defaultEnabled) || (!explicitlyDisabled && gaServer)); diff --git a/app/screens/channel/header/header.tsx b/app/screens/channel/header/header.tsx index d9ea6981e..0b93644c7 100644 --- a/app/screens/channel/header/header.tsx +++ b/app/screens/channel/header/header.tsx @@ -6,6 +6,7 @@ import {useIntl} from 'react-intl'; import {Keyboard, Platform, Text, View} from 'react-native'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; +import {getCallsConfig} from '@calls/state'; import {CHANNEL_ACTIONS_OPTIONS_HEIGHT} from '@components/channel_actions/channel_actions'; import CompassIcon from '@components/compass_icon'; import CustomStatusEmoji from '@components/custom_status/custom_status_emoji'; @@ -14,6 +15,7 @@ import {ITEM_HEIGHT} from '@components/option_item'; import OtherMentionsBadge from '@components/other_mentions_badge'; import RoundedHeaderContext from '@components/rounded_header_context'; import {General, Screens} from '@constants'; +import {useServerUrl} from '@context/server'; import {useTheme} from '@context/theme'; import {useIsTablet} from '@hooks/device'; import {useDefaultHeaderHeight} from '@hooks/header'; @@ -87,10 +89,13 @@ const ChannelHeader = ({ const theme = useTheme(); const styles = getStyleSheet(theme); const defaultHeight = useDefaultHeaderHeight(); + const serverUrl = useServerUrl(); + + const callsConfig = getCallsConfig(serverUrl); // NOTE: callsEnabledInChannel will be true/false (not undefined) based on explicit state + the DefaultEnabled system setting // which ultimately comes from channel/index.tsx, and observeIsCallsEnabledInChannel - let callsAvailable = callsEnabledInChannel; + let callsAvailable = callsConfig.pluginEnabled && callsEnabledInChannel; if (!groupCallsAllowed && channelType !== General.DM_CHANNEL) { callsAvailable = false; } diff --git a/app/screens/channel_info/index.ts b/app/screens/channel_info/index.ts index da0b1a64b..20c964ea1 100644 --- a/app/screens/channel_info/index.ts +++ b/app/screens/channel_info/index.ts @@ -43,6 +43,11 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => { switchMap(([tId, uId]) => observeUserIsTeamAdmin(database, uId, tId)), ); + const callsPluginEnabled = observeCallsConfig(serverUrl).pipe( + switchMap((config) => of$(config.pluginEnabled)), + distinctUntilChanged(), + ); + // callsDefaultEnabled means "live mode" post 7.6 const callsDefaultEnabled = observeCallsConfig(serverUrl).pipe( switchMap((config) => of$(config.DefaultEnabled)), @@ -66,8 +71,9 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => { switchMap((v) => of$(isMinimumServerVersion(v || '', 7, 6))), ); const dmOrGM = type.pipe(switchMap((t) => of$(isTypeDMorGM(t)))); - const canEnableDisableCalls = combineLatest([callsDefaultEnabled, allowEnableCalls, systemAdmin, channelAdmin, callsGAServer, dmOrGM, isTeamAdmin]).pipe( - switchMap(([liveMode, allow, sysAdmin, chAdmin, gaServer, dmGM, tAdmin]) => { + const canEnableDisableCalls = combineLatest([callsPluginEnabled, callsDefaultEnabled, allowEnableCalls, systemAdmin, channelAdmin, callsGAServer, dmOrGM, isTeamAdmin]).pipe( + switchMap(([pluginEnabled, liveMode, allow, sysAdmin, chAdmin, gaServer, dmGM, tAdmin]) => { + // Always false if the plugin is not enabled. // if GA 7.6: // allow (will always be true) and !liveMode = system admins can enable/disable // allow (will always be true) and liveMode = channel, team, system admins, DM/GM participants can enable/disable @@ -78,6 +84,10 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => { // !allow and liveMode = system admins can enable/disable -- can combine with above // Note: There are ways to 'simplify' the conditions below. Here we're preferring clarity. + if (!pluginEnabled) { + return of$(false); + } + if (gaServer) { if (allow && !liveMode) { return of$(Boolean(sysAdmin));