2022-10-13 08:26:28 +00:00
|
|
|
import { SET_CONFIG } from '../base/config/actionTypes';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2022-05-23 15:02:14 +00:00
|
|
|
|
|
|
|
import { SET_DYNAMIC_BRANDING_DATA } from './actionTypes';
|
|
|
|
import { fetchCustomBrandingData } from './actions.native';
|
|
|
|
|
|
|
|
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
|
|
|
case SET_CONFIG: {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
store.dispatch(fetchCustomBrandingData());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SET_DYNAMIC_BRANDING_DATA: {
|
|
|
|
const {
|
2022-06-14 12:52:18 +00:00
|
|
|
avatarBackgrounds = [],
|
2022-05-23 15:02:14 +00:00
|
|
|
backgroundColor,
|
2022-06-14 12:52:18 +00:00
|
|
|
backgroundImageUrl,
|
|
|
|
didPageUrl,
|
|
|
|
inviteDomain
|
2022-05-23 15:02:14 +00:00
|
|
|
} = action.value;
|
|
|
|
|
|
|
|
action.value = {
|
|
|
|
avatarBackgrounds,
|
|
|
|
backgroundColor,
|
2022-06-14 12:52:18 +00:00
|
|
|
backgroundImageUrl,
|
|
|
|
didPageUrl,
|
|
|
|
inviteDomain
|
2022-05-23 15:02:14 +00:00
|
|
|
};
|
2022-06-14 12:53:14 +00:00
|
|
|
|
2022-12-15 10:04:27 +00:00
|
|
|
// The backend may send an empty string, make sure we skip that.
|
|
|
|
if (Array.isArray(avatarBackgrounds)) {
|
|
|
|
// TODO: implement support for gradients.
|
|
|
|
action.value.avatarBackgrounds = avatarBackgrounds.filter(
|
|
|
|
(color: string) => !color.includes('linear-gradient')
|
|
|
|
);
|
|
|
|
}
|
2022-06-14 12:53:14 +00:00
|
|
|
|
2022-05-23 15:02:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|