|
|
|
@ -802,7 +802,7 @@
|
|
|
|
|
appView.openConversation(groupId, {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.toasts = {};
|
|
|
|
|
window.toasts = new Map();
|
|
|
|
|
window.pushToast = options => {
|
|
|
|
|
// Setting toasts with the same ID can be used to prevent identical
|
|
|
|
|
// toasts from appearing at once (stacking).
|
|
|
|
@ -810,45 +810,38 @@
|
|
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
title: options.title,
|
|
|
|
|
description: options.description ? options.description : '',
|
|
|
|
|
type: options.type ? options.type : '',
|
|
|
|
|
id: options.id ? options.id : '',
|
|
|
|
|
id:
|
|
|
|
|
options.id ||
|
|
|
|
|
Math.random()
|
|
|
|
|
.toString(36)
|
|
|
|
|
.substring(3),
|
|
|
|
|
description: options.description || '',
|
|
|
|
|
type: options.type || '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Give all toasts an ID. User may define.
|
|
|
|
|
const toastID = options.id
|
|
|
|
|
? options.id
|
|
|
|
|
: Math.random()
|
|
|
|
|
.toString(36)
|
|
|
|
|
.substring(3);
|
|
|
|
|
|
|
|
|
|
let toastExists = false;
|
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
|
|
|
for (const key in window.toasts) {
|
|
|
|
|
if (!!options.id && key === options.id) {
|
|
|
|
|
toastExists = true;
|
|
|
|
|
window.toasts[key].update(params);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!toastExists) {
|
|
|
|
|
const toastID = params.id;
|
|
|
|
|
const toast = !!toastID && window.toasts.get(toastID);
|
|
|
|
|
if (toast) {
|
|
|
|
|
window.toasts.get(toastID).update(params);
|
|
|
|
|
} else {
|
|
|
|
|
// Make new Toast
|
|
|
|
|
window.toasts[toastID] = new Whisper.SessionToastView({
|
|
|
|
|
el: window.$('#session-toast-container'),
|
|
|
|
|
});
|
|
|
|
|
window.toasts.set(
|
|
|
|
|
toastID,
|
|
|
|
|
new Whisper.SessionToastView({
|
|
|
|
|
el: $('#session-toast-container'),
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
window.toasts[toastID].render();
|
|
|
|
|
window.toasts[toastID].update(params);
|
|
|
|
|
window.toasts.get(toastID).render();
|
|
|
|
|
window.toasts.get(toastID).update(params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove some toasts if too many exist
|
|
|
|
|
const maxToasts = 6;
|
|
|
|
|
const numToasts = window.toasts.length;
|
|
|
|
|
|
|
|
|
|
if (numToasts > maxToasts) {
|
|
|
|
|
const finalToastID = window.toasts.keys[window.toasts.length];
|
|
|
|
|
window.toasts[finalToastID].fadeToast();
|
|
|
|
|
while (window.toasts.size > maxToasts) {
|
|
|
|
|
const finalToastID = window.toasts.keys().next().value;
|
|
|
|
|
window.toasts.get(finalToastID).fadeToast();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return toastID;
|
|
|
|
|