Coding style: naming, comments
This commit is contained in:
parent
46bc63b79e
commit
5e8ecc5fee
|
@ -6,7 +6,6 @@ import { Linking } from 'react-native';
|
|||
|
||||
import '../../analytics';
|
||||
import '../../authentication';
|
||||
import '../../base/domains';
|
||||
import { Platform } from '../../base/react';
|
||||
import {
|
||||
AspectRatioDetector,
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
// @flow
|
||||
|
||||
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
||||
|
||||
/**
|
||||
* Sends an action to add one or an array of known domains if not present yet.
|
||||
*
|
||||
* @param {string | Array<string>} knownDomains - The new domain as a string or
|
||||
* an array of domains.
|
||||
* @returns {{
|
||||
* type: ADD_KNOWN_DOMAINS,
|
||||
* knownDomains: Array<string>
|
||||
* }}
|
||||
*/
|
||||
export function addKnownDomains(knownDomains: string | Array<string>) {
|
||||
return {
|
||||
type: ADD_KNOWN_DOMAINS,
|
||||
knownDomains: typeof knownDomains === 'string'
|
||||
? [ knownDomains ] : knownDomains
|
||||
};
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// @flow
|
||||
|
||||
/**
|
||||
* A list of domains we consider jitsi-enabled domains by default. This is in
|
||||
* line with the app links on iOS and Android, but stands here as retreiving
|
||||
* those programatically is not straightforward.
|
||||
*/
|
||||
export const JITSI_KNOWN_DOMAINS = [
|
||||
'beta.meet.jit.si',
|
||||
'beta.hipchat.me',
|
||||
'chaos.hipchat.me',
|
||||
'enso.me',
|
||||
'hipchat.me',
|
||||
'meet.jit.si'
|
||||
];
|
|
@ -1,49 +0,0 @@
|
|||
// @flow
|
||||
|
||||
import { ReducerRegistry } from '../redux';
|
||||
import { PersistenceRegistry } from '../storage';
|
||||
|
||||
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
||||
|
||||
const DEFAULT_STATE = [];
|
||||
|
||||
const STORE_NAME = 'features/base/domains';
|
||||
|
||||
PersistenceRegistry.register(STORE_NAME);
|
||||
|
||||
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ADD_KNOWN_DOMAINS:
|
||||
return _addKnownDomain(state, action);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Adds an array of new domains to the known domain list if not present yet.
|
||||
*
|
||||
* @param {Object} state - The redux state.
|
||||
* @param {Object} action - The redux action.
|
||||
* @private
|
||||
* @returns {Object}
|
||||
*/
|
||||
function _addKnownDomain(state, action) {
|
||||
const { knownDomains: knownDomainsToAdd } = action;
|
||||
const knownDomains = Array.from(state);
|
||||
|
||||
if (Array.isArray(knownDomainsToAdd)) {
|
||||
for (let knownDomain of knownDomainsToAdd) {
|
||||
knownDomain = knownDomain.toLowerCase();
|
||||
|
||||
if (knownDomains.indexOf(knownDomain) === -1) {
|
||||
knownDomains.push(knownDomain);
|
||||
}
|
||||
}
|
||||
|
||||
return knownDomains;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
// @flow
|
||||
|
||||
/**
|
||||
* Action to add new domains to the list of domains known to the feature
|
||||
* base/domains.
|
||||
* The type of (redux) action to add known domains to the list of domains known
|
||||
* to the feature base/known-domains.
|
||||
*
|
||||
* {
|
||||
* type: ADD_KNOWN_DOMAINS,
|
|
@ -0,0 +1,22 @@
|
|||
// @flow
|
||||
|
||||
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
||||
|
||||
/**
|
||||
* Creates a (redux) action to add known domains to the list of domains known to
|
||||
* the feature base/known-domains.
|
||||
*
|
||||
* @param {string | Array<string>} knownDomains - The known domain(s) to add to
|
||||
* the list of domains known to the feature base/known-domains.
|
||||
* @returns {{
|
||||
* type: ADD_KNOWN_DOMAINS,
|
||||
* knownDomains: Array<string>
|
||||
* }}
|
||||
*/
|
||||
export function addKnownDomains(knownDomains: string | Array<string>) {
|
||||
return {
|
||||
type: ADD_KNOWN_DOMAINS,
|
||||
knownDomains:
|
||||
typeof knownDomains === 'string' ? [ knownDomains ] : knownDomains
|
||||
};
|
||||
}
|
|
@ -6,19 +6,17 @@ import { MiddlewareRegistry } from '../redux';
|
|||
import { parseURIString } from '../util';
|
||||
|
||||
import { addKnownDomains } from './actions';
|
||||
import { JITSI_KNOWN_DOMAINS } from './constants';
|
||||
|
||||
MiddlewareRegistry.register(store => next => action => {
|
||||
const result = next(action);
|
||||
|
||||
switch (action.type) {
|
||||
|
||||
case APP_WILL_MOUNT:
|
||||
_ensureDefaultServer(store);
|
||||
_appWillMount(store);
|
||||
break;
|
||||
|
||||
case SET_ROOM:
|
||||
_parseAndAddKnownDomain(store);
|
||||
_setRoom(store);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -26,34 +24,33 @@ MiddlewareRegistry.register(store => next => action => {
|
|||
});
|
||||
|
||||
/**
|
||||
* Ensures presence of the default server in the known domains list.
|
||||
* Adds the domain of the app's {@code defaultURL} to the list of domains known
|
||||
* to the feature base/known-domains.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function _ensureDefaultServer({ dispatch, getState }) {
|
||||
const { app } = getState()['features/app'];
|
||||
const defaultURL = parseURIString(app._getDefaultURL());
|
||||
function _appWillMount({ dispatch, getState }) {
|
||||
const defaultURL
|
||||
= parseURIString(getState()['features/app'].app._getDefaultURL());
|
||||
|
||||
dispatch(addKnownDomains([
|
||||
defaultURL.host,
|
||||
...JITSI_KNOWN_DOMAINS
|
||||
]));
|
||||
dispatch(addKnownDomains(defaultURL.host));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the domain name of a room upon join and stores it in the known
|
||||
* domain list, if not present yet.
|
||||
* Adds the domain of {@code locationURL} to the list of domains known to the
|
||||
* feature base/known-domains.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @private
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function _parseAndAddKnownDomain({ dispatch, getState }) {
|
||||
function _setRoom({ dispatch, getState }) {
|
||||
const { locationURL } = getState()['features/base/connection'];
|
||||
let host;
|
||||
|
||||
locationURL
|
||||
&& locationURL.host
|
||||
&& dispatch(addKnownDomains(locationURL.host));
|
||||
&& (host = locationURL.host)
|
||||
&& dispatch(addKnownDomains(host));
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
// @flow
|
||||
|
||||
import { APP_WILL_MOUNT } from '../../app';
|
||||
import { ReducerRegistry } from '../redux';
|
||||
import { PersistenceRegistry } from '../storage';
|
||||
|
||||
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
||||
|
||||
/**
|
||||
* The default list of domains known to the feature base/known-domains.
|
||||
* Generally, it should be in sync with the domains associated with the app
|
||||
* through its manifest (in other words, Universal Links, deep linking). Anyway,
|
||||
* we need a hardcoded list because it has proven impossible to programmatically
|
||||
* read the information out of the app's manifests: App Store strips the
|
||||
* associated domains manifest out of the app so it's never downloaded on the
|
||||
* client and we did not spend a lot of effort to read the associated domains
|
||||
* out of the Andorid manifest.
|
||||
*/
|
||||
export const DEFAULT_STATE = [
|
||||
'beta.hipchat.me',
|
||||
'beta.meet.jit.si',
|
||||
'chaos.hipchat.me',
|
||||
'enso.me',
|
||||
'hipchat.me',
|
||||
'meet.jit.si'
|
||||
];
|
||||
|
||||
const STORE_NAME = 'features/base/known-domains';
|
||||
|
||||
PersistenceRegistry.register(STORE_NAME);
|
||||
|
||||
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
case ADD_KNOWN_DOMAINS:
|
||||
return _addKnownDomains(state, action.knownDomains);
|
||||
|
||||
case APP_WILL_MOUNT:
|
||||
// In case persistence has deserialized a weird redux state:
|
||||
return _addKnownDomains(state, DEFAULT_STATE);
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Adds an array of known domains to the list of domains known to the feature
|
||||
* base/known-domains.
|
||||
*
|
||||
* @param {Object} state - The redux state.
|
||||
* @param {Array<string>} knownDomains - The array of known domains to add to
|
||||
* the list of domains known to the feature base/known-domains.
|
||||
* @private
|
||||
* @returns {Object} The next redux state.
|
||||
*/
|
||||
function _addKnownDomains(state, knownDomains) {
|
||||
// In case persistence has deserialized a weird redux state:
|
||||
let nextState = Array.isArray(state) ? state : [];
|
||||
|
||||
if (Array.isArray(knownDomains)) {
|
||||
nextState = Array.from(state);
|
||||
for (let knownDomain of knownDomains) {
|
||||
knownDomain = knownDomain.toLowerCase();
|
||||
nextState.indexOf(knownDomain) === -1
|
||||
&& nextState.push(knownDomain);
|
||||
}
|
||||
}
|
||||
|
||||
return nextState;
|
||||
}
|
|
@ -3,27 +3,24 @@
|
|||
import RNCalendarEvents from 'react-native-calendar-events';
|
||||
|
||||
import { APP_WILL_MOUNT } from '../app';
|
||||
import { ADD_KNOWN_DOMAINS } from '../base/domains';
|
||||
import { ADD_KNOWN_DOMAINS } from '../base/known-domains';
|
||||
import { MiddlewareRegistry } from '../base/redux';
|
||||
import { APP_LINK_SCHEME, parseURIString } from '../base/util';
|
||||
import { APP_STATE_CHANGED } from '../mobile/background';
|
||||
|
||||
import {
|
||||
setCalendarAuthorization,
|
||||
setCalendarEvents
|
||||
} from './actions';
|
||||
import { setCalendarAuthorization, setCalendarEvents } from './actions';
|
||||
import { REFRESH_CALENDAR } from './actionTypes';
|
||||
import { CALENDAR_ENABLED } from './constants';
|
||||
|
||||
const logger = require('jitsi-meet-logger').getLogger(__filename);
|
||||
|
||||
/**
|
||||
* The no. of days to fetch.
|
||||
* The number of days to fetch.
|
||||
*/
|
||||
const FETCH_END_DAYS = 10;
|
||||
|
||||
/**
|
||||
* The no. of days to go back when fetching.
|
||||
* The number of days to go back when fetching.
|
||||
*/
|
||||
const FETCH_START_DAYS = -1;
|
||||
|
||||
|
@ -37,15 +34,15 @@ CALENDAR_ENABLED
|
|||
const result = next(action);
|
||||
|
||||
switch (action.type) {
|
||||
case APP_STATE_CHANGED:
|
||||
_maybeClearAccessStatus(store, action);
|
||||
break;
|
||||
|
||||
case ADD_KNOWN_DOMAINS:
|
||||
case APP_WILL_MOUNT:
|
||||
_fetchCalendarEntries(store, false, false);
|
||||
break;
|
||||
|
||||
case APP_STATE_CHANGED:
|
||||
_maybeClearAccessStatus(store, action);
|
||||
break;
|
||||
|
||||
case REFRESH_CALENDAR:
|
||||
_fetchCalendarEntries(store, true, action.forcePermission);
|
||||
break;
|
||||
|
@ -54,23 +51,6 @@ CALENDAR_ENABLED
|
|||
return result;
|
||||
});
|
||||
|
||||
/**
|
||||
* Clears the calendar access status when the app comes back from the
|
||||
* background. This is needed as some users may never quit the app, but puts it
|
||||
* into the background and we need to try to request for a permission as often
|
||||
* as possible, but not annoyingly often.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @param {Object} action - The Redux action.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _maybeClearAccessStatus(store, { appState }) {
|
||||
if (appState === 'background') {
|
||||
store.dispatch(setCalendarAuthorization(undefined));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures calendar access if possible and resolves the promise if it's granted.
|
||||
*
|
||||
|
@ -113,13 +93,13 @@ function _ensureCalendarAccess(promptForPermission, dispatch) {
|
|||
* @returns {void}
|
||||
*/
|
||||
function _fetchCalendarEntries(
|
||||
{ dispatch, getState },
|
||||
store,
|
||||
maybePromptForPermission,
|
||||
forcePermission) {
|
||||
const featureState = getState()['features/calendar-sync'];
|
||||
const knownDomains = getState()['features/base/domains'];
|
||||
const { dispatch, getState } = store;
|
||||
const promptForPermission
|
||||
= (maybePromptForPermission && !featureState.authorization)
|
||||
= (maybePromptForPermission
|
||||
&& !getState()['features/calendar-sync'].authorization)
|
||||
|| forcePermission;
|
||||
|
||||
_ensureCalendarAccess(promptForPermission, dispatch)
|
||||
|
@ -135,11 +115,7 @@ function _fetchCalendarEntries(
|
|||
startDate.getTime(),
|
||||
endDate.getTime(),
|
||||
[])
|
||||
.then(events =>
|
||||
_updateCalendarEntries(
|
||||
events,
|
||||
knownDomains,
|
||||
dispatch))
|
||||
.then(_updateCalendarEntries.bind(store))
|
||||
.catch(error =>
|
||||
logger.error('Error fetching calendar.', error));
|
||||
} else {
|
||||
|
@ -192,6 +168,22 @@ function _getURLFromEvent(event, knownDomains) {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the calendar access status when the app comes back from the
|
||||
* background. This is needed as some users may never quit the app, but puts it
|
||||
* into the background and we need to try to request for a permission as often
|
||||
* as possible, but not annoyingly often.
|
||||
*
|
||||
* @param {Object} store - The redux store.
|
||||
* @param {Object} action - The Redux action.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _maybeClearAccessStatus(store, { appState }) {
|
||||
appState === 'background'
|
||||
&& store.dispatch(setCalendarAuthorization(undefined));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the calendar entries in Redux when new list is received.
|
||||
*
|
||||
|
@ -231,26 +223,30 @@ function _parseCalendarEntry(event, knownDomains) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Updates the calendar entries in Redux when new list is received.
|
||||
* Updates the calendar entries in redux when new list is received.
|
||||
*
|
||||
* XXX The function's {@code this} is the redux store.
|
||||
*
|
||||
* @param {Array<CalendarEntry>} events - The new event list.
|
||||
* @param {Array<string>} knownDomains - The known domain list.
|
||||
* @param {Function} dispatch - The Redux dispatch function.
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
function _updateCalendarEntries(events, knownDomains, dispatch) {
|
||||
function _updateCalendarEntries(events) {
|
||||
if (events && events.length) {
|
||||
// eslint-disable-next-line no-invalid-this
|
||||
const { dispatch, getState } = this;
|
||||
|
||||
const knownDomains = getState()['features/base/known-domains'];
|
||||
const eventList = [];
|
||||
|
||||
for (const event of events) {
|
||||
const calendarEntry
|
||||
= _parseCalendarEntry(event, knownDomains);
|
||||
const now = Date.now();
|
||||
const now = Date.now();
|
||||
|
||||
if (calendarEntry && calendarEntry.endDate > now) {
|
||||
eventList.push(calendarEntry);
|
||||
}
|
||||
for (const event of events) {
|
||||
const calendarEntry = _parseCalendarEntry(event, knownDomains);
|
||||
|
||||
calendarEntry
|
||||
&& calendarEntry.endDate > now
|
||||
&& eventList.push(calendarEntry);
|
||||
}
|
||||
|
||||
dispatch(
|
||||
|
|
Loading…
Reference in New Issue