49 lines
1.8 KiB
TypeScript
49 lines
1.8 KiB
TypeScript
// Metro module 16312 (f16313).
|
|
import SavedMessagesStore from "../SavedMessagesStore";
|
|
import ForLaterExperiment from "../ForLaterExperiment";
|
|
import Dispatcher from "../../../Dispatcher";
|
|
import Durations from "../../../utils/Durations";
|
|
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
|
|
let c11730_3;
|
|
const scheduleNextNotification = function scheduleNextNotification() {
|
|
if (ForLaterExperiment.getConfig({
|
|
location: "MessageRemindersNotificationManager"
|
|
}).enabled) {
|
|
if (c11730_3 != null) {
|
|
clearTimeout(c11730_3);
|
|
}
|
|
const savedMessage = SavedMessagesStore.getMessageReminders().find((item) => item.saveData.dueAt != null && item.saveData.dueAt > new Date());
|
|
if ((savedMessage == null ? void 0 : savedMessage.saveData?.dueAt) != null) {
|
|
const r35 = Date.now() + Durations.Millis.WEEK;
|
|
if (!(savedMessage.saveData.dueAt.getTime() > r35)) {
|
|
c11730_3 = setTimeout(() => {
|
|
if (ForLaterExperiment.getConfig({
|
|
location: "MessageRemindersNotificationManager"
|
|
}).enabled) {
|
|
Dispatcher.dispatch({
|
|
type: "MESSAGE_REMINDER_DUE",
|
|
savedMessage
|
|
});
|
|
scheduleNextNotification();
|
|
}
|
|
}, savedMessage.saveData.dueAt.getTime() - Date.now());
|
|
}
|
|
} else {
|
|
c11730_3 = null;
|
|
}
|
|
}
|
|
};
|
|
c11730_3 = null;
|
|
class MessageRemindersNotificationManager extends AutomaticLifecycleManager {
|
|
actions = {
|
|
SAVED_MESSAGES_UPDATE: () => this.handleUpdates(),
|
|
SAVED_MESSAGE_CREATE: () => this.handleUpdates(),
|
|
SAVED_MESSAGE_DELETE: () => this.handleUpdates()
|
|
};
|
|
handleUpdates = () => {
|
|
scheduleNextNotification();
|
|
};
|
|
}
|
|
const messageRemindersNotificationManager = new MessageRemindersNotificationManager();
|
|
export default messageRemindersNotificationManager;
|