|
|
@@ -1,296 +0,0 @@
|
|
1
|
|
-// @flow
|
|
2
|
|
-
|
|
3
|
|
-import React, { Component } from 'react';
|
|
4
|
|
-import { Text, TouchableOpacity, View } from 'react-native';
|
|
5
|
|
-
|
|
6
|
|
-import { appNavigate } from '../../app/actions';
|
|
7
|
|
-import { getURLWithoutParamsNormalized } from '../../base/connection';
|
|
8
|
|
-import { getLocalizedDateFormatter, translate } from '../../base/i18n';
|
|
9
|
|
-import { Icon, IconArrowRight } from '../../base/icons';
|
|
10
|
|
-import { connect } from '../../base/redux';
|
|
11
|
|
-import { ASPECT_RATIO_NARROW } from '../../base/responsive-ui';
|
|
12
|
|
-
|
|
13
|
|
-import styles from './styles';
|
|
14
|
|
-
|
|
15
|
|
-const ALERT_MILLISECONDS = 5 * 60 * 1000;
|
|
16
|
|
-
|
|
17
|
|
-/**
|
|
18
|
|
- * The type of the React {@code Component} props of
|
|
19
|
|
- * {@link ConferenceNotification}.
|
|
20
|
|
- */
|
|
21
|
|
-type Props = {
|
|
22
|
|
-
|
|
23
|
|
- /**
|
|
24
|
|
- * The current aspect ratio of the screen.
|
|
25
|
|
- */
|
|
26
|
|
- _aspectRatio: Symbol,
|
|
27
|
|
-
|
|
28
|
|
- /**
|
|
29
|
|
- * The URL of the current conference without params.
|
|
30
|
|
- */
|
|
31
|
|
- _currentConferenceURL: string,
|
|
32
|
|
-
|
|
33
|
|
- /**
|
|
34
|
|
- * The calendar event list.
|
|
35
|
|
- */
|
|
36
|
|
- _eventList: Array<Object>,
|
|
37
|
|
-
|
|
38
|
|
- /**
|
|
39
|
|
- * The Redux dispatch function.
|
|
40
|
|
- */
|
|
41
|
|
- dispatch: Function,
|
|
42
|
|
-
|
|
43
|
|
- /**
|
|
44
|
|
- * The translate function.
|
|
45
|
|
- */
|
|
46
|
|
- t: Function
|
|
47
|
|
-};
|
|
48
|
|
-
|
|
49
|
|
-/**
|
|
50
|
|
- * The type of the React {@code Component} state of
|
|
51
|
|
- * {@link ConferenceNotification}.
|
|
52
|
|
- */
|
|
53
|
|
-type State = {
|
|
54
|
|
-
|
|
55
|
|
- /**
|
|
56
|
|
- * The event object to display the notification for.
|
|
57
|
|
- */
|
|
58
|
|
- event?: Object
|
|
59
|
|
-};
|
|
60
|
|
-
|
|
61
|
|
-/**
|
|
62
|
|
- * Component to display a permanent badge-like notification on the conference
|
|
63
|
|
- * screen when another meeting is about to start.
|
|
64
|
|
- */
|
|
65
|
|
-class ConferenceNotification extends Component<Props, State> {
|
|
66
|
|
- updateIntervalId: IntervalID;
|
|
67
|
|
-
|
|
68
|
|
- /**
|
|
69
|
|
- * Constructor of the ConferenceNotification component.
|
|
70
|
|
- *
|
|
71
|
|
- * @inheritdoc
|
|
72
|
|
- */
|
|
73
|
|
- constructor(props: Props) {
|
|
74
|
|
- super(props);
|
|
75
|
|
-
|
|
76
|
|
- this.state = {
|
|
77
|
|
- event: undefined
|
|
78
|
|
- };
|
|
79
|
|
-
|
|
80
|
|
- // Bind event handlers so they are only bound once per instance.
|
|
81
|
|
- this._getNotificationContentStyle
|
|
82
|
|
- = this._getNotificationContentStyle.bind(this);
|
|
83
|
|
- this._getNotificationPosition
|
|
84
|
|
- = this._getNotificationPosition.bind(this);
|
|
85
|
|
- this._maybeDisplayNotification
|
|
86
|
|
- = this._maybeDisplayNotification.bind(this);
|
|
87
|
|
- this._onGoToNext = this._onGoToNext.bind(this);
|
|
88
|
|
- }
|
|
89
|
|
-
|
|
90
|
|
- /**
|
|
91
|
|
- * Implements React Component's componentDidMount.
|
|
92
|
|
- *
|
|
93
|
|
- * @inheritdoc
|
|
94
|
|
- */
|
|
95
|
|
- componentDidMount() {
|
|
96
|
|
- this.updateIntervalId = setInterval(
|
|
97
|
|
- this._maybeDisplayNotification,
|
|
98
|
|
- 10 * 1000
|
|
99
|
|
- );
|
|
100
|
|
- }
|
|
101
|
|
-
|
|
102
|
|
- /**
|
|
103
|
|
- * Implements React Component's componentWillUnmount.
|
|
104
|
|
- *
|
|
105
|
|
- * @inheritdoc
|
|
106
|
|
- */
|
|
107
|
|
- componentWillUnmount() {
|
|
108
|
|
- clearInterval(this.updateIntervalId);
|
|
109
|
|
- }
|
|
110
|
|
-
|
|
111
|
|
- /**
|
|
112
|
|
- * Implements the React Components's render.
|
|
113
|
|
- *
|
|
114
|
|
- * @inheritdoc
|
|
115
|
|
- */
|
|
116
|
|
- render() {
|
|
117
|
|
- const { event } = this.state;
|
|
118
|
|
- const { t } = this.props;
|
|
119
|
|
-
|
|
120
|
|
- if (event) {
|
|
121
|
|
- const now = Date.now();
|
|
122
|
|
- const label
|
|
123
|
|
- = event.startDate < now && event.endDate > now
|
|
124
|
|
- ? 'calendarSync.ongoingMeeting'
|
|
125
|
|
- : 'calendarSync.nextMeeting';
|
|
126
|
|
-
|
|
127
|
|
- return (
|
|
128
|
|
- <View
|
|
129
|
|
- style = { [
|
|
130
|
|
- styles.notificationContainer,
|
|
131
|
|
- this._getNotificationPosition()
|
|
132
|
|
- ] } >
|
|
133
|
|
- <View
|
|
134
|
|
- style = { this._getNotificationContentStyle() }>
|
|
135
|
|
- <TouchableOpacity
|
|
136
|
|
- onPress = { this._onGoToNext } >
|
|
137
|
|
- <View style = { styles.touchableView }>
|
|
138
|
|
- <View
|
|
139
|
|
- style = {
|
|
140
|
|
- styles.notificationTextContainer
|
|
141
|
|
- }>
|
|
142
|
|
- <Text style = { styles.notificationText }>
|
|
143
|
|
- { t(label) }
|
|
144
|
|
- </Text>
|
|
145
|
|
- <Text style = { styles.notificationText }>
|
|
146
|
|
- {
|
|
147
|
|
- getLocalizedDateFormatter(
|
|
148
|
|
- event.startDate
|
|
149
|
|
- ).fromNow()
|
|
150
|
|
- }
|
|
151
|
|
- </Text>
|
|
152
|
|
- </View>
|
|
153
|
|
- <View
|
|
154
|
|
- style = {
|
|
155
|
|
- styles.notificationIconContainer
|
|
156
|
|
- }>
|
|
157
|
|
- <Icon
|
|
158
|
|
- src = { IconArrowRight }
|
|
159
|
|
- style = { styles.notificationIcon } />
|
|
160
|
|
- </View>
|
|
161
|
|
- </View>
|
|
162
|
|
- </TouchableOpacity>
|
|
163
|
|
- </View>
|
|
164
|
|
- </View>
|
|
165
|
|
- );
|
|
166
|
|
- }
|
|
167
|
|
-
|
|
168
|
|
- return null;
|
|
169
|
|
- }
|
|
170
|
|
-
|
|
171
|
|
- _getNotificationContentStyle: () => Array<Object>;
|
|
172
|
|
-
|
|
173
|
|
- /**
|
|
174
|
|
- * Decides the color of the notification and some additional
|
|
175
|
|
- * styles based on notificationPosition.
|
|
176
|
|
- *
|
|
177
|
|
- * @private
|
|
178
|
|
- * @returns {Array<Object>}
|
|
179
|
|
- */
|
|
180
|
|
- _getNotificationContentStyle() {
|
|
181
|
|
- const { event } = this.state;
|
|
182
|
|
- const { _aspectRatio } = this.props;
|
|
183
|
|
- const now = Date.now();
|
|
184
|
|
- const style = [
|
|
185
|
|
- styles.notificationContent
|
|
186
|
|
- ];
|
|
187
|
|
-
|
|
188
|
|
- if (event && event.startDate < now && event.endDate > now) {
|
|
189
|
|
- style.push(styles.notificationContentPast);
|
|
190
|
|
- } else {
|
|
191
|
|
- style.push(styles.notificationContentNext);
|
|
192
|
|
- }
|
|
193
|
|
-
|
|
194
|
|
- if (_aspectRatio === ASPECT_RATIO_NARROW) {
|
|
195
|
|
- style.push(styles.notificationContentSide);
|
|
196
|
|
- } else {
|
|
197
|
|
- style.push(styles.notificationContentTop);
|
|
198
|
|
- }
|
|
199
|
|
-
|
|
200
|
|
- return style;
|
|
201
|
|
- }
|
|
202
|
|
-
|
|
203
|
|
- _getNotificationPosition: () => Object;
|
|
204
|
|
-
|
|
205
|
|
- /**
|
|
206
|
|
- * Decides the position of the notification.
|
|
207
|
|
- *
|
|
208
|
|
- * @private
|
|
209
|
|
- * @returns {Object}
|
|
210
|
|
- */
|
|
211
|
|
- _getNotificationPosition() {
|
|
212
|
|
- const { _aspectRatio } = this.props;
|
|
213
|
|
-
|
|
214
|
|
- if (_aspectRatio === ASPECT_RATIO_NARROW) {
|
|
215
|
|
- return styles.notificationContainerSide;
|
|
216
|
|
- }
|
|
217
|
|
-
|
|
218
|
|
- return styles.notificationContainerTop;
|
|
219
|
|
- }
|
|
220
|
|
-
|
|
221
|
|
- _maybeDisplayNotification: () => void;
|
|
222
|
|
-
|
|
223
|
|
- /**
|
|
224
|
|
- * Periodically checks if there is an event in the calendar for which we
|
|
225
|
|
- * need to show a notification.
|
|
226
|
|
- *
|
|
227
|
|
- * @private
|
|
228
|
|
- * @returns {void}
|
|
229
|
|
- */
|
|
230
|
|
- _maybeDisplayNotification() {
|
|
231
|
|
- const { _currentConferenceURL, _eventList } = this.props;
|
|
232
|
|
- let eventToShow;
|
|
233
|
|
-
|
|
234
|
|
- if (_eventList && _eventList.length) {
|
|
235
|
|
- const now = Date.now();
|
|
236
|
|
-
|
|
237
|
|
- for (const event of _eventList) {
|
|
238
|
|
- const eventUrl
|
|
239
|
|
- = event.url
|
|
240
|
|
- && getURLWithoutParamsNormalized(new URL(event.url));
|
|
241
|
|
-
|
|
242
|
|
- if (eventUrl && eventUrl !== _currentConferenceURL) {
|
|
243
|
|
- if ((!eventToShow
|
|
244
|
|
- && event.startDate > now
|
|
245
|
|
- && event.startDate < now + ALERT_MILLISECONDS)
|
|
246
|
|
- || (event.startDate < now && event.endDate > now)) {
|
|
247
|
|
- eventToShow = event;
|
|
248
|
|
- }
|
|
249
|
|
- }
|
|
250
|
|
- }
|
|
251
|
|
- }
|
|
252
|
|
-
|
|
253
|
|
- this.setState({
|
|
254
|
|
- event: eventToShow
|
|
255
|
|
- });
|
|
256
|
|
- }
|
|
257
|
|
-
|
|
258
|
|
- _onGoToNext: () => void;
|
|
259
|
|
-
|
|
260
|
|
- /**
|
|
261
|
|
- * Opens the meeting URL that the notification shows.
|
|
262
|
|
- *
|
|
263
|
|
- * @private
|
|
264
|
|
- * @returns {void}
|
|
265
|
|
- */
|
|
266
|
|
- _onGoToNext() {
|
|
267
|
|
- const { event } = this.state;
|
|
268
|
|
-
|
|
269
|
|
- if (event && event.url) {
|
|
270
|
|
- this.props.dispatch(appNavigate(event.url));
|
|
271
|
|
- }
|
|
272
|
|
- }
|
|
273
|
|
-}
|
|
274
|
|
-
|
|
275
|
|
-/**
|
|
276
|
|
- * Maps redux state to component props.
|
|
277
|
|
- *
|
|
278
|
|
- * @param {Object} state - The redux state.
|
|
279
|
|
- * @returns {{
|
|
280
|
|
- * _aspectRatio: Symbol,
|
|
281
|
|
- * _currentConferenceURL: string,
|
|
282
|
|
- * _eventList: Array
|
|
283
|
|
- * }}
|
|
284
|
|
- */
|
|
285
|
|
-function _mapStateToProps(state: Object) {
|
|
286
|
|
- const { locationURL } = state['features/base/connection'];
|
|
287
|
|
-
|
|
288
|
|
- return {
|
|
289
|
|
- _aspectRatio: state['features/base/responsive-ui'].aspectRatio,
|
|
290
|
|
- _currentConferenceURL:
|
|
291
|
|
- locationURL ? getURLWithoutParamsNormalized(locationURL) : '',
|
|
292
|
|
- _eventList: state['features/calendar-sync'].events
|
|
293
|
|
- };
|
|
294
|
|
-}
|
|
295
|
|
-
|
|
296
|
|
-export default translate(connect(_mapStateToProps)(ConferenceNotification));
|