"use strict";
var EXPORTED_SYMBOLS = ["module"];
var module = function (application) {
var log = function (message) {
application.logger.trace("[Notifications Queue] " + message);
}
;
function NotificationsQueue() {
this._notificationsList = [];
this.init();
}

NotificationsQueue.prototype = {
constructor: NotificationsQueue,
init: function NotificationsQueue_init() {

}
,
finalize: function NotificationsQueue_finalize() {
this._notificationsList = [];
}
,
add: function NotificationsQueue_add(notification) {
log("Add new notification to queue.\n" + JSON.stringify(notification));
this._notificationsList.push(notification);
this._mailman.send("notification-added");
}
,
getNext: function NotificationsQueue_getNext() {
if (this.isEmpty)
return null;
var notification = this._notificationsList.splice(0,1)[0];
return notification;
}
,
removeAllNotificationsFrom: function NotificationsQueue_removeAllNotificationsFrom(owner) {
log("Remove all notifications from \"" + owner + "\".");
if (this.isEmpty)
return;
var currentNotificationNumber = this._notificationsList.length;
this._notificationsList = this._notificationsList.filter(function (notification) {
var currentOwner = notification.owner;
return "undefined" != typeof currentOwner && owner !== currentOwner;
}
);
log(currentNotificationNumber - this._notificationsList.length + " notification(s) removed.");
}
,
get isEmpty() {
return 0 === this._notificationsList.length;
}
,
__mailman: null,
get _mailman() {
return this.__mailman ? this.__mailman : (this.__mailman = application.loadModule("Mailman"));
}
};
return NotificationsQueue;
}
;
