소스 검색

Properly gate calendar feature on-off

master
zbettenbuk 7 년 전
부모
커밋
374e3ccf2c

+ 1
- 1
react/features/calendar-sync/components/ConferenceNotification.native.js 파일 보기

@@ -267,7 +267,7 @@ class ConferenceNotification extends Component<Props, State> {
267 267
  *     _eventList: Array
268 268
  * }}
269 269
  */
270
-export function _mapStateToProps(state: Object) {
270
+function _mapStateToProps(state: Object) {
271 271
     const { locationURL } = state['features/base/connection'];
272 272
 
273 273
     return {

+ 22
- 17
react/features/calendar-sync/components/MeetingList.native.js 파일 보기

@@ -10,6 +10,7 @@ import { NavigateSectionList } from '../../base/react';
10 10
 import { openSettings } from '../../mobile/permissions';
11 11
 
12 12
 import { refreshCalendar } from '../actions';
13
+import { CALENDAR_ENABLED } from '../constants';
13 14
 import styles from './styles';
14 15
 
15 16
 type Props = {
@@ -59,6 +60,23 @@ class MeetingList extends Component<Props> {
59 60
         _eventList: []
60 61
     };
61 62
 
63
+    /**
64
+     * Public API method for {@code Component}s rendered in
65
+     * {@link AbstractPagedList}. When invoked, refreshes the calendar entries
66
+     * in the app.
67
+     *
68
+     * Note: It is a static method as the {@code Component} may not be
69
+     * initialized yet when the UI invokes refresh (e.g. {@link TabBarIOS} tab
70
+     * change).
71
+     *
72
+     * @param {Function} dispatch - The Redux dispatch function.
73
+     * @public
74
+     * @returns {void}
75
+     */
76
+    static refresh(dispatch) {
77
+        dispatch(refreshCalendar());
78
+    }
79
+
62 80
     /**
63 81
      * Constructor of the MeetingList component.
64 82
      *
@@ -82,21 +100,6 @@ class MeetingList extends Component<Props> {
82 100
         this._toDateString = this._toDateString.bind(this);
83 101
     }
84 102
 
85
-    /**
86
-     * Implements React Component's componentWillReceiveProps.
87
-     *
88
-     * @inheritdoc
89
-     */
90
-    componentWillReceiveProps(newProps) {
91
-        const { displayed } = this.props;
92
-
93
-        if (newProps.displayed && !displayed) {
94
-            const { dispatch } = this.props;
95
-
96
-            dispatch(refreshCalendar());
97
-        }
98
-    }
99
-
100 103
     /**
101 104
      * Implements the React Components's render.
102 105
      *
@@ -266,7 +269,7 @@ class MeetingList extends Component<Props> {
266 269
  *     _eventList: Array
267 270
  * }}
268 271
  */
269
-export function _mapStateToProps(state: Object) {
272
+function _mapStateToProps(state: Object) {
270 273
     const calendarSyncState = state['features/calendar-sync'];
271 274
 
272 275
     return {
@@ -275,4 +278,6 @@ export function _mapStateToProps(state: Object) {
275 278
     };
276 279
 }
277 280
 
278
-export default translate(connect(_mapStateToProps)(MeetingList));
281
+export default CALENDAR_ENABLED
282
+    ? translate(connect(_mapStateToProps)(MeetingList))
283
+    : undefined;

+ 26
- 0
react/features/calendar-sync/constants.js 파일 보기

@@ -0,0 +1,26 @@
1
+// @flow
2
+
3
+import { NativeModules } from 'react-native';
4
+
5
+/**
6
+ * The indicator which determines whether the calendar feature is enabled by the
7
+ * app.
8
+ *
9
+ * @type {boolean}
10
+ */
11
+export const CALENDAR_ENABLED = _isCalendarEnabled();
12
+
13
+/**
14
+ * Determines whether the calendar feature is enabled by the app. For
15
+ * example, Apple through its App Store requires
16
+ * {@code NSCalendarsUsageDescription} in the app's Info.plist or App Store
17
+ * rejects the app.
18
+ *
19
+ * @returns {boolean} If the app has enabled the calendar feature, {@code true};
20
+ * otherwise, {@code false}.
21
+ */
22
+function _isCalendarEnabled() {
23
+    const { calendarEnabled } = NativeModules.AppInfo;
24
+
25
+    return typeof calendarEnabled === 'undefined' ? true : calendarEnabled;
26
+}

+ 0
- 1
react/features/calendar-sync/index.js 파일 보기

@@ -1,4 +1,3 @@
1
-export * from './actions';
2 1
 export * from './components';
3 2
 
4 3
 import './middleware';

+ 21
- 39
react/features/calendar-sync/middleware.js 파일 보기

@@ -1,6 +1,5 @@
1 1
 // @flow
2 2
 
3
-import { NativeModules } from 'react-native';
4 3
 import RNCalendarEvents from 'react-native-calendar-events';
5 4
 
6 5
 import { APP_WILL_MOUNT } from '../app';
@@ -15,6 +14,7 @@ import {
15 14
     setCalendarEvents
16 15
 } from './actions';
17 16
 import { REFRESH_CALENDAR } from './actionTypes';
17
+import { CALENDAR_ENABLED } from './constants';
18 18
 
19 19
 const logger = require('jitsi-meet-logger').getLogger(__filename);
20 20
 
@@ -22,30 +22,31 @@ const FETCH_END_DAYS = 10;
22 22
 const FETCH_START_DAYS = -1;
23 23
 const MAX_LIST_LENGTH = 10;
24 24
 
25
-MiddlewareRegistry.register(store => next => action => {
26
-    const result = next(action);
25
+CALENDAR_ENABLED
26
+    && MiddlewareRegistry.register(store => next => action => {
27
+        const result = next(action);
27 28
 
28
-    switch (action.type) {
29
-    case APP_STATE_CHANGED:
30
-        _maybeClearAccessStatus(store, action);
31
-        break;
29
+        switch (action.type) {
30
+        case APP_STATE_CHANGED:
31
+            _maybeClearAccessStatus(store, action);
32
+            break;
32 33
 
33
-    case APP_WILL_MOUNT:
34
-        _ensureDefaultServer(store);
35
-        _fetchCalendarEntries(store, false, false);
36
-        break;
34
+        case APP_WILL_MOUNT:
35
+            _ensureDefaultServer(store);
36
+            _fetchCalendarEntries(store, false, false);
37
+            break;
37 38
 
38
-    case REFRESH_CALENDAR:
39
-        _fetchCalendarEntries(store, true, action.forcePermission);
40
-        break;
39
+        case REFRESH_CALENDAR:
40
+            _fetchCalendarEntries(store, true, action.forcePermission);
41
+            break;
41 42
 
42
-    case SET_ROOM:
43
-        _parseAndAddKnownDomain(store);
44
-        break;
45
-    }
43
+        case SET_ROOM:
44
+            _parseAndAddKnownDomain(store);
45
+            break;
46
+        }
46 47
 
47
-    return result;
48
-});
48
+        return result;
49
+    });
49 50
 
50 51
 /**
51 52
  * Clears the calendar access status when the app comes back from the
@@ -123,11 +124,6 @@ function _fetchCalendarEntries(
123 124
         { dispatch, getState },
124 125
         maybePromptForPermission,
125 126
         forcePermission) {
126
-    if (!_isCalendarEnabled()) {
127
-        // The calendar feature is not enabled.
128
-        return;
129
-    }
130
-
131 127
     const state = getState()['features/calendar-sync'];
132 128
     const promptForPermission
133 129
         = (maybePromptForPermission && !state.authorization)
@@ -203,20 +199,6 @@ function _getURLFromEvent(event, knownDomains) {
203 199
     return null;
204 200
 }
205 201
 
206
-/**
207
- * Determines whether the calendar feature is enabled by the app. For
208
- * example, Apple through its App Store requires NSCalendarsUsageDescription in
209
- * the app's Info.plist or App Store rejects the app.
210
- *
211
- * @returns {boolean} If the app has enabled the calendar feature, {@code true};
212
- * otherwise, {@code false}.
213
- */
214
-export function _isCalendarEnabled() {
215
-    const { calendarEnabled } = NativeModules.AppInfo;
216
-
217
-    return typeof calendarEnabled === 'undefined' ? true : calendarEnabled;
218
-}
219
-
220 202
 /**
221 203
  * Retrieves the domain name of a room upon join and stores it in the known
222 204
  * domain list, if not present yet.

+ 28
- 25
react/features/calendar-sync/reducer.js 파일 보기

@@ -8,6 +8,7 @@ import {
8 8
     SET_CALENDAR_AUTHORIZATION,
9 9
     SET_CALENDAR_EVENTS
10 10
 } from './actionTypes';
11
+import { CALENDAR_ENABLED } from './constants';
11 12
 
12 13
 const DEFAULT_STATE = {
13 14
     /**
@@ -24,31 +25,33 @@ const MAX_DOMAIN_LIST_SIZE = 10;
24 25
 
25 26
 const STORE_NAME = 'features/calendar-sync';
26 27
 
27
-PersistenceRegistry.register(STORE_NAME, {
28
-    knownDomains: true
29
-});
30
-
31
-ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
32
-    switch (action.type) {
33
-    case ADD_KNOWN_DOMAIN:
34
-        return _addKnownDomain(state, action);
35
-
36
-    case SET_CALENDAR_AUTHORIZATION:
37
-        return {
38
-            ...state,
39
-            authorization: action.status
40
-        };
41
-
42
-    case SET_CALENDAR_EVENTS:
43
-        return {
44
-            ...state,
45
-            events: action.events
46
-        };
47
-
48
-    default:
49
-        return state;
50
-    }
51
-});
28
+CALENDAR_ENABLED
29
+    && PersistenceRegistry.register(STORE_NAME, {
30
+        knownDomains: true
31
+    });
32
+
33
+CALENDAR_ENABLED
34
+    && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
35
+        switch (action.type) {
36
+        case ADD_KNOWN_DOMAIN:
37
+            return _addKnownDomain(state, action);
38
+
39
+        case SET_CALENDAR_AUTHORIZATION:
40
+            return {
41
+                ...state,
42
+                authorization: action.status
43
+            };
44
+
45
+        case SET_CALENDAR_EVENTS:
46
+            return {
47
+                ...state,
48
+                events: action.events
49
+            };
50
+
51
+        default:
52
+            return state;
53
+        }
54
+    });
52 55
 
53 56
 /**
54 57
  * Adds a new domain to the known domain list if not present yet.

+ 0
- 53
react/features/welcome/components/AbstractPagedList.js 파일 보기

@@ -1,53 +0,0 @@
1
-// @flow
2
-
3
-import { Component } from 'react';
4
-
5
-/**
6
- * The page to be displayed on render.
7
- */
8
-export const DEFAULT_PAGE = 0;
9
-
10
-type Props = {
11
-
12
-    /**
13
-     * Indicates if the list is disabled or not.
14
-     */
15
-    disabled: boolean,
16
-
17
-    /**
18
-     * The Redux dispatch function.
19
-     */
20
-    dispatch: Function,
21
-
22
-    /**
23
-     * The i18n translate function
24
-     */
25
-    t: Function
26
-}
27
-
28
-type State = {
29
-
30
-    /**
31
-     * The currently selected page.
32
-     */
33
-    pageIndex: number
34
-}
35
-
36
-/**
37
- * Abstract class for the platform specific paged lists.
38
- */
39
-export default class AbstractPagedList extends Component<Props, State> {
40
-    /**
41
-     * Constructor of the component.
42
-     *
43
-     * @inheritdoc
44
-     */
45
-    constructor(props: Props) {
46
-        super(props);
47
-
48
-        this.state = {
49
-            pageIndex: DEFAULT_PAGE
50
-        };
51
-    }
52
-
53
-}

+ 91
- 0
react/features/welcome/components/AbstractPagedList.native.js 파일 보기

@@ -0,0 +1,91 @@
1
+// @flow
2
+
3
+import React, { Component } from 'react';
4
+import { View } from 'react-native';
5
+import { isCalendarEnabled } from '../../calendar-sync';
6
+import { RecentList } from '../../recent-list';
7
+
8
+import styles from './styles';
9
+
10
+/**
11
+ * The page to be displayed on render.
12
+ */
13
+export const DEFAULT_PAGE = 0;
14
+
15
+type Props = {
16
+
17
+    /**
18
+     * Indicates if the list is disabled or not.
19
+     */
20
+    disabled: boolean,
21
+
22
+    /**
23
+     * The Redux dispatch function.
24
+     */
25
+    dispatch: Function,
26
+
27
+    /**
28
+     * The i18n translate function
29
+     */
30
+    t: Function
31
+}
32
+
33
+type State = {
34
+
35
+    /**
36
+     * The currently selected page.
37
+     */
38
+    pageIndex: number
39
+}
40
+
41
+/**
42
+ * Abstract class for the platform specific paged lists.
43
+ */
44
+export default class AbstractPagedList extends Component<Props, State> {
45
+    /**
46
+     * True if the calendar feature is enabled on the platform, false otherwise.
47
+     */
48
+    _calendarEnabled: boolean
49
+
50
+    /**
51
+     * Constructor of the component.
52
+     *
53
+     * @inheritdoc
54
+     */
55
+    constructor(props: Props) {
56
+        super(props);
57
+
58
+        this._calendarEnabled = isCalendarEnabled();
59
+
60
+        this.state = {
61
+            pageIndex: DEFAULT_PAGE
62
+        };
63
+    }
64
+
65
+    /**
66
+     * Renders the component.
67
+     *
68
+     * @inheritdoc
69
+     */
70
+    render() {
71
+        const { disabled } = this.props;
72
+
73
+        return (
74
+            <View
75
+                style = { [
76
+                    styles.pagedListContainer,
77
+                    disabled ? styles.pagedListContainerDisabled : null
78
+                ] }>
79
+                {
80
+                    (this._calendarEnabled && this._renderPagedList(disabled))
81
+                    || <RecentList
82
+                        disabled = { disabled }
83
+                        style = { styles.pagedList } />
84
+                }
85
+            </View>
86
+        );
87
+    }
88
+
89
+    _renderPagedList: boolean => Object
90
+
91
+}

+ 0
- 0
react/features/welcome/components/AbstractPagedList.web.js 파일 보기


+ 6
- 9
react/features/welcome/components/PagedList.android.js 파일 보기

@@ -35,20 +35,17 @@ export default class PagedList extends AbstractPagedList {
35 35
     }
36 36
 
37 37
     /**
38
-     * Renders the paged list.
38
+     * Renders the entire paged list if calendar is enabled.
39 39
      *
40
-     * @inheritdoc
40
+     * @param {boolean} disabled - True if the rendered lists should be
41
+     * disabled.
42
+     * @returns {ReactElement}
41 43
      */
42
-    render() {
43
-        const { disabled } = this.props;
44
+    _renderPagedList(disabled) {
44 45
         const { pageIndex } = this.state;
45 46
 
46 47
         return (
47
-            <View
48
-                style = { [
49
-                    styles.pagedListContainer,
50
-                    disabled ? styles.pagedListContainerDisabled : null
51
-                ] }>
48
+            <View style = { styles.pagedListContainer }>
52 49
                 <ViewPagerAndroid
53 50
                     initialPage = { DEFAULT_PAGE }
54 51
                     onPageSelected = { this._onPageSelected }

+ 25
- 29
react/features/welcome/components/PagedList.ios.js 파일 보기

@@ -1,7 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import React from 'react';
4
-import { View, TabBarIOS } from 'react-native';
4
+import { TabBarIOS } from 'react-native';
5 5
 import { connect } from 'react-redux';
6 6
 
7 7
 import { translate } from '../../base/i18n';
@@ -31,39 +31,35 @@ class PagedList extends AbstractPagedList {
31 31
     }
32 32
 
33 33
     /**
34
-     * Renders the paged list.
34
+     * Renders the entire paged list if calendar is enabled.
35 35
      *
36
-     * @inheritdoc
36
+     * @param {boolean} disabled - True if the rendered lists should be
37
+     * disabled.
38
+     * @returns {ReactElement}
37 39
      */
38
-    render() {
40
+    _renderPagedList(disabled) {
39 41
         const { pageIndex } = this.state;
40
-        const { disabled, t } = this.props;
42
+        const { t } = this.props;
41 43
 
42 44
         return (
43
-            <View
44
-                style = { [
45
-                    styles.pagedListContainer,
46
-                    disabled ? styles.pagedListContainerDisabled : null
47
-                ] }>
48
-                <TabBarIOS
49
-                    itemPositioning = 'fill'
50
-                    style = { styles.pagedList }>
51
-                    <TabBarIOS.Item
52
-                        onPress = { this._onTabSelected(0) }
53
-                        selected = { pageIndex === 0 }
54
-                        systemIcon = 'history' >
55
-                        <RecentList disabled = { disabled } />
56
-                    </TabBarIOS.Item>
57
-                    <TabBarIOS.Item
58
-                        icon = { CALENDAR_ICON }
59
-                        onPress = { this._onTabSelected(1) }
60
-                        selected = { pageIndex === 1 }
61
-                        title = { t('welcomepage.calendar') } >
62
-                        <MeetingList
63
-                            disabled = { disabled } />
64
-                    </TabBarIOS.Item>
65
-                </TabBarIOS>
66
-            </View>
45
+            <TabBarIOS
46
+                itemPositioning = 'fill'
47
+                style = { styles.pagedList }>
48
+                <TabBarIOS.Item
49
+                    onPress = { this._onTabSelected(0) }
50
+                    selected = { pageIndex === 0 }
51
+                    systemIcon = 'history' >
52
+                    <RecentList disabled = { disabled } />
53
+                </TabBarIOS.Item>
54
+                <TabBarIOS.Item
55
+                    icon = { CALENDAR_ICON }
56
+                    onPress = { this._onTabSelected(1) }
57
+                    selected = { pageIndex === 1 }
58
+                    title = { t('welcomepage.calendar') } >
59
+                    <MeetingList
60
+                        disabled = { disabled } />
61
+                </TabBarIOS.Item>
62
+            </TabBarIOS>
67 63
         );
68 64
     }
69 65
 

Loading…
취소
저장