From e88c1084caa02c21c5c60582f155ade76323a98d Mon Sep 17 00:00:00 2001 From: Tor Hveem Date: Sun, 6 Oct 2013 12:34:41 +0200 Subject: [PATCH] Add notification support --- img/favicon.png | Bin 0 -> 1782 bytes index.html | 1 + js/websockets.js | 82 +++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 img/favicon.png diff --git a/img/favicon.png b/img/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..7eca5c8d6e06516fc48ba7e43acd40bb14221df8 GIT binary patch literal 1782 zcmVNAZT=Sa5^t9cV%T`Xkm0NZ*pfZasXu^ z000I_NklU2Igx703TG_wIVvi$B0N{)B|a#Xv|vf*^<-wW0>0L{*zSgo=_@ zNrfyG5v7Qfx2Q=3m0GE4m4`~aM5$USZKX!75{b4XSeBbQw$letW+^qqdWJ`+;e{CKj+R2aKGFy|KlS5Q^&@w&B)HJmLFqBUO(Ir zZ>p;g0+sL!VN8YE4t*6P7uaJK~2X05gPPKr=%TK@+n!kwn^%@O8k``S$_%H31HNd*53vTQ}}fT36Vm z5U^~C;uo%$o?N;U6vIpyC|`xz)xLJaKo^y-U1P{2BA=LiW7w;@dt}JhL_Yb(r<=to z0K5+1(20FV9@yJ`wBlR}2#&4&jI`aKup^4(WXruea&6H zb<(nIX~iL=z;A!h{|tb4)&V?q?r@z6%?E$`)r9TleAmtUdC&24MaOfDGVa{i{QCgh z%NM@&$kB6eUa;ax09^Ur&#eUM>CsLAIP~4u9&c>lx>H)QWaXci7Ur)F&AOSpcgpY9 z0Q~ulNuvXGDb?2S)|TDxOH(325cQ$!ScwfApY;pb z5df*qod-`wb5pgV34!#~=s1AcCrB39m;fThi<4s?8x>9gkZoV;Kknr;Kn&)R zcVQzvHFOJ%aR6xV8yGYy1?A}~K*r+r@o@n2wE)DHN1r}j%mg4RBLmDp=sN!VCqq{N z6n7mvw;kO4h?iC1a`eQImc+I9esLAR4FG7^y#IS{CIm5+#zYECUwPxN01E2>dizfu zk+F_$cU4t6XD~~w%uUZa=}$ibz;%f&2SYEmS@}9ri2xP?#mtRdc7AdQK=9!H!Dm3N zjm1?}QVD>tu(~jDM|sZJn%|}bAX^^z+Bbbi+guenGed|NZVg`=0x%m5-*hr4NDvu- zxs-}>~LY9`Zs*mDecP4oiV zU((An!&d?10d!ljZ3B_YfN7`_4^ zSO*Zg;cilmeV$W_stSOq-rn3hxE~_6lHBm%^P!spldeR@1Ta~4N8gXnbnb|sVFpx@ z5VDCBC{1HwdEyp>M{4amwzPVVhHe66bS3l4^vuAfo>MO~)5}bNn++CV!CGin4l*qsR!AGM?A~q(H1RNGT$%z}jafpUHU4#VnazmMOc!lvyT| z{=%5g7TH|C8XZ@7JwV_DSG0fa1UU6W<_&$|Sez&f!TBOlKF{Q2nR3g_&Jt7M9y6@~ zW*Mw9#9oHYvP0&d4v=>N_@!kwEJaM!`@nxYl*R${0B9-iEdW*l6srvL{d4^N@_$$U Y1seB0;07)3N&o-=07*qoM6N<$f|o=#y#N3J literal 0 HcmV?d00001 diff --git a/index.html b/index.html index 2f906d4..32879e0 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ + diff --git a/js/websockets.js b/js/websockets.js index fa2475e..f57eaa9 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -205,6 +205,10 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'pluginManager', function($ var prefix = colors.parse(message['objects'][0]['content'][0]['prefix']); var text = colors.parse(message['objects'][0]['content'][0]['message']); var buffer = message['objects'][0]['content'][0]['buffer']; + var tags_array = message['objects'][0]['content'][0]['tags_array']; + var displayed = message['objects'][0]['content'][0]['displayed']; + var highlight = message['objects'][0]['content'][0]['highlight']; + console.log(highlight, tags_array); var message = _.union(prefix, text); message =_.map(message, function(message) { if ('fg' in message) { @@ -212,19 +216,28 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'pluginManager', function($ } return message; }); - buffer_line['message'] = message; + // Only react to line if its displayed + if (displayed) { + buffer_line['message'] = message; - if (!_isActiveBuffer(buffer)) { - $rootScope.buffers[buffer]['notification'] = true; + + if (!_isActiveBuffer(buffer)) { + $rootScope.buffers[buffer]['notification'] = true; + } + + var additionalContent = pluginManager.contentForMessage(text[0]['text']); + + if (additionalContent) { + buffer_line['metadata'] = additionalContent; + } + + $rootScope.buffers[buffer]['lines'].push(buffer_line); + + + if(highlight || _.contains(tags_array, 'notify_private')) { + $rootScope.createHighlight(prefix, text, message, buffer, additionalContent); + } } - - var additionalContent = pluginManager.contentForMessage(text[0]['text']); - - if (additionalContent) { - buffer_line['metadata'] = additionalContent; - } - - $rootScope.buffers[buffer]['lines'].push(buffer_line); } /* @@ -245,6 +258,7 @@ weechat.factory('handlers', ['$rootScope', 'colors', 'pluginManager', function($ } + /* * Handle answers to (bufinfo) messages * @@ -321,18 +335,20 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct websocket.binaryType = "arraybuffer" websocket.onopen = function (evt) { + var send = ""; // FIXME: does password need to be sent only if protocol is not weechat? if (proto == "weechat") { if (password) { - doSend("init compression=off,password=" + password + "\n"); + send += "init compression=off,password=" + password + "\n"; } - doSend("(bufinfo) hdata buffer:gui_buffers(*) full_name\n"); - doSend("sync\n"); + send += "(bufinfo) hdata buffer:gui_buffers(*) full_name\n"; + send += "sync\n"; } else { } $log.info("Connected to relay"); + doSend(send); $rootScope.connected = true; $rootScope.$apply(); } @@ -372,6 +388,21 @@ weechat.factory('connection', ['$rootScope', '$log', 'handlers', 'colors', funct }]); weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection', function ($rootScope, $scope, $store, connection) { + + // Request notification permission + Notification.requestPermission(function (status) { + console.log('Notification permission status:',status); + if (Notification.permission !== status) { + Notification.permission = status; + } + }); + if(window.webkitNotifications != undefined) { + if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED + console.log('Notification permission status:', window.webkitNotifications.checkPermission() == 0); + window.webkitNotifications.requestPermission(); + } + } + $rootScope.commands = [] $rootScope.buffer = [] @@ -402,5 +433,28 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', 'connection $scope.connect = function() { connection.connect($scope.hostport, $scope.proto, $scope.password); } + + + /* Function gets called from bufferLineAdded code if user should be notified */ + $rootScope.createHighlight = function(prefix, text, message, buffer, additionalContent) { + var prefixs = ""; + prefixs += prefix[0].text; + prefixs += prefix[1].text; + var messages = ""; + messages += text[0].text; + + var buffers = $rootScope.buffers[buffer]; + + var title = buffers.full_name; + var content = "<"+prefixs+">"+messages; + + var timeout = 15*1000; + console.log('Displaying notification:',title,',with timeout:',timeout); + var notification = new Notification(title, {body:content, icon:'img/favicon.png'}); + // Cancel notification automatically + notification.onshow = function() { + setTimeout(function() { notification.close() }, timeout); + } + }; }] );