Rework notifications
* Improve content of notifications
* More descriptive title
* The bug that caused the need for manually assembling the message has been fixed (#161 or c5e548c8ab
)
* Permission for displaying notifications can only be requested upon user interaction in Chrome, not on page load. Bind to connect button
* Take user to g-b tab and buffer causing the notification on click
This commit is contained in:
parent
0deb14fc84
commit
157917d40c
1 changed files with 30 additions and 16 deletions
|
@ -507,12 +507,16 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
console.log(watchers.length);
|
console.log(watchers.length);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.requestWebkitNotificationPermission = function() {
|
||||||
if (window.webkitNotifications !== undefined) {
|
if (window.webkitNotifications !== undefined) {
|
||||||
if (window.webkitNotifications.checkPermission() === 0) { // 0 is PERMISSION_ALLOWED
|
var havePermission = window.webkitNotifications.checkPermission();
|
||||||
$log.info('Notification permission status:', window.webkitNotifications.checkPermission() === 0);
|
if (havePermission !== 0) { // 0 is PERMISSION_ALLOWED
|
||||||
|
$log.info('Notification permission status:', havePermission === 0);
|
||||||
window.webkitNotifications.requestPermission();
|
window.webkitNotifications.requestPermission();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Check for firefox & app installed
|
// Check for firefox & app installed
|
||||||
if (navigator.mozApps !== undefined) {
|
if (navigator.mozApps !== undefined) {
|
||||||
navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) {
|
navigator.mozApps.getSelf().onsuccess = function _onAppReady(evt) {
|
||||||
|
@ -721,6 +725,7 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
|
|
||||||
|
|
||||||
$scope.connect = function() {
|
$scope.connect = function() {
|
||||||
|
$scope.requestWebkitNotificationPermission();
|
||||||
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
|
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
|
||||||
};
|
};
|
||||||
$scope.disconnect = function() {
|
$scope.disconnect = function() {
|
||||||
|
@ -749,25 +754,34 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout',
|
||||||
|
|
||||||
/* Function gets called from bufferLineAdded code if user should be notified */
|
/* Function gets called from bufferLineAdded code if user should be notified */
|
||||||
$rootScope.createHighlight = function(buffer, message) {
|
$rootScope.createHighlight = function(buffer, message) {
|
||||||
var messages = "";
|
var title = '';
|
||||||
message.content.forEach(function(part) {
|
if (buffer.shortName.charAt(0) === '#') {
|
||||||
if (part.text !== undefined) {
|
title = 'Highlight in ';
|
||||||
messages += part.text + " ";
|
} else {
|
||||||
|
title = 'Private message from ';
|
||||||
}
|
}
|
||||||
|
title += buffer.shortName;
|
||||||
|
title += buffer.fullName.replace(/irc.([^\.]+)\..+/, " ($1)");
|
||||||
|
|
||||||
|
var notification = new Notification(title, {
|
||||||
|
body: message.text,
|
||||||
|
icon: 'img/favicon.png'
|
||||||
});
|
});
|
||||||
|
|
||||||
var title = buffer.fullName;
|
|
||||||
var content = messages;
|
|
||||||
|
|
||||||
var timeout = 15*1000;
|
|
||||||
$log.info('Displaying notification:buffer:',buffer,',message:',message,',with timeout:',timeout);
|
|
||||||
var notification = new Notification(title, {body:content, icon:'img/favicon.png'});
|
|
||||||
// Cancel notification automatically
|
// Cancel notification automatically
|
||||||
|
var timeout = 15*1000;
|
||||||
notification.onshow = function() {
|
notification.onshow = function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
notification.close();
|
notification.close();
|
||||||
}, timeout);
|
}, timeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Click takes the user to the buffer
|
||||||
|
notification.onclick = function() {
|
||||||
|
models.setActiveBuffer(buffer.id);
|
||||||
|
window.focus();
|
||||||
|
notification.close();
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.hasUnread = function(buffer) {
|
$scope.hasUnread = function(buffer) {
|
||||||
|
|
Loading…
Reference in a new issue