[MM-57994] Hide Calls buttons/actions if plugin is not enabled (#8121)

* Limit group calls to DMs only on unlicensed servers

* Hide Calls buttons/actions if plugin is disabled

* Fix lint

* Address feedback
This commit is contained in:
Claudio Costa 2024-08-19 09:33:20 -06:00 committed by GitHub
parent fe0dd4b5af
commit 52d04ca252
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 5 deletions

View file

@ -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 (
<OptionItem
action={preventDoubleTap(tryOnPress)}

View file

@ -29,6 +29,10 @@ export type LimitRestrictedInfo = {
}
export const observeIsCallsEnabledInChannel = (database: Database, serverUrl: string, channelId: Observable<string>) => {
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));

View file

@ -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;
}

View file

@ -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));