this.__beeper = new qwebirc.ui.Beeper(this.uiOptions);
this.__flasher = new qwebirc.ui.Flasher(this.uiOptions);
-
- this.beep = this.__beeper.beep.bind(this.__beeper);
-
- this.flash = this.__flasher.flash.bind(this.__flasher);
+ this.__notifier = new qwebirc.ui.Notifier(this.uiOptions);
+
this.cancelFlash = this.__flasher.cancelFlash.bind(this.__flasher);
},
+ beep: function() {
+ this.__beeper.beep();
+ },
+ notify: function(title, message, callback) {
+ this.__beeper.beep();
+ this.__flasher.flash();
+ this.__notifier.notify(title, message, callback);
+ },
setBeepOnMention: function(value) {
if(value)
this.__beeper.soundInit();
},
+ setNotifications: function(value) {
+ this.__notifier.setEnabled(value);
+ },
updateTitle: function(text) {
if(this.__flasher.updateTitle(text))
this.parent(text);
focusChange: function(value) {
this.parent(value);
this.__flasher.focusChange(value);
+ this.__notifier.focusChange(value);
}
});
addLine: function(type, line, colour, element) {
var hilight = qwebirc.ui.HILIGHT_NONE;
var lhilight = false;
-
+
if(type) {
+ var selectMe = function() { this.parentObject.selectWindow(this); }.bind(this);
+ var message = $defined(line) ? line["m"] : null;
hilight = qwebirc.ui.HILIGHT_ACTIVITY;
if(type.match(/(NOTICE|ACTION|MSG)$/)) {
hilight = qwebirc.ui.HILIGHT_ACTIVITY;
} else {
hilight = qwebirc.ui.HILIGHT_US;
- this.parentObject.beep();
- this.parentObject.flash();
+ this.parentObject.notify("Private message from " + this.name, message, selectMe);
}
}
- if(!type.match(/^OUR/) && this.client.hilightController.match(line["m"])) {
+ if(!type.match(/^OUR/) && this.client.hilightController.match(message)) {
lhilight = true;
hilight = qwebirc.ui.HILIGHT_US;
- this.parentObject.beep();
- this.parentObject.flash();
+ this.parentObject.notify("Hilighted in " + this.name, message, selectMe);
} else if(hilight != qwebirc.ui.HILIGHT_US) {
hilight = qwebirc.ui.HILIGHT_SPEECH;
}
this.cancelFlash();
}
});
+
+qwebirc.ui.Notifier = new Class({
+ initialize: function(uiOptions) {
+ this.uiOptions = uiOptions;
+
+ this.windowFocused = false;
+ this.previous = null;
+ this.setEnabled(this.uiOptions.NOTIFICATIONS);
+ },
+ focusChange: function(value) {
+ this.windowFocused = value;
+ },
+ setEnabled: function(value) {
+ this.enabled = value;
+ if(!value)
+ return;
+
+ if(this.isGranted())
+ return;
+
+ Notification.requestPermission(function (permission) {
+ if (!("permission" in Notification))
+ Notification.permission = permission;
+ });
+ },
+ isGranted: function() {
+ if(!("Notification" in window))
+ return false;
+
+ return Notification.permission === "granted";
+ },
+ notify: function(title, message, callback) {
+ if(this.windowFocused && !this.enabled || !this.isGranted())
+ return;
+
+ if(this.previous)
+ this.previous.close();
+
+ var n = new Notification(title, {body: message, icon: qwebirc.global.staticBaseURL + "images/qwebircsmall.png"});
+ var delay = function() {
+ n.close();
+ this.previous = null;
+ }.bind(this).delay(5000);
+
+ this.previous = n;
+ if(callback) {
+ n.addEventListener("click", function() {
+ this.previous = null;
+ window.focus();
+ callback();
+ });
+ n.addEventListener("close", function() {
+ this.previous = null;
+ }.bind(this));
+ }
+ }
+});
* settableByURL...
*/
qwebirc.config.DEFAULT_OPTIONS = [
- [1, "BEEP_ON_MENTION", "Beep when nick mentioned or on query activity", true, {
+ [1, "BEEP_ON_MENTION", "Beep on activity", true, {
applyChanges: function(value, ui) {
if(ui.setBeepOnMention)
ui.setBeepOnMention(value);
}
}],
+ [16, "NOTIFICATIONS", "Emit HTML5 notifications on activity", false, {
+ enabled: function() {
+ if(!("Notification" in window))
+ return [false, false]; /* [disabled, default_value] */
+ return [true];
+ },
+ applyChanges: function(value, ui) {
+ if(ui.setNotifications)
+ ui.setNotifications(value);
+ }
+ }],
[7, "FLASH_ON_MENTION", "Flash titlebar when nick mentioned or on query activity", true, {
enabled: qwebirc.ui.supportsFocus
}],