Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(groupchat-polls-permissions) Implement groupchat and polls creation for web (#15806)

Horatiu Muresan45626a0d23e4
diff --git a/config.js b/config.js
index 3894d01e16..2428c6b427 100644
--- a/config.js
+++ b/config.js
@@ -1378,8 +1378,12 @@ var config = {
The config file should be in JSON.
None of the fields are mandatory and the response must have the shape:
{
+ // Whether participant can only send group chat message if `send-groupchat` feature is enabled in jwt.
+ groupChatRequiresPermission: false,
+ // Whether participant can only create polls if `create-polls` feature is enabled in jwt.
+ pollCreationRequiresPermission: false,
// The domain url to apply (will replace the domain in the sharing conference link/embed section)
- inviteDomain: 'example-company.org,
+ inviteDomain: 'example-company.org',
// The hex value for the colour used as background
backgroundColor: '#fff',
// The url for the image used as background
diff --git a/react/features/base/jwt/constants.ts b/react/features/base/jwt/constants.ts
index dd1abc8dff..18f03f99fc 100644
--- a/react/features/base/jwt/constants.ts
+++ b/react/features/base/jwt/constants.ts
@@ -1,9 +1,12 @@
+import { ParticipantFeaturesKey } from '../participants/types';
+
/**
* The list of supported meeting features to enable/disable through jwt.
*/
-export const MEET_FEATURES = {
+export const MEET_FEATURES: Record<string, ParticipantFeaturesKey> = {
BRANDING: 'branding',
CALENDAR: 'calendar',
+ CREATE_POLLS: 'create-polls',
FLIP: 'flip',
INBOUND_CALL: 'inbound-call',
LIVESTREAMING: 'livestreaming',
@@ -13,6 +16,7 @@ export const MEET_FEATURES = {
RECORDING: 'recording',
ROOM: 'room',
SCREEN_SHARING: 'screen-sharing',
+ SEND_GROUPCHAT: 'send-groupchat',
SIP_INBOUND_CALL: 'sip-inbound-call',
SIP_OUTBOUND_CALL: 'sip-outbound-call',
TRANSCRIPTION: 'transcription'
diff --git a/react/features/base/jwt/functions.ts b/react/features/base/jwt/functions.ts
index 856fcaf4aa..22c9b97797 100644
--- a/react/features/base/jwt/functions.ts
+++ b/react/features/base/jwt/functions.ts
@@ -4,7 +4,7 @@ import jwtDecode from 'jwt-decode';
import { IReduxState } from '../../app/types';
import { isVpaasMeeting } from '../../jaas/functions';
import { getLocalParticipant } from '../participants/functions';
-import { IParticipantFeatures } from '../participants/types';
+import { IParticipantFeatures, ParticipantFeaturesKey } from '../participants/types';
import { parseURLParams } from '../util/parseURLParams';
import { JWT_VALIDATION_ERRORS, MEET_FEATURES } from './constants';
@@ -49,7 +49,12 @@ export function getJwtName(state: IReduxState) {
* @param {boolean} ifNotInFeatures - Default value if features prop exists but does not have the {@code feature}.
* @returns {boolean}
*/
-export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoToken: boolean, ifNotInFeatures: boolean) {
+export function isJwtFeatureEnabled(
+ state: IReduxState,
+ feature: ParticipantFeaturesKey,
+ ifNoToken: boolean,
+ ifNotInFeatures: boolean
+) {
const { jwt } = state['features/base/jwt'];
let { features } = getLocalParticipant(state) || {};
@@ -68,7 +73,7 @@ export function isJwtFeatureEnabled(state: IReduxState, feature: string, ifNoTok
}
interface IIsJwtFeatureEnabledStatelessParams {
- feature: string;
+ feature: ParticipantFeaturesKey;
ifNoToken: boolean;
ifNotInFeatures: boolean;
jwt?: string;
@@ -101,11 +106,11 @@ export function isJwtFeatureEnabledStateless({
return ifNoToken;
}
- if (typeof features[feature as keyof typeof features] === 'undefined') {
+ if (typeof features[feature] === 'undefined') {
return ifNotInFeatures;
}
- return String(features[feature as keyof typeof features]) === 'true';
+ return String(features[feature]) === 'true';
}
/**
@@ -202,7 +207,7 @@ export function validateJwt(jwt: string) {
const { features } = context;
const meetFeatures = Object.values(MEET_FEATURES);
- Object.keys(features).forEach(feature => {
+ (Object.keys(features) as ParticipantFeaturesKey[]).forEach(feature => {
if (meetFeatures.includes(feature)) {
const featureValue = features[feature];
diff --git a/react/features/base/participants/types.ts b/react/features/base/participants/types.ts
index 2e4a7a6dcb..9322ead9e4 100644
--- a/react/features/base/participants/types.ts
+++ b/react/features/base/participants/types.ts
@@ -57,6 +57,7 @@ export interface ILocalParticipant extends IParticipant {
export interface IParticipantFeatures {
'branding'?: boolean | string;
'calendar'?: boolean | string;
+ 'create-polls'?: boolean | string;
'flip'?: boolean | string;
'inbound-call'?: boolean | string;
'livestreaming'?: boolean | string;
@@ -66,6 +67,7 @@ export interface IParticipantFeatures {
'recording'?: boolean | string;
'room'?: boolean | string;
'screen-sharing'?: boolean | string;
+ 'send-groupchat'?: boolean | string;
'sip-inbound-call'?: boolean | string;
'sip-outbound-call'?: boolean | string;
'transcription'?: boolean | string;
@@ -84,3 +86,5 @@ export interface IJitsiParticipant {
getSources: () => Map<string, Map<string, ISourceInfo>>;
isHidden: () => boolean;
}
+
+export type ParticipantFeaturesKey = keyof IParticipantFeatures;
diff --git a/react/features/chat/components/web/ChatInput.tsx b/react/features/chat/components/web/ChatInput.tsx
index 84bbb341cc..c088a9ff86 100644
--- a/react/features/chat/components/web/ChatInput.tsx
+++ b/react/features/chat/components/web/ChatInput.tsx
@@ -8,7 +8,7 @@ import { translate } from '../../../base/i18n/functions';
import { IconFaceSmile, IconSend } from '../../../base/icons/svg';
import Button from '../../../base/ui/components/web/Button';
import Input from '../../../base/ui/components/web/Input';
-import { areSmileysDisabled } from '../../functions';
+import { areSmileysDisabled, isSendGroupChatDisabled } from '../../functions';
import SmileysPanel from './SmileysPanel';
@@ -22,6 +22,8 @@ interface IProps extends WithTranslation {
*/
_areSmileysDisabled: boolean;
+ _isSendGroupChatDisabled: boolean;
+
/**
* The id of the message recipient, if any.
*/
@@ -145,7 +147,8 @@ class ChatInput extends Component<IProps, IState> {
value = { this.state.message } />
<Button
accessibilityLabel = { this.props.t('chat.sendButton') }
- disabled = { !this.state.message.trim() }
+ disabled = { !this.state.message.trim()
+ || (this.props._isSendGroupChatDisabled && !this.props._privateMessageRecipientId) }
icon = { IconSend }
onClick = { this._onSubmitMessage }
size = { isMobileBrowser() ? 'large' : 'medium' } />
@@ -170,10 +173,20 @@ class ChatInput extends Component<IProps, IState> {
* @returns {void}
*/
_onSubmitMessage() {
+ const {
+ _isSendGroupChatDisabled,
+ _privateMessageRecipientId,
+ onSend
+ } = this.props;
+
+ if (_isSendGroupChatDisabled && !_privateMessageRecipientId) {
+ return;
+ }
+
const trimmed = this.state.message.trim();
if (trimmed) {
- this.props.onSend(trimmed);
+ onSend(trimmed);
this.setState({ message: '' });
@@ -276,10 +289,12 @@ class ChatInput extends Component<IProps, IState> {
*/
const mapStateToProps = (state: IReduxState) => {
const { privateMessageRecipient } = state['features/chat'];
+ const isGroupChatDisabled = isSendGroupChatDisabled(state);
return {
_areSmileysDisabled: areSmileysDisabled(state),
- _privateMessageRecipientId: privateMessageRecipient?.id
+ _privateMessageRecipientId: privateMessageRecipient?.id,
+ _isSendGroupChatDisabled: isGroupChatDisabled
};
};
diff --git a/react/features/chat/functions.ts b/react/features/chat/functions.ts
index 7081cfd682..07b9fd78e5 100644
--- a/react/features/chat/functions.ts
+++ b/react/features/chat/functions.ts
@@ -7,6 +7,7 @@ import emojiAsciiAliases from 'react-emoji-render/data/asciiAliases';
import { IReduxState } from '../app/types';
import { getLocalizedDateFormatter } from '../base/i18n/dateUtil';
import i18next from '../base/i18n/i18next';
+import { isJwtFeatureEnabled } from '../base/jwt/functions';
import { getParticipantById } from '../base/participants/functions';
import { escapeRegexp } from '../base/util/helpers';
@@ -190,3 +191,20 @@ export function getPrivateNoticeMessage(message: IMessage) {
recipient: message.messageType === MESSAGE_TYPE_LOCAL ? message.recipient : i18next.t('chat.you')
});
}
+
+
+/**
+ * Check if participant is not allowed to send group messages.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @returns {boolean} - Returns true if the participant is not allowed to send group messages.
+ */
+export function isSendGroupChatDisabled(state: IReduxState) {
+ const { groupChatRequiresPermission } = state['features/dynamic-branding'];
+
+ if (!groupChatRequiresPermission) {
+ return false;
+ }
+
+ return !isJwtFeatureEnabled(state, 'send-groupchat', false, false);
+}
diff --git a/react/features/chat/middleware.ts b/react/features/chat/middleware.ts
index fa6f0f28b8..697d2755c9 100644
--- a/react/features/chat/middleware.ts
+++ b/react/features/chat/middleware.ts
@@ -42,7 +42,7 @@ import {
SEND_REACTION,
SET_IS_POLL_TAB_FOCUSED
} from './actionTypes';
-import { addMessage, addMessageReaction, clearMessages, closeChat } from './actions.any';
+import { addMessage, addMessageReaction, clearMessages, closeChat, setPrivateMessageRecipient } from './actions.any';
import { ChatPrivacyDialog } from './components';
import {
INCOMING_MSG_SOUND_ID,
@@ -52,7 +52,7 @@ import {
MESSAGE_TYPE_REMOTE,
MESSAGE_TYPE_SYSTEM
} from './constants';
-import { getUnreadCount } from './functions';
+import { getUnreadCount, isSendGroupChatDisabled } from './functions';
import { INCOMING_MSG_SOUND_FILE } from './sounds';
/**
@@ -161,13 +161,29 @@ MiddlewareRegistry.register(store => next => action => {
break;
}
- case OPEN_CHAT:
+ case OPEN_CHAT: {
unreadCount = 0;
if (typeof APP !== 'undefined') {
APP.API.notifyChatUpdated(unreadCount, true);
}
+
+ const { privateMessageRecipient } = store.getState()['features/chat'];
+
+ if (
+ isSendGroupChatDisabled(store.getState())
+ && privateMessageRecipient
+ && !action.participant
+ ) {
+ const participant = getParticipantById(store.getState(), privateMessageRecipient.id);
+
+ if (participant) {
+ action.participant = participant;
+ }
+ }
+
break;
+ }
case SET_IS_POLL_TAB_FOCUSED: {
dispatch(resetNbUnreadPollsMessages());
@@ -307,6 +323,12 @@ function _addChatMsgListener(conference: IJitsiConference, store: IStore) {
isGuest,
messageId,
privateMessage: false });
+
+ if (isSendGroupChatDisabled(store.getState()) && participantId) {
+ const participant = getParticipantById(store, participantId);
+
+ store.dispatch(setPrivateMessageRecipient(participant));
+ }
}
);
diff --git a/react/features/dynamic-branding/reducer.ts b/react/features/dynamic-branding/reducer.ts
index 1dec7fa601..6f76ccd9d4 100644
--- a/react/features/dynamic-branding/reducer.ts
+++ b/react/features/dynamic-branding/reducer.ts
@@ -76,6 +76,15 @@ const DEFAULT_STATE = {
*/
didPageUrl: '',
+ /**
+ * Whether participant can only send group chat message if `send-groupchat`
+ * feature is enabled in jwt.
+ *
+ * @public
+ * @type {boolean}
+ */
+ groupChatRequiresPermission: false,
+
/**
* The custom invite domain.
*
@@ -117,6 +126,14 @@ const DEFAULT_STATE = {
*/
muiBrandedTheme: undefined,
+ /**
+ * Whether participant can only create polls if `create-polls` feature is enabled in jwt.
+ *
+ * @public
+ * @type {boolean}
+ */
+ pollCreationRequiresPermission: false,
+
/**
* The lobby/prejoin background.
*
@@ -152,11 +169,13 @@ export interface IDynamicBrandingState {
defaultBranding: boolean;
defaultTranscriptionLanguage?: boolean;
didPageUrl: string;
+ groupChatRequiresPermission: boolean;
inviteDomain: string;
labels: Object | null;
logoClickUrl: string;
logoImageUrl: string;
muiBrandedTheme?: boolean;
+ pollCreationRequiresPermission: boolean;
premeetingBackground: string;
requireRecordingConsent?: boolean;
sharedVideoAllowedURLDomains?: Array<string>;
@@ -179,11 +198,13 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STA
brandedIcons,
defaultBranding,
didPageUrl,
+ groupChatRequiresPermission,
inviteDomain,
labels,
logoClickUrl,
logoImageUrl,
muiBrandedTheme,
+ pollCreationRequiresPermission,
premeetingBackground,
sharedVideoAllowedURLDomains,
showGiphyIntegration,
@@ -199,11 +220,13 @@ ReducerRegistry.register<IDynamicBrandingState>(STORE_NAME, (state = DEFAULT_STA
brandedIcons,
defaultBranding,
didPageUrl,
+ groupChatRequiresPermission,
inviteDomain,
labels,
logoClickUrl,
logoImageUrl,
muiBrandedTheme,
+ pollCreationRequiresPermission,
premeetingBackground,
sharedVideoAllowedURLDomains,
showGiphyIntegration,
diff --git a/react/features/jaas/actions.web.ts b/react/features/jaas/actions.web.ts
index 6897cfeebb..b7e8887435 100644
--- a/react/features/jaas/actions.web.ts
+++ b/react/features/jaas/actions.web.ts
@@ -1,5 +1,6 @@
import { IStore } from '../app/types';
import { openDialog } from '../base/dialog/actions';
+import { ParticipantFeaturesKey } from '../base/participants/types';
import PremiumFeatureDialog from './components/web/PremiumFeatureDialog';
import { isFeatureDisabled } from './functions';
@@ -7,11 +8,11 @@ import { isFeatureDisabled } from './functions';
/**
* Shows a dialog prompting users to upgrade, if requested feature is disabled.
*
- * @param {string} feature - The feature to check availability for.
+ * @param {ParticipantFeaturesKey} feature - The feature to check availability for.
*
* @returns {Function}
*/
-export function maybeShowPremiumFeatureDialog(feature: string) {
+export function maybeShowPremiumFeatureDialog(feature: ParticipantFeaturesKey) {
return function(dispatch: IStore['dispatch'], getState: IStore['getState']) {
if (isFeatureDisabled(getState(), feature)) {
dispatch(openDialog(PremiumFeatureDialog));
diff --git a/react/features/jaas/functions.ts b/react/features/jaas/functions.ts
index 89ac44a599..748da40cbf 100644
--- a/react/features/jaas/functions.ts
+++ b/react/features/jaas/functions.ts
@@ -1,5 +1,6 @@
import { IReduxState } from '../app/types';
import { IJitsiConference } from '../base/conference/reducer';
+import { ParticipantFeaturesKey } from '../base/participants/types';
import { VPAAS_TENANT_PREFIX } from './constants';
import logger from './logger';
@@ -105,10 +106,10 @@ export async function sendGetDetailsRequest({ appId, baseUrl }: {
* Returns the billing id for vpaas meetings.
*
* @param {IReduxState} state - The state of the app.
- * @param {string} feature - Feature to be looked up for disable state.
+ * @param {ParticipantFeaturesKey} feature - Feature to be looked up for disable state.
* @returns {boolean}
*/
-export function isFeatureDisabled(state: IReduxState, feature: string) {
+export function isFeatureDisabled(state: IReduxState, feature: ParticipantFeaturesKey) {
return state['features/jaas'].disabledFeatures.includes(feature);
}
diff --git a/react/features/polls/components/AbstractPollsPane.tsx b/react/features/polls/components/AbstractPollsPane.tsx
index 0ef274a069..7e6efa1233 100644
--- a/react/features/polls/components/AbstractPollsPane.tsx
+++ b/react/features/polls/components/AbstractPollsPane.tsx
@@ -1,5 +1,8 @@
import React, { ComponentType, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useSelector } from 'react-redux';
+
+import { isCreatePollDisabled } from '../functions';
/*
* Props that will be passed by the AbstractPollsPane to its
@@ -7,6 +10,7 @@ import { useTranslation } from 'react-i18next';
**/
export type AbstractProps = {
createMode: boolean;
+ isCreatePollsDisabled: boolean;
onCreate: () => void;
setCreateMode: (mode: boolean) => void;
t: Function;
@@ -21,6 +25,7 @@ export type AbstractProps = {
*/
const AbstractPollsPane = (Component: ComponentType<AbstractProps>) => () => {
+ const isCreatePollsDisabled = useSelector(isCreatePollDisabled);
const [ createMode, setCreateMode ] = useState(false);
const onCreate = () => {
@@ -31,6 +36,7 @@ const AbstractPollsPane = (Component: ComponentType<AbstractProps>) => () => {
return (<Component
createMode = { createMode }
+ isCreatePollsDisabled = { isCreatePollsDisabled }
/* eslint-disable react/jsx-no-bind */
onCreate = { onCreate }
setCreateMode = { setCreateMode }
diff --git a/react/features/polls/components/web/PollsPane.tsx b/react/features/polls/components/web/PollsPane.tsx
index 8bee11762d..5701e4d3f1 100644
--- a/react/features/polls/components/web/PollsPane.tsx
+++ b/react/features/polls/components/web/PollsPane.tsx
@@ -28,7 +28,7 @@ const useStyles = makeStyles()(() => {
};
});
-const PollsPane = ({ createMode, onCreate, setCreateMode, t }: AbstractProps) => {
+const PollsPane = ({ createMode, isCreatePollsDisabled, onCreate, setCreateMode, t }: AbstractProps) => {
const { classes } = useStyles();
return createMode
@@ -40,6 +40,7 @@ const PollsPane = ({ createMode, onCreate, setCreateMode, t }: AbstractProps) =>
<div className = { classes.footer }>
<Button
accessibilityLabel = { t('polls.create.create') }
+ disabled = { isCreatePollsDisabled }
fullWidth = { true }
labelKey = { 'polls.create.create' }
onClick = { onCreate } />
diff --git a/react/features/polls/functions.ts b/react/features/polls/functions.ts
index 43f4ad5eaa..24025c1ddf 100644
--- a/react/features/polls/functions.ts
+++ b/react/features/polls/functions.ts
@@ -1,4 +1,5 @@
import { IReduxState } from '../app/types';
+import { isJwtFeatureEnabled } from '../base/jwt/functions';
import { IAnswerData } from './types';
@@ -62,3 +63,19 @@ export function hasIdenticalAnswers(currentAnswers: Array<IAnswerData>): boolean
return currentAnswersSet.size !== nonEmptyCurrentAnswers.length;
}
+
+/**
+ * Check if participant is not allowed to create polls.
+ *
+ * @param {IReduxState} state - The redux state.
+ * @returns {boolean} - Returns true if the participant is not allowed to create polls.
+ */
+export function isCreatePollDisabled(state: IReduxState) {
+ const { pollCreationRequiresPermission } = state['features/dynamic-branding'];
+
+ if (!pollCreationRequiresPermission) {
+ return false;
+ }
+
+ return !isJwtFeatureEnabled(state, 'create-polls', false, false);
+}