2017-07-31 18:36:41 +00:00
|
|
|
import jitsiLocalStorage from '../../../modules/util/JitsiLocalStorage';
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
import {
|
|
|
|
HIDE_NOTIFICATION,
|
2017-08-02 18:15:55 +00:00
|
|
|
SET_NOTIFICATIONS_ENABLED,
|
2017-07-28 17:56:49 +00:00
|
|
|
SHOW_NOTIFICATION
|
|
|
|
} from './actionTypes';
|
2017-11-03 19:05:03 +00:00
|
|
|
import {
|
|
|
|
Notification,
|
|
|
|
NotificationWithToggle
|
|
|
|
} from './components';
|
|
|
|
|
|
|
|
import { NOTIFICATION_TYPE } from './constants';
|
2017-07-28 17:56:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the notification with the passed in id.
|
|
|
|
*
|
|
|
|
* @param {string} uid - The unique identifier for the notification to be
|
|
|
|
* removed.
|
|
|
|
* @returns {{
|
|
|
|
* type: HIDE_NOTIFICATION,
|
2017-07-31 18:36:41 +00:00
|
|
|
* uid: number
|
2017-07-28 17:56:49 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function hideNotification(uid) {
|
|
|
|
return {
|
|
|
|
type: HIDE_NOTIFICATION,
|
|
|
|
uid
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-02 18:15:55 +00:00
|
|
|
/**
|
|
|
|
* Stops notifications from being displayed.
|
|
|
|
*
|
|
|
|
* @param {boolean} enabled - Whether or not notifications should display.
|
|
|
|
* @returns {{
|
|
|
|
* type: SET_NOTIFICATIONS_ENABLED,
|
|
|
|
* enabled: boolean
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function setNotificationsEnabled(enabled) {
|
|
|
|
return {
|
|
|
|
type: SET_NOTIFICATIONS_ENABLED,
|
|
|
|
enabled
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
/**
|
|
|
|
* Queues an error notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function showErrorNotification(props) {
|
|
|
|
return showNotification(Notification, {
|
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.ERROR
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Queues a notification for display.
|
|
|
|
*
|
|
|
|
* @param {ReactComponent} component - The notification component to be
|
|
|
|
* displayed.
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @param {number} timeout - How long the notification should display before
|
|
|
|
* automatically being hidden.
|
|
|
|
* @returns {{
|
|
|
|
* type: SHOW_NOTIFICATION,
|
|
|
|
* component: ReactComponent,
|
|
|
|
* props: Object,
|
|
|
|
* timeout: number,
|
|
|
|
* uid: number
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function showNotification(component, props = {}, timeout) {
|
|
|
|
return {
|
|
|
|
type: SHOW_NOTIFICATION,
|
|
|
|
component,
|
|
|
|
props,
|
|
|
|
timeout,
|
|
|
|
uid: window.Date.now()
|
|
|
|
};
|
|
|
|
}
|
2017-07-31 18:36:41 +00:00
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
/**
|
|
|
|
* Queues a warning notification for display.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
export function showWarningNotification(props) {
|
|
|
|
return showNotification(Notification, {
|
|
|
|
...props,
|
|
|
|
appearance: NOTIFICATION_TYPE.WARNING
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-07-31 18:36:41 +00:00
|
|
|
/**
|
|
|
|
* Displays a notification unless the passed in persistenceKey value exists in
|
|
|
|
* local storage and has been set to "true".
|
|
|
|
*
|
|
|
|
* @param {string} persistenceKey - The local storage key to look up for whether
|
|
|
|
* or not the notification should display.
|
|
|
|
* @param {Object} props - The props needed to show the notification component.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function maybeShowNotificationWithDoNotDisplay(persistenceKey, props) {
|
|
|
|
return dispatch => {
|
|
|
|
if (jitsiLocalStorage.getItem(persistenceKey) === 'true') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const newProps = Object.assign({}, props, {
|
|
|
|
onToggleSubmit: isToggled => {
|
|
|
|
jitsiLocalStorage.setItem(persistenceKey, isToggled);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SHOW_NOTIFICATION,
|
|
|
|
component: NotificationWithToggle,
|
|
|
|
props: newProps,
|
|
|
|
uid: window.Date.now()
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|