Skip to content

Commit

Permalink
[MM-57781] Limit group calls to DMs only on unlicensed servers (#8075) (
Browse files Browse the repository at this point in the history
#8145)

* Limit group calls to DMs only on unlicensed servers

* Update calls-common

(cherry picked from commit 4e4bd8f)

Co-authored-by: Claudio Costa <[email protected]>
  • Loading branch information
mattermost-build and streamer45 authored Aug 13, 2024
1 parent 446e720 commit cb6f22e
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/components/post_draft/send_handler/send_handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export default function SendHandler({

const sendCommand = useCallback(async () => {
if (value.trim().startsWith('/call')) {
const {handled, error} = await handleCallsSlashCommand(value.trim(), serverUrl, channelId, rootId, currentUserId, intl);
const {handled, error} = await handleCallsSlashCommand(value.trim(), serverUrl, channelId, channelType ?? '', rootId, currentUserId, intl);
if (handled) {
setSendingMessage(false);
clearDraft();
Expand Down
21 changes: 20 additions & 1 deletion app/products/calls/actions/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
setSpeakerPhone,
} from '@calls/state';
import {type AudioDevice, type Call, type CallSession, type CallsConnection, EndCallReturn} from '@calls/types/calls';
import {areGroupCallsAllowed} from '@calls/utils';
import {General, Preferences} from '@constants';
import Calls from '@constants/calls';
import DatabaseManager from '@database/manager';
Expand Down Expand Up @@ -493,7 +494,7 @@ export const dismissIncomingCall = async (serverUrl: string, channelId: string)
};

// handleCallsSlashCommand will return true if the slash command was handled
export const handleCallsSlashCommand = async (value: string, serverUrl: string, channelId: string, rootId: string, currentUserId: string, intl: IntlShape):
export const handleCallsSlashCommand = async (value: string, serverUrl: string, channelId: string, channelType: string, rootId: string, currentUserId: string, intl: IntlShape):
Promise<{ handled?: boolean; error?: string }> => {
const tokens = value.split(' ');
if (tokens.length < 2 || tokens[0] !== '/call') {
Expand All @@ -505,6 +506,15 @@ export const handleCallsSlashCommand = async (value: string, serverUrl: string,
await handleEndCall(serverUrl, channelId, currentUserId, intl);
return {handled: true};
case 'start': {
if (!areGroupCallsAllowed(getCallsConfig(serverUrl)) && channelType !== General.DM_CHANNEL) {
return {
error: intl.formatMessage({
id: 'mobile.calls_group_calls_not_available',
defaultMessage: 'Calls are only available in DM channels.',
}),
};
}

if (getChannelsWithCalls(serverUrl)[channelId]) {
return {
error: intl.formatMessage({
Expand All @@ -518,6 +528,15 @@ export const handleCallsSlashCommand = async (value: string, serverUrl: string,
return {handled: true};
}
case 'join': {
if (!areGroupCallsAllowed(getCallsConfig(serverUrl)) && channelType !== General.DM_CHANNEL) {
return {
error: intl.formatMessage({
id: 'mobile.calls_group_calls_not_available',
defaultMessage: 'Calls are only available in DM channels.',
}),
};
}

const title = tokens.length > 2 ? tokens.slice(2).join(' ') : undefined;
await leaveAndJoinWithAlert(intl, serverUrl, channelId, title, rootId);
return {handled: true};
Expand Down
1 change: 1 addition & 0 deletions app/products/calls/types/calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const DefaultCallsConfig: CallsConfigState = {
HostControlsAllowed: false,
EnableAV1: false,
TranscribeAPI: TranscribeAPI.WhisperCPP,
GroupCallsAllowed: true, // Set to true to keep backward compatibility with older servers.
};

export type ApiResp = {
Expand Down
4 changes: 4 additions & 0 deletions app/products/calls/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ export function isHostControlsAllowed(config: CallsConfigState) {
return Boolean(config.HostControlsAllowed);
}

export function areGroupCallsAllowed(config: CallsConfigState) {
return Boolean(config.GroupCallsAllowed);
}

export function isCallsCustomMessage(post: PostModel | Post): boolean {
return Boolean(post.type && post.type === Post.POST_TYPES.CUSTOM_CALLS);
}
Expand Down
3 changes: 3 additions & 0 deletions app/screens/channel/channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type ChannelProps = {
showJoinCallBanner: boolean;
isInACall: boolean;
isCallsEnabledInChannel: boolean;
groupCallsAllowed: boolean;
showIncomingCalls: boolean;
isTabletView?: boolean;
dismissedGMasDMNotice: PreferenceModel[];
Expand All @@ -58,6 +59,7 @@ const Channel = ({
showJoinCallBanner,
isInACall,
isCallsEnabledInChannel,
groupCallsAllowed,
showIncomingCalls,
isTabletView,
dismissedGMasDMNotice,
Expand Down Expand Up @@ -125,6 +127,7 @@ const Channel = ({
channelId={channelId}
componentId={componentId}
callsEnabledInChannel={isCallsEnabledInChannel}
groupCallsAllowed={groupCallsAllowed}
isTabletView={isTabletView}
shouldRenderBookmarks={shouldRender}
/>
Expand Down
8 changes: 6 additions & 2 deletions app/screens/channel/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ChannelProps = {
searchTerm: string;
teamId: string;
callsEnabledInChannel: boolean;
groupCallsAllowed: boolean;
isTabletView?: boolean;
shouldRenderBookmarks: boolean;
};
Expand Down Expand Up @@ -78,7 +79,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
const ChannelHeader = ({
canAddBookmarks, channelId, channelType, componentId, customStatus, displayName, hasBookmarks,
isBookmarksEnabled, isCustomStatusEnabled, isCustomStatusExpired, isOwnDirectMessage, memberCount,
searchTerm, teamId, callsEnabledInChannel, isTabletView, shouldRenderBookmarks,
searchTerm, teamId, callsEnabledInChannel, groupCallsAllowed, isTabletView, shouldRenderBookmarks,
}: ChannelProps) => {
const intl = useIntl();
const isTablet = useIsTablet();
Expand All @@ -89,7 +90,10 @@ const ChannelHeader = ({

// 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
const callsAvailable = callsEnabledInChannel;
let callsAvailable = callsEnabledInChannel;
if (!groupCallsAllowed && channelType !== General.DM_CHANNEL) {
callsAvailable = false;
}

const isDMorGM = isTypeDMorGM(channelType);
const contextStyle = useMemo(() => ({
Expand Down
7 changes: 7 additions & 0 deletions app/screens/channel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {withDatabase, withObservables} from '@nozbe/watermelondb/react';
import {combineLatestWith, distinctUntilChanged, of as of$, switchMap} from 'rxjs';

import {observeCallStateInChannel, observeIsCallsEnabledInChannel} from '@calls/observers';
import {observeCallsConfig} from '@calls/state';
import {Preferences} from '@constants';
import {withServerUrl} from '@context/server';
import {observeCurrentChannel} from '@queries/servers/channel';
Expand Down Expand Up @@ -43,10 +44,16 @@ const enhanced = withObservables([], ({database, serverUrl}: EnhanceProps) => {
}),
);

const groupCallsAllowed = observeCallsConfig(serverUrl).pipe(
switchMap((config) => of$(config.GroupCallsAllowed)),
distinctUntilChanged(),
);

return {
channelId,
...observeCallStateInChannel(serverUrl, database, channelId),
isCallsEnabledInChannel: observeIsCallsEnabledInChannel(database, serverUrl, channelId),
groupCallsAllowed,
dismissedGMasDMNotice,
channelType,
currentUserId,
Expand Down
9 changes: 7 additions & 2 deletions app/screens/channel_info/channel_info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ import type {AvailableScreens} from '@typings/screens/navigation';
type Props = {
canAddBookmarks: boolean;
canEnableDisableCalls: boolean;
canManageMembers: boolean;
canManageSettings: boolean;
channelId: string;
closeButtonId: string;
componentId: AvailableScreens;
isBookmarksEnabled: boolean;
isCallsEnabledInChannel: boolean;
groupCallsAllowed: boolean;
canManageMembers: boolean;
isConvertGMFeatureAvailable: boolean;
isCRTEnabled: boolean;
isGuestUser: boolean;
Expand Down Expand Up @@ -68,6 +69,7 @@ const ChannelInfo = ({
componentId,
isBookmarksEnabled,
isCallsEnabledInChannel,
groupCallsAllowed,
isConvertGMFeatureAvailable,
isCRTEnabled,
isGuestUser,
Expand All @@ -79,7 +81,10 @@ const ChannelInfo = ({

// NOTE: isCallsEnabledInChannel will be true/false (not undefined) based on explicit state + the DefaultEnabled system setting
// which comes from observeIsCallsEnabledInChannel
const callsAvailable = isCallsEnabledInChannel;
let callsAvailable = isCallsEnabledInChannel;
if (!groupCallsAllowed && type !== General.DM_CHANNEL) {
callsAvailable = false;
}

const onPressed = useCallback(() => {
return dismissModal({componentId});
Expand Down
7 changes: 6 additions & 1 deletion app/screens/channel_info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
}),
);
const isCallsEnabledInChannel = observeIsCallsEnabledInChannel(database, serverUrl, observeCurrentChannelId(database));
const groupCallsAllowed = observeCallsConfig(serverUrl).pipe(
switchMap((config) => of$(config.GroupCallsAllowed)),
distinctUntilChanged(),
);

const canManageMembers = currentUser.pipe(
combineLatestWith(channelId),
Expand Down Expand Up @@ -135,11 +139,12 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
return {
type,
canEnableDisableCalls,
isCallsEnabledInChannel,
groupCallsAllowed,
canAddBookmarks,
canManageMembers,
canManageSettings,
isBookmarksEnabled,
isCallsEnabledInChannel,
isCRTEnabled: observeIsCRTEnabled(database),
isGuestUser,
isConvertGMFeatureAvailable,
Expand Down
1 change: 1 addition & 0 deletions assets/base/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
"mobile.calls_ended_at": "Ended at",
"mobile.calls_error_message": "Error: {error}",
"mobile.calls_error_title": "Error",
"mobile.calls_group_calls_not_available": "Calls are only available in DM channels.",
"mobile.calls_headset": "Headset",
"mobile.calls_hide_cc": "Hide live captions",
"mobile.calls_host": "host",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@formatjs/intl-numberformat": "8.10.3",
"@formatjs/intl-pluralrules": "5.2.14",
"@gorhom/bottom-sheet": "4.6.4",
"@mattermost/calls": "github:mattermost/calls-common#5cc5598fe9574125a61a3b54501deb6b65fcc70f",
"@mattermost/calls": "github:mattermost/calls-common#1ce6defb1ee0c1e0f106ddff8f46c37d10d60b76",
"@mattermost/compass-icons": "0.1.45",
"@mattermost/hardware-keyboard": "file:./libraries/@mattermost/hardware-keyboard",
"@mattermost/keyboard-tracker": "file:./libraries/@mattermost/keyboard-tracker",
Expand Down

0 comments on commit cb6f22e

Please sign in to comment.