This adds a new table UserNotificationSchedules which stores monday-friday start and ends times that each user would like to receive notifications (with a Boolean enabled to remove the use of the schedule). There is then a background job that runs every day and creates do_not_disturb_timings for each user with an enabled notification schedule. The job schedules timings 2 days in advance. The job is designed so that it can be run at any point in time, and it will not create duplicate records. When a users saves their notification schedule, the schedule processing service will run and schedule do_not_disturb_timings. If the user should be in DND due to their schedule, the user will immediately be put in DND (message bus publishes this state). The UI for a user's notification schedule is in user -> preferences -> notifications. By default every day is 8am - 5pm when first enabled.
32 lines
763 B
JavaScript
32 lines
763 B
JavaScript
import Controller from "@ember/controller";
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
import { action } from "@ember/object";
|
|
import { extractError } from "discourse/lib/ajax-error";
|
|
|
|
export default Controller.extend(ModalFunctionality, {
|
|
duration: null,
|
|
|
|
@action
|
|
setDuration(duration) {
|
|
this.set("duration", duration);
|
|
this.save();
|
|
},
|
|
|
|
save() {
|
|
this.currentUser
|
|
.enterDoNotDisturbFor(this.duration)
|
|
.then(() => {
|
|
this.send("closeModal");
|
|
})
|
|
.catch((e) => {
|
|
this.flash(extractError(e), "error");
|
|
});
|
|
},
|
|
|
|
@action
|
|
navigateToNotificationSchedule() {
|
|
this.transitionToRoute("preferences.notifications", this.currentUser);
|
|
this.send("closeModal");
|
|
},
|
|
});
|