浏览代码

[RN] Legacy support of calendar-sync's knownDomains

Knowledge is power, man!

We moved "knownDomains" from calendar-sync to base/known-domains.
However, we do have an official release in the app stores and I'd like
us to not throw away the knowledge it has acquired.
j8
Lyubo Marinov 7 年前
父节点
当前提交
631f51d627
共有 2 个文件被更改,包括 68 次插入19 次删除
  1. 47
    15
      react/features/calendar-sync/middleware.js
  2. 21
    4
      react/features/calendar-sync/reducer.js

+ 47
- 15
react/features/calendar-sync/middleware.js 查看文件

3
 import RNCalendarEvents from 'react-native-calendar-events';
3
 import RNCalendarEvents from 'react-native-calendar-events';
4
 
4
 
5
 import { APP_WILL_MOUNT } from '../app';
5
 import { APP_WILL_MOUNT } from '../app';
6
-import { ADD_KNOWN_DOMAINS } from '../base/known-domains';
6
+import { ADD_KNOWN_DOMAINS, addKnownDomains } from '../base/known-domains';
7
 import { MiddlewareRegistry } from '../base/redux';
7
 import { MiddlewareRegistry } from '../base/redux';
8
 import { APP_LINK_SCHEME, parseURIString } from '../base/util';
8
 import { APP_LINK_SCHEME, parseURIString } from '../base/util';
9
 import { APP_STATE_CHANGED } from '../mobile/background';
9
 import { APP_STATE_CHANGED } from '../mobile/background';
31
 
31
 
32
 CALENDAR_ENABLED
32
 CALENDAR_ENABLED
33
     && MiddlewareRegistry.register(store => next => action => {
33
     && MiddlewareRegistry.register(store => next => action => {
34
-        const result = next(action);
35
-
36
         switch (action.type) {
34
         switch (action.type) {
37
-        case ADD_KNOWN_DOMAINS:
38
-        case APP_WILL_MOUNT:
39
-            _fetchCalendarEntries(store, false, false);
40
-            break;
35
+        case ADD_KNOWN_DOMAINS: {
36
+            // XXX Fetch new calendar entries only when an actual domain has
37
+            // become known.
38
+            const { getState } = store;
39
+            const oldValue = getState()['features/base/known-domains'];
40
+            const result = next(action);
41
+            const newValue = getState()['features/base/known-domains'];
42
+
43
+            oldValue === newValue || _fetchCalendarEntries(store, false, false);
44
+
45
+            return result;
46
+        }
47
+
48
+        case APP_STATE_CHANGED: {
49
+            const result = next(action);
41
 
50
 
42
-        case APP_STATE_CHANGED:
43
             _maybeClearAccessStatus(store, action);
51
             _maybeClearAccessStatus(store, action);
44
-            break;
45
 
52
 
46
-        case REFRESH_CALENDAR:
53
+            return result;
54
+        }
55
+
56
+        case APP_WILL_MOUNT: {
57
+            // For legacy purposes, we've allowed the deserialization of
58
+            // knownDomains and now we're to translate it to base/known-domains.
59
+            const state = store.getState()['features/calendar-sync'];
60
+
61
+            if (state) {
62
+                const { knownDomains } = state;
63
+
64
+                Array.isArray(knownDomains)
65
+                    && knownDomains.length
66
+                    && store.dispatch(addKnownDomains(knownDomains));
67
+            }
68
+
69
+            const result = next(action);
70
+
71
+            _fetchCalendarEntries(store, false, false);
72
+
73
+            return result;
74
+        }
75
+
76
+        case REFRESH_CALENDAR: {
77
+            const result = next(action);
78
+
47
             _fetchCalendarEntries(store, true, action.forcePermission);
79
             _fetchCalendarEntries(store, true, action.forcePermission);
48
-            break;
80
+
81
+            return result;
82
+        }
49
         }
83
         }
50
 
84
 
51
-        return result;
85
+        return next(action);
52
     });
86
     });
53
 
87
 
54
 /**
88
 /**
122
                 logger.warn('Calendar access not granted.');
156
                 logger.warn('Calendar access not granted.');
123
             }
157
             }
124
         })
158
         })
125
-        .catch(reason => {
126
-            logger.error('Error accessing calendar.', reason);
127
-        });
159
+        .catch(reason => logger.error('Error accessing calendar.', reason));
128
 }
160
 }
129
 
161
 
130
 /**
162
 /**

+ 21
- 4
react/features/calendar-sync/reducer.js 查看文件

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { ReducerRegistry } from '../base/redux';
3
+import { APP_WILL_MOUNT } from '../app';
4
+import { ReducerRegistry, set } from '../base/redux';
5
+import { PersistenceRegistry } from '../base/storage';
4
 
6
 
5
 import {
7
 import {
6
     SET_CALENDAR_AUTHORIZATION,
8
     SET_CALENDAR_AUTHORIZATION,
20
 
22
 
21
 const STORE_NAME = 'features/calendar-sync';
23
 const STORE_NAME = 'features/calendar-sync';
22
 
24
 
25
+// XXX For legacy purposes, read any {@code knownDomains} persisted by the
26
+// feature calendar-sync.
27
+CALENDAR_ENABLED
28
+    && PersistenceRegistry.register(STORE_NAME, {
29
+        knownDomains: true
30
+    });
31
+
23
 CALENDAR_ENABLED
32
 CALENDAR_ENABLED
24
     && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
33
     && ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
25
         switch (action.type) {
34
         switch (action.type) {
35
+        case APP_WILL_MOUNT:
36
+            // For legacy purposes, we've allowed the deserialization of
37
+            // knownDomains. At this point, it should have already been
38
+            // translated into the new state format (namely, base/known-domains)
39
+            // and the app no longer needs it.
40
+            if (typeof state.knownDomains !== 'undefined') {
41
+                return set(state, 'knownDomains', undefined);
42
+            }
43
+            break;
26
 
44
 
27
         case SET_CALENDAR_AUTHORIZATION:
45
         case SET_CALENDAR_AUTHORIZATION:
28
             return {
46
             return {
35
                 ...state,
53
                 ...state,
36
                 events: action.events
54
                 events: action.events
37
             };
55
             };
38
-
39
-        default:
40
-            return state;
41
         }
56
         }
57
+
58
+        return state;
42
     });
59
     });

正在加载...
取消
保存