2017-12-14 17:02:32 +00:00
|
|
|
// @flow
|
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../../app';
|
2018-02-02 19:35:49 +00:00
|
|
|
import { ReducerRegistry } from '../redux';
|
|
|
|
import { PersistenceRegistry } from '../storage';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-01-29 22:20:38 +00:00
|
|
|
import { PROFILE_UPDATED } from './actionTypes';
|
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
/**
|
|
|
|
* The default/initial redux state of the feature {@code base/profile}.
|
|
|
|
*
|
|
|
|
* @type Object
|
|
|
|
*/
|
|
|
|
const DEFAULT_STATE = {};
|
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
const STORE_NAME = 'features/base/profile';
|
|
|
|
|
2018-02-02 19:35:49 +00:00
|
|
|
/**
|
2018-02-27 20:21:28 +00:00
|
|
|
* Sets up the persistence of the feature {@code base/profile}.
|
2018-02-02 19:35:49 +00:00
|
|
|
*/
|
2018-02-06 12:18:05 +00:00
|
|
|
PersistenceRegistry.register(STORE_NAME);
|
2018-01-17 11:19:10 +00:00
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
// XXX APP_WILL_MOUNT is the earliest redux action of ours dispatched in
|
|
|
|
// the store. For the purposes of legacy support, make sure that the
|
|
|
|
// deserialized base/profile's state is in the format deemed current by
|
|
|
|
// the current app revision.
|
|
|
|
if (state && typeof state === 'object') {
|
|
|
|
// In an enterprise/internal build of Jitsi Meet for Android and iOS
|
|
|
|
// we had base/profile's state as an object with property profile.
|
|
|
|
const { profile } = state;
|
|
|
|
|
|
|
|
if (profile && typeof profile === 'object') {
|
|
|
|
return { ...profile };
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// In the weird case that we have previously persisted/serialized
|
|
|
|
// null.
|
|
|
|
return DEFAULT_STATE;
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
2018-02-27 20:21:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROFILE_UPDATED:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...action.profile
|
|
|
|
};
|
|
|
|
}
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
return state;
|
|
|
|
});
|