diff --git a/src/components/views/rooms/AppsDrawer.js b/src/components/views/rooms/AppsDrawer.js index 4bc98abb6f..e372cefaef 100644 --- a/src/components/views/rooms/AppsDrawer.js +++ b/src/components/views/rooms/AppsDrawer.js @@ -28,6 +28,8 @@ import ScalarMessaging from '../../../ScalarMessaging'; import { _t } from '../../../languageHandler'; import WidgetUtils from '../../../WidgetUtils'; +// The maximum number of widgets that can be added in a room +const MAX_WIDGETS = 2; module.exports = React.createClass({ displayName: 'AppsDrawer', @@ -162,6 +164,18 @@ module.exports = React.createClass({ e.preventDefault(); } + // Display a warning dialog if the max number of widgets have already been added to the room + if (this.state.apps && this.state.apps.length >= MAX_WIDGETS) { + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + const errorMsg = `The maximum number of ${MAX_WIDGETS} widgets have already been added to this room.`; + console.error(errorMsg); + Modal.createDialog(ErrorDialog, { + title: _t("Cannot add any more widgets"), + description: _t("The maximum permitted number of widgets have already been added to this room."), + }); + return; + } + const IntegrationsManager = sdk.getComponent("views.settings.IntegrationsManager"); const src = (this.scalarClient !== null && this.scalarClient.hasCredentials()) ? this.scalarClient.getScalarInterfaceUrlForRoom(this.props.room.roomId, 'add_integ') : @@ -186,21 +200,22 @@ module.exports = React.createClass({ />); }); - const addWidget = this.state.apps && this.state.apps.length < 2 && this._canUserModify() && - (
- [+] {_t('Add a widget')} -
); + const addWidget = ( +
+ [+] {_t('Add a widget')} +
+ ); return (
{apps}
- {addWidget} + {this._canUserModify() && addWidget}
); }, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 83be31de4b..4c16e0f2eb 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -190,6 +190,7 @@ "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate is trusted, and that a browser extension is not blocking requests.": "Can't connect to homeserver - please check your connectivity, ensure your homeserver's SSL certificate is trusted, and that a browser extension is not blocking requests.", "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.": "Can't connect to homeserver via HTTP when an HTTPS URL is in your browser bar. Either use HTTPS or enable unsafe scripts.", "Can't load user settings": "Can't load user settings", + "Cannot add any more widgets": "Cannot add any more widgets", "Change Password": "Change Password", "%(senderName)s changed their display name from %(oldDisplayName)s to %(displayName)s.": "%(senderName)s changed their display name from %(oldDisplayName)s to %(displayName)s.", "%(senderName)s changed their profile picture.": "%(senderName)s changed their profile picture.", @@ -547,6 +548,7 @@ "Tagged as: ": "Tagged as: ", "The default role for new room members is": "The default role for new room members is", "The main address for this room is": "The main address for this room is", + "The maximum permitted number of widgets have already been added to this room.": "The maximum permitted number of widgets have already been added to this room.", "The phone number entered looks invalid": "The phone number entered looks invalid", "The signing key you provided matches the signing key you received from %(userId)s's device %(deviceId)s. Device marked as verified.": "The signing key you provided matches the signing key you received from %(userId)s's device %(deviceId)s. Device marked as verified.", "This action cannot be performed by a guest user. Please register to be able to do this.": "This action cannot be performed by a guest user. Please register to be able to do this.",