@intuitionrobotics/push-pub-sub
Version:
55 lines • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationsModule = exports.NotificationsModule_Class = exports.dispatch_NotificationsUpdated = void 0;
const thunder_dispatcher_1 = require("@intuitionrobotics/thunderstorm/app-frontend/core/thunder-dispatcher");
const ts_common_1 = require("@intuitionrobotics/ts-common");
const frontend_1 = require("@intuitionrobotics/thunderstorm/frontend");
const thunderstorm_1 = require("@intuitionrobotics/thunderstorm");
exports.dispatch_NotificationsUpdated = new thunder_dispatcher_1.ThunderDispatcher('__onNotificationsUpdated');
class NotificationsModule_Class extends ts_common_1.Module {
constructor() {
super("NotificationsModule");
this.notifications = [];
this.setNotificationList = (notifications) => {
this.notifications = notifications;
exports.dispatch_NotificationsUpdated.dispatchUI();
};
this.read = (notification, read) => {
const readNotification = this.notifications.find(_notification => _notification._id === notification._id);
if (!readNotification || !readNotification.persistent)
return;
readNotification.read = read;
this.readNotification(notification._id, read);
};
this.readNotification = (id, read) => {
const body = {
_id: id,
read
};
frontend_1.XhrHttpModule
.createRequest(thunderstorm_1.HttpMethod.POST, 'read-notification')
.setRelativeUrl("/v1/push/read")
.setJsonBody(body)
.setOnError('Something went wrong while reading your notification')
.setTimeout(ts_common_1.Minute)
.execute(() => {
exports.dispatch_NotificationsUpdated.dispatchUI();
});
};
}
getNotifications() {
return this.notifications;
}
addNotification(newNotification) {
this.notifications.push(newNotification);
exports.dispatch_NotificationsUpdated.dispatchUI();
}
removeNotification(notification) {
(0, ts_common_1.removeItemFromArray)(this.notifications, notification);
exports.dispatch_NotificationsUpdated.dispatchUI();
return notification._id;
}
}
exports.NotificationsModule_Class = NotificationsModule_Class;
exports.NotificationsModule = new NotificationsModule_Class();
//# sourceMappingURL=NotificationModule.js.map