Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(calendar-sync): don't prompt Google sign-in until the user asks (#18098)
MANIdd1a828963a1
diff --git a/lang/main.json b/lang/main.jsonindex 2474a19e4e..b3520a134a 100644--- a/lang/main.json+++ b/lang/main.json@@ -106,6 +106,8 @@"permissionButton": "Open settings","permissionMessage": "The Calendar permission is required to see your meetings in the app.","refresh": "Refresh calendar",+ "signInAgain": "Sign in again",+ "signInAgainMessage": "Your calendar is still connected, but you need to sign in again to see upcoming meetings.","today": "Today"},"carmode": {diff --git a/react/features/calendar-sync/actions.web.ts b/react/features/calendar-sync/actions.web.tsindex 47e7ed34d5..747c15dc0e 100644--- a/react/features/calendar-sync/actions.web.ts+++ b/react/features/calendar-sync/actions.web.ts@@ -63,12 +63,14 @@ export function bootstrapCalendarIntegration() {return dispatch(integrationToLoad._isSignedIn()).then((signedIn: boolean) => {- if (signedIn) {- dispatch(setIntegrationReady(integrationType));- dispatch(updateProfile(integrationType));- } else {- dispatch(clearCalendarIntegration());+ if (!signedIn) {+ // Keep the selected integration, so the user only+ // has to sign in again.+ return;}++ dispatch(setIntegrationReady(integrationType));+ dispatch(updateProfile(integrationType));});});};diff --git a/react/features/calendar-sync/components/CalendarList.web.tsx b/react/features/calendar-sync/components/CalendarList.web.tsxindex 5f7dfc264e..62143b0b47 100644--- a/react/features/calendar-sync/components/CalendarList.web.tsx+++ b/react/features/calendar-sync/components/CalendarList.web.tsx@@ -12,7 +12,7 @@ import AbstractPage from '../../base/react/components/AbstractPage';import Spinner from '../../base/ui/components/web/Spinner';import { openSettingsDialog } from '../../settings/actions.web';import { SETTINGS_TABS } from '../../settings/constants';-import { refreshCalendar } from '../actions.web';+import { refreshCalendar, signIn } from '../actions.web';import { ERRORS } from '../constants';import CalendarListContent from './CalendarListContent.web';@@ -29,14 +29,14 @@ interface IProps extends WithTranslation {_calendarError?: { error: string; };/**- * Whether or not a calendar may be connected for fetching calendar events.+ * Whether or not events have been fetched from a calendar.*/- _hasIntegrationSelected: boolean;+ _hasLoadedEvents: boolean;/**- * Whether or not events have been fetched from a calendar.+ * The selected calendar integration type, if any.*/- _hasLoadedEvents: boolean;+ _integrationType?: string;/*** Indicates if the list is disabled or not.@@ -67,6 +67,7 @@ class CalendarList extends AbstractPage<IProps> {this._onOpenSettings = this._onOpenSettings.bind(this);this._onKeyPressOpenSettings = this._onKeyPressOpenSettings.bind(this);this._onRefreshEvents = this._onRefreshEvents.bind(this);+ this._onSignIn = this._onSignIn.bind(this);}/**@@ -95,19 +96,31 @@ class CalendarList extends AbstractPage<IProps> {* @returns {React$Component}*/_getErrorMessage() {- const { _calendarError = { error: undefined }, t } = this.props;+ const {+ _calendarError = { error: undefined },+ _integrationType,+ t+ } = this.props;let errorMessageKey = 'calendarSync.error.generic';let showRefreshButton = true;let showSettingsButton = true;+ let showSignInButton = false;if (_calendarError.error === ERRORS.GOOGLE_APP_MISCONFIGURED) {errorMessageKey = 'calendarSync.error.appConfiguration';showRefreshButton = false;showSettingsButton = false;} else if (_calendarError.error === ERRORS.AUTH_FAILED) {- errorMessageKey = 'calendarSync.error.notSignedIn';showRefreshButton = false;++ // The selected calendar is kept, so this only needs a new sign in.+ if (_integrationType) {+ errorMessageKey = 'calendarSync.signInAgainMessage';+ showSignInButton = true;+ } else {+ errorMessageKey = 'calendarSync.error.notSignedIn';+ }}return (@@ -116,6 +129,13 @@ class CalendarList extends AbstractPage<IProps> {{ t(errorMessageKey) }</p><div className = 'calendar-action-buttons'>+ { showSignInButton+ && <div+ className = 'button'+ onClick = { this._onSignIn }>+ { t('calendarSync.signInAgain') }+ </div>+ }{ showSettingsButton&& <divclassName = 'button'@@ -145,14 +165,14 @@ class CalendarList extends AbstractPage<IProps> {_getRenderListEmptyComponent() {const {_calendarError,- _hasIntegrationSelected,_hasLoadedEvents,+ _integrationType,t} = this.props;if (_calendarError) {return this._getErrorMessage();- } else if (_hasIntegrationSelected && _hasLoadedEvents) {+ } else if (_integrationType && _hasLoadedEvents) {return (<div className = 'meetings-list-empty'><p className = 'description'>@@ -165,7 +185,7 @@ class CalendarList extends AbstractPage<IProps> {</div></div>);- } else if (_hasIntegrationSelected && !_hasLoadedEvents) {+ } else if (_integrationType && !_hasLoadedEvents) {return (<div className = 'meetings-list-empty'><Spinner />@@ -237,6 +257,21 @@ class CalendarList extends AbstractPage<IProps> {_onRefreshEvents() {this.props.dispatch(refreshCalendar(true));}++ /**+ * Signs in again to the selected calendar integration.+ *+ * @private+ * @returns {void}+ */+ _onSignIn() {+ const { _integrationType, dispatch } = this.props;++ _integrationType && dispatch(signIn(_integrationType))+ .catch(() => {+ // The error is already logged by signIn.+ });+ }}/**@@ -247,8 +282,8 @@ class CalendarList extends AbstractPage<IProps> {* @private* @returns {{* _calendarError: Object,- * _hasIntegrationSelected: boolean,- * _hasLoadedEvents: boolean+ * _hasLoadedEvents: boolean,+ * _integrationType: string* }}*/function _mapStateToProps(state: IReduxState) {@@ -261,8 +296,8 @@ function _mapStateToProps(state: IReduxState) {return {_calendarError: error,- _hasIntegrationSelected: Boolean(integrationType),- _hasLoadedEvents: Boolean(events) || !isLoadingEvents+ _hasLoadedEvents: Boolean(events) || !isLoadingEvents,+ _integrationType: integrationType};}diff --git a/react/features/calendar-sync/functions.web.ts b/react/features/calendar-sync/functions.web.tsindex f8e7ac17b6..90d6dc2e2b 100644--- a/react/features/calendar-sync/functions.web.ts+++ b/react/features/calendar-sync/functions.web.ts@@ -3,7 +3,6 @@ import { IStateful } from '../base/app/types';import { toState } from '../base/redux/functions';import {- clearCalendarIntegration,setCalendarError,setLoadingCalendarEvents} from './actions.web';@@ -87,10 +86,8 @@ export function _fetchCalendarEntries(}, (error: any) => {logger.error('Error fetching calendar.', error);- if (error.error === ERRORS.AUTH_FAILED) {- dispatch(clearCalendarIntegration());- }-+ // On AUTH_FAILED the selected integration is kept, so the user+ // only has to sign in again.dispatch(setCalendarError(error));}).then(() => dispatch(setLoadingCalendarEvents(false)));diff --git a/react/features/calendar-sync/web/microsoftCalendar.ts b/react/features/calendar-sync/web/microsoftCalendar.tsindex c9b17b31db..f498caed2b 100644--- a/react/features/calendar-sync/web/microsoftCalendar.ts+++ b/react/features/calendar-sync/web/microsoftCalendar.ts@@ -254,7 +254,13 @@ export const microsoftCalendarApi = {// token expired, let's refresh itreturn dispatch(refreshAuthToken()).then(() => true)- .catch(() => false);+ .catch(() => {+ // Drop the dead auth state, so the refresh is not+ // retried on every page load.+ dispatch(setCalendarAPIAuthState(undefined));++ return false;+ });}return Promise.resolve(state.accessToken && !isExpired);@@ -517,6 +523,10 @@ function refreshAuthToken() {return signInPromise.then(hash => {const params = getParamsFromHash(hash as string);+ if (!params.access_token) {+ return Promise.reject('Refreshing the auth token failed');+ }+dispatch(setCalendarAPIAuthState({accessToken: params.access_token,idToken: params.id_token,diff --git a/react/features/google-api/actions.ts b/react/features/google-api/actions.tsindex 682aa4a6bf..48f17f9b3c 100644--- a/react/features/google-api/actions.ts+++ b/react/features/google-api/actions.ts@@ -27,7 +27,8 @@ export function getCalendarEntries(}/**- * Loads Google API.+ * Loads Google API. It does not prompt the user to sign in, that has to be+ * started explicitly by the user with {@link signIn}.** @returns {Function}*/@@ -51,7 +52,6 @@ export function loadGoogleAPI() {return Promise.resolve();}).then(() => dispatch(setGoogleAPIState(GOOGLE_API_STATES.LOADED)))- .then(() => googleApi.signInIfNotSignedIn()).then(() => googleApi.isSignedIn()).then((isSignedIn: boolean) => {if (isSignedIn) {diff --git a/react/features/settings/components/web/CalendarTab.tsx b/react/features/settings/components/web/CalendarTab.tsxindex 65e2c2740e..2857f9e9db 100644--- a/react/features/settings/components/web/CalendarTab.tsx+++ b/react/features/settings/components/web/CalendarTab.tsx@@ -35,6 +35,12 @@ interface IProps extends WithTranslation {*/_enableMicrosoftIntegration: boolean;+ /**+ * Whether or not a calendar integration is selected, even if the user+ * still has to sign in to it again.+ */+ _hasIntegrationSelected: boolean;+/*** The current calendar integration in use, if any.*/@@ -220,6 +226,7 @@ class CalendarTab extends Component<IProps, IState> {_appName,_enableGoogleIntegration,_enableMicrosoftIntegration,+ _hasIntegrationSelected,t} = this.props;const classes = withStyles.getClasses(this.props);@@ -242,6 +249,12 @@ class CalendarTab extends Component<IProps, IState> {onClick = { this._onClickMicrosoft }text = { t('settings.calendar.microsoftSignIn') } /></div> }+ { _hasIntegrationSelected+ && <Button+ className = { classes.button }+ id = 'calendar_logout'+ label = { t('settings.calendar.disconnect') }+ onClick = { this._onClickDisconnect } /> }</>);}@@ -281,6 +294,7 @@ class CalendarTab extends Component<IProps, IState> {* _appName: string,* _enableGoogleIntegration: boolean,* _enableMicrosoftIntegration: boolean,+ * _hasIntegrationSelected: boolean,* _isConnectedToCalendar: boolean,* _profileEmail: string* }}@@ -299,6 +313,7 @@ function _mapStateToProps(state: IReduxState) {calendarEnabled && googleApiApplicationClientID),_enableMicrosoftIntegration: Boolean(calendarEnabled && microsoftApiApplicationClientID),+ _hasIntegrationSelected: Boolean(calendarState.integrationType),_isConnectedToCalendar: calendarState.integrationReady,_profileEmail: calendarState.profileEmail};