2013-10-11 19:07:04 +02:00
|
|
|
var weechat = angular.module('weechat', ['localStorage', 'weechatModels', 'plugins', 'ngSanitize']);
|
2013-02-18 00:49:42 +01:00
|
|
|
|
2013-10-06 13:42:45 +02:00
|
|
|
weechat.filter('toArray', function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
return function (obj) {
|
|
|
|
if (!(obj instanceof Object)) {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(obj).map(function (key) {
|
|
|
|
return Object.defineProperty(obj[key], '$key', {__proto__: null, value: key});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2013-02-18 00:49:42 +01:00
|
|
|
|
2013-07-27 16:43:41 +02:00
|
|
|
weechat.factory('colors', [function($scope) {
|
|
|
|
|
|
|
|
return {
|
2013-10-16 23:10:49 +02:00
|
|
|
prepareCss: weeChat.color.prepareCss,
|
|
|
|
parse: weeChat.color.parse
|
|
|
|
};
|
2013-07-27 16:43:41 +02:00
|
|
|
|
|
|
|
}]);
|
|
|
|
|
2013-10-08 23:55:30 +02:00
|
|
|
weechat.factory('handlers', ['$rootScope', 'colors', 'models', 'plugins', function($rootScope, colors, models, plugins) {
|
2013-08-05 03:39:23 +02:00
|
|
|
|
2013-10-02 02:32:18 +02:00
|
|
|
var handleBufferClosing = function(message) {
|
2013-10-08 03:15:25 +02:00
|
|
|
var bufferMessage = message['objects'][0]['content'][0];
|
|
|
|
var buffer = new models.Buffer(bufferMessage);
|
2013-10-08 16:13:48 +02:00
|
|
|
models.closeBuffer(buffer);
|
2013-10-02 02:32:18 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 23:59:34 +02:00
|
|
|
var handleLine = function(line, initial) {
|
2013-10-09 17:53:25 +02:00
|
|
|
var message = new models.BufferLine(line);
|
2013-10-06 12:34:41 +02:00
|
|
|
// Only react to line if its displayed
|
2013-10-09 17:53:25 +02:00
|
|
|
if(message.displayed) {
|
|
|
|
var buffer = models.getBuffer(message.buffer);
|
2013-10-15 18:58:00 +02:00
|
|
|
message = plugins.PluginManager.contentForMessage(message);
|
2013-10-09 17:53:25 +02:00
|
|
|
buffer.addLine(message);
|
2013-10-06 02:06:28 +02:00
|
|
|
|
2013-10-09 17:53:25 +02:00
|
|
|
if (buffer.active) {
|
|
|
|
$rootScope.scrollToBottom();
|
2013-10-06 12:34:41 +02:00
|
|
|
}
|
2013-10-08 15:55:07 +02:00
|
|
|
|
2013-10-09 17:53:25 +02:00
|
|
|
if (!initial) {
|
2013-10-16 00:32:56 +02:00
|
|
|
if (!buffer.active && !buffer.notify==0 && _.contains(message.tags, 'notify_message') && !_.contains(message.tags, 'notify_none')) {
|
2013-10-15 14:59:06 +02:00
|
|
|
buffer.unread++;
|
2013-10-15 15:21:13 +02:00
|
|
|
$rootScope.$emit('notificationChanged');
|
2013-10-09 17:53:25 +02:00
|
|
|
}
|
2013-08-06 22:39:10 +02:00
|
|
|
|
2013-10-16 00:32:56 +02:00
|
|
|
if(!buffer.notify==0 && message.highlight || _.contains(message.tags, 'notify_private') ) {
|
2013-10-15 14:59:06 +02:00
|
|
|
buffer.notification++;
|
2013-10-09 17:53:25 +02:00
|
|
|
$rootScope.createHighlight(buffer, message);
|
2013-10-15 15:21:13 +02:00
|
|
|
$rootScope.$emit('notificationChanged');
|
2013-10-09 17:53:25 +02:00
|
|
|
}
|
2013-10-06 12:34:41 +02:00
|
|
|
}
|
2013-10-08 16:03:44 +02:00
|
|
|
}
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 20:20:34 +02:00
|
|
|
var handleBufferLineAdded = function(message) {
|
|
|
|
message['objects'][0]['content'].forEach(function(l) {
|
2013-10-06 23:59:34 +02:00
|
|
|
handleLine(l, false);
|
2013-10-06 20:20:34 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-05 03:39:23 +02:00
|
|
|
var handleBufferOpened = function(message) {
|
2013-10-08 03:15:25 +02:00
|
|
|
var bufferMessage = message['objects'][0]['content'][0];
|
|
|
|
var buffer = new models.Buffer(bufferMessage);
|
2013-10-08 16:05:46 +02:00
|
|
|
models.addBuffer(buffer);
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
2013-10-06 02:06:28 +02:00
|
|
|
|
2013-10-07 00:24:18 +02:00
|
|
|
var handleBufferTitleChanged = function(message) {
|
|
|
|
var obj = message['objects'][0]['content'][0];
|
|
|
|
var buffer = obj['pointers'][0];
|
2013-10-10 12:37:25 +02:00
|
|
|
var old = models.getBuffer(buffer);
|
|
|
|
old.fullName = obj['full_name'];
|
|
|
|
old.title = obj['title'];
|
|
|
|
old.number = obj['number'];
|
2013-10-10 21:34:33 +02:00
|
|
|
}
|
2013-10-07 11:45:18 +02:00
|
|
|
var handleBufferRenamed = function(message) {
|
|
|
|
var obj = message['objects'][0]['content'][0];
|
|
|
|
var buffer = obj['pointers'][0];
|
2013-10-10 12:37:25 +02:00
|
|
|
var old = models.getBuffer(buffer);
|
|
|
|
old.fullName = obj['full_name'];
|
|
|
|
old.shortName = obj['short_name'];
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 20:20:34 +02:00
|
|
|
/*
|
|
|
|
* Handle answers to (lineinfo) messages
|
|
|
|
*
|
|
|
|
* (lineinfo) messages are specified by this client. It is request after bufinfo completes
|
|
|
|
*/
|
|
|
|
var handleLineInfo = function(message) {
|
|
|
|
var lines = message['objects'][0]['content'].reverse();
|
|
|
|
lines.forEach(function(l) {
|
2013-10-06 23:59:34 +02:00
|
|
|
handleLine(l, true);
|
2013-10-06 20:20:34 +02:00
|
|
|
});
|
2013-08-05 03:59:29 +02:00
|
|
|
}
|
2013-10-06 02:06:28 +02:00
|
|
|
|
2013-10-16 01:09:31 +02:00
|
|
|
/*
|
|
|
|
* Handle answers to hotlist request
|
|
|
|
*/
|
|
|
|
var handleHotlistInfo = function(message) {
|
|
|
|
var hotlist = message['objects'][0]['content'];
|
|
|
|
hotlist.forEach(function(l) {
|
|
|
|
var buffer = models.getBuffer(l.buffer);
|
|
|
|
// 1 is message
|
|
|
|
buffer.unread += l.count[1];
|
|
|
|
// 2 is ?
|
|
|
|
buffer.unread += l.count[2];
|
|
|
|
// 3 is highlight
|
|
|
|
buffer.notification += l.count[3];
|
|
|
|
/* Since there is unread messages, we can guess
|
|
|
|
* what the last read line is and update it accordingly
|
|
|
|
*/
|
|
|
|
var unreadSum = _.reduce(l.count, function(memo, num){ return memo + num; }, 0);
|
|
|
|
buffer.lastSeen = buffer.lines.length - 1 - unreadSum;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-05 04:31:04 +02:00
|
|
|
var handleEvent = function(event) {
|
2013-10-12 18:13:32 +02:00
|
|
|
|
2013-08-05 04:31:04 +02:00
|
|
|
if (_.has(eventHandlers, event['id'])) {
|
|
|
|
eventHandlers[event['id']](event);
|
|
|
|
}
|
2013-08-05 03:59:29 +02:00
|
|
|
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
|
|
|
|
2013-08-05 04:31:04 +02:00
|
|
|
var eventHandlers = {
|
2013-10-06 02:06:28 +02:00
|
|
|
_buffer_closing: handleBufferClosing,
|
2013-08-05 03:39:23 +02:00
|
|
|
_buffer_line_added: handleBufferLineAdded,
|
2013-10-07 00:24:18 +02:00
|
|
|
_buffer_opened: handleBufferOpened,
|
2013-10-07 11:45:18 +02:00
|
|
|
_buffer_title_changed: handleBufferTitleChanged,
|
|
|
|
_buffer_renamed: handleBufferRenamed
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2013-10-12 18:29:10 +02:00
|
|
|
handleEvent: handleEvent,
|
2013-10-16 01:09:31 +02:00
|
|
|
handleLineInfo: handleLineInfo,
|
|
|
|
handleHotlistInfo: handleHotlistInfo
|
2013-08-05 03:39:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}]);
|
|
|
|
|
2013-10-15 17:20:35 +02:00
|
|
|
weechat.factory('connection', ['$q', '$rootScope', '$log', '$store', 'handlers', 'colors', 'models', function($q, $rootScope, $log, storage, handlers, colors, models) {
|
2013-10-16 23:10:49 +02:00
|
|
|
protocol = new weeChat.Protocol();
|
2013-08-02 03:54:12 +02:00
|
|
|
var websocket = null;
|
2013-02-24 20:44:03 +01:00
|
|
|
|
2013-10-12 18:13:32 +02:00
|
|
|
var callbacks = {}
|
|
|
|
var currentCallBackId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var doSendWithCallback = function(message) {
|
|
|
|
var defer = $q.defer();
|
|
|
|
callbacks[++currentCallBackId] = {
|
|
|
|
time: new Date,
|
|
|
|
cb: defer
|
|
|
|
}
|
|
|
|
callBackIdString = "(" + currentCallBackId + ")";
|
|
|
|
doSend(callBackIdString + " " + message);
|
|
|
|
return defer.promise;
|
|
|
|
}
|
2013-07-27 16:43:41 +02:00
|
|
|
|
2013-10-06 02:06:28 +02:00
|
|
|
// Sanitizes messages to be sent to the weechat relay
|
2013-08-05 04:25:59 +02:00
|
|
|
var doSend = function(message) {
|
2013-08-02 03:54:12 +02:00
|
|
|
msgs = message.replace(/[\r\n]+$/g, "").split("\n");
|
|
|
|
for (var i = 0; i < msgs.length; i++) {
|
2013-08-05 04:25:59 +02:00
|
|
|
$log.log('=' + msgs[i] + '=');
|
2013-08-02 03:55:51 +02:00
|
|
|
$rootScope.commands.push("SENT: " + msgs[i]);
|
2013-02-18 00:49:42 +01:00
|
|
|
}
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.send(message);
|
|
|
|
}
|
2013-10-06 01:54:07 +02:00
|
|
|
|
2013-08-05 04:25:59 +02:00
|
|
|
// Takes care of the connection and websocket hooks
|
2013-10-11 23:15:08 +02:00
|
|
|
var connect = function (host, port, passwd, ssl) {
|
2013-10-07 15:38:47 +02:00
|
|
|
var proto = ssl ? 'wss':'ws';
|
2013-10-11 23:15:08 +02:00
|
|
|
websocket = new WebSocket(proto+"://" + host + ':' + port + "/weechat");
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.binaryType = "arraybuffer"
|
2013-02-18 00:49:42 +01:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.onopen = function (evt) {
|
2013-10-15 17:20:35 +02:00
|
|
|
$log.info("Connected to relay");
|
2013-10-16 01:09:31 +02:00
|
|
|
$rootScope.connected = true;
|
2013-10-16 23:10:49 +02:00
|
|
|
doSend(weeChat.Protocol.formatInit({
|
2013-10-06 01:54:07 +02:00
|
|
|
password: passwd,
|
|
|
|
compression: 'off'
|
2013-10-15 17:20:35 +02:00
|
|
|
}));
|
2013-10-16 23:10:49 +02:00
|
|
|
doSendWithCallback(weeChat.Protocol.formatHdata({
|
2013-10-16 00:32:56 +02:00
|
|
|
path: 'buffer:gui_buffers(*)',
|
|
|
|
keys: ['local_variables,notify,number,full_name,short_name,title']
|
2013-10-15 17:20:35 +02:00
|
|
|
})).then(function(message) {
|
|
|
|
$log.info("Parsing bufinfo");
|
2013-10-12 18:13:32 +02:00
|
|
|
var bufferInfos = message['objects'][0]['content'];
|
|
|
|
// buffers objects
|
|
|
|
for (var i = 0; i < bufferInfos.length ; i++) {
|
|
|
|
var buffer = new models.Buffer(bufferInfos[i]);
|
|
|
|
models.addBuffer(buffer);
|
|
|
|
// Switch to first buffer on startup
|
|
|
|
if (i == 0) {
|
|
|
|
models.setActiveBuffer(buffer.id);
|
|
|
|
}
|
|
|
|
}
|
2013-10-15 17:20:35 +02:00
|
|
|
}).then(function() {
|
|
|
|
$log.info("Parsing lineinfo");
|
2013-10-16 23:10:49 +02:00
|
|
|
doSendWithCallback(weeChat.Protocol.formatHdata({
|
2013-10-15 17:20:35 +02:00
|
|
|
path: "buffer:gui_buffers(*)/own_lines/last_line(-"+storage.get('lines')+")/data",
|
|
|
|
keys: []
|
|
|
|
})).then(function(hdata) {
|
|
|
|
handlers.handleLineInfo(hdata);
|
|
|
|
});
|
2013-10-16 01:09:31 +02:00
|
|
|
}).then(function() {
|
|
|
|
$log.info("Requesting hotlist");
|
2013-10-16 23:10:49 +02:00
|
|
|
doSendWithCallback(weeChat.Protocol.formatHdata({
|
2013-10-16 01:09:31 +02:00
|
|
|
path: "hotlist:gui_hotlist(*)",
|
|
|
|
keys: []
|
|
|
|
})).then(function(hdata) {
|
|
|
|
handlers.handleHotlistInfo(hdata)
|
|
|
|
});
|
2013-10-15 17:20:35 +02:00
|
|
|
}).then(function() {
|
2013-10-16 23:10:49 +02:00
|
|
|
doSend(weeChat.Protocol.formatSync({}));
|
2013-10-15 17:20:35 +02:00
|
|
|
$log.info("Synced");
|
2013-10-12 18:13:32 +02:00
|
|
|
});
|
2013-08-02 03:54:12 +02:00
|
|
|
}
|
2013-07-21 17:48:32 +02:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.onclose = function (evt) {
|
2013-08-05 04:25:59 +02:00
|
|
|
$log.info("Disconnected from relay");
|
2013-08-02 03:55:51 +02:00
|
|
|
$rootScope.connected = false;
|
2013-08-05 04:25:59 +02:00
|
|
|
$rootScope.$apply();
|
2013-08-02 03:54:12 +02:00
|
|
|
}
|
2013-07-21 17:48:32 +02:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.onmessage = function (evt) {
|
2013-08-05 03:59:29 +02:00
|
|
|
message = protocol.parse(evt.data)
|
2013-10-12 18:13:32 +02:00
|
|
|
if (_.has(callbacks, message['id'])) {
|
|
|
|
var promise = callbacks[message['id']];
|
2013-10-12 18:29:10 +02:00
|
|
|
promise.cb.resolve(message);
|
2013-10-12 18:13:32 +02:00
|
|
|
delete(callbacks[message['id']]);
|
|
|
|
} else {
|
|
|
|
handlers.handleEvent(message);
|
|
|
|
}
|
2013-08-02 03:55:51 +02:00
|
|
|
$rootScope.commands.push("RECV: " + evt.data + " TYPE:" + evt.type) ;
|
|
|
|
$rootScope.$apply();
|
2013-08-02 03:54:12 +02:00
|
|
|
}
|
2013-07-21 17:48:32 +02:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
websocket.onerror = function (evt) {
|
2013-10-07 15:38:47 +02:00
|
|
|
if (evt.type == "error" && websocket.readyState != 1) {
|
2013-10-03 01:55:30 +02:00
|
|
|
$rootScope.errorMessage = true;
|
|
|
|
}
|
2013-08-05 04:25:59 +02:00
|
|
|
$log.error("Relay error " + evt.data);
|
2013-02-18 00:49:42 +01:00
|
|
|
}
|
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
this.websocket = websocket;
|
|
|
|
}
|
2013-07-31 14:40:43 +02:00
|
|
|
|
2013-10-16 14:25:07 +02:00
|
|
|
var disconnect = function() {
|
|
|
|
console.log(this.websocket);
|
|
|
|
this.websocket.close();
|
|
|
|
}
|
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
var sendMessage = function(message) {
|
2013-10-16 23:10:49 +02:00
|
|
|
doSend(weeChat.Protocol.formatInput({
|
2013-10-08 15:55:07 +02:00
|
|
|
buffer: models.getActiveBuffer()['fullName'],
|
2013-10-06 01:54:07 +02:00
|
|
|
data: message
|
|
|
|
}));
|
2013-08-02 03:54:12 +02:00
|
|
|
}
|
2013-07-21 17:48:32 +02:00
|
|
|
|
2013-10-06 20:20:34 +02:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
return {
|
2013-10-06 20:20:34 +02:00
|
|
|
send: doSend,
|
2013-08-02 03:54:12 +02:00
|
|
|
connect: connect,
|
2013-10-16 14:25:07 +02:00
|
|
|
disconnect: disconnect,
|
2013-08-02 03:54:12 +02:00
|
|
|
sendMessage: sendMessage
|
|
|
|
}
|
2013-02-18 00:49:42 +01:00
|
|
|
}]);
|
|
|
|
|
2013-10-16 01:09:31 +02:00
|
|
|
weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', '$log', 'models', 'connection', function ($rootScope, $scope, $store, $timeout, $log, models, connection, testService) {
|
2013-10-08 15:55:07 +02:00
|
|
|
|
2013-10-06 12:34:41 +02:00
|
|
|
// Request notification permission
|
|
|
|
Notification.requestPermission(function (status) {
|
2013-10-16 01:09:31 +02:00
|
|
|
$log.info('Notification permission status:',status);
|
2013-10-06 12:34:41 +02:00
|
|
|
if (Notification.permission !== status) {
|
|
|
|
Notification.permission = status;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if(window.webkitNotifications != undefined) {
|
|
|
|
if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED
|
2013-10-16 01:09:31 +02:00
|
|
|
$log.info('Notification permission status:', window.webkitNotifications.checkPermission() == 0);
|
2013-10-06 12:34:41 +02:00
|
|
|
window.webkitNotifications.requestPermission();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-12 22:09:02 +02:00
|
|
|
$rootScope.$on('activeBufferChanged', function() {
|
|
|
|
$rootScope.scrollToBottom();
|
|
|
|
document.getElementById('sendMessage').focus();
|
|
|
|
var ab = models.getActiveBuffer();
|
|
|
|
$rootScope.pageTitle = ab.shortName + ' | ' + ab.title;
|
|
|
|
});
|
2013-10-15 15:21:13 +02:00
|
|
|
$rootScope.$on('notificationChanged', function() {
|
2013-10-15 19:08:24 +02:00
|
|
|
var notifications = _.reduce(models.model.buffers, function(memo, num) { return (memo||0) + num.notification;});
|
2013-10-15 15:21:13 +02:00
|
|
|
if (notifications > 0 ) {
|
|
|
|
$scope.favico = new Favico({
|
|
|
|
animation:'none'
|
|
|
|
});
|
|
|
|
$scope.favico.badge(notifications);
|
|
|
|
}else {
|
2013-10-15 19:08:24 +02:00
|
|
|
var unread = _.reduce(models.model.buffers, function(memo, num) { return (memo||0) + num.unread;});
|
2013-10-15 15:21:13 +02:00
|
|
|
$scope.favico = new Favico({
|
|
|
|
animation:'none',
|
|
|
|
bgColor : '#5CB85C',
|
|
|
|
textColor : '#ff0',
|
|
|
|
});
|
|
|
|
$scope.favico.badge(unread);
|
|
|
|
}
|
|
|
|
});
|
2013-10-12 22:09:02 +02:00
|
|
|
|
2013-10-08 15:55:07 +02:00
|
|
|
$scope.buffers = models.model.buffers;
|
|
|
|
$scope.activeBuffer = models.getActiveBuffer
|
|
|
|
|
2013-02-18 00:49:42 +01:00
|
|
|
$rootScope.commands = []
|
2013-02-16 19:18:14 +01:00
|
|
|
|
2013-10-08 15:55:07 +02:00
|
|
|
$rootScope.models = models;
|
|
|
|
|
2013-07-21 17:48:32 +02:00
|
|
|
$rootScope.buffer = []
|
2013-10-08 15:55:07 +02:00
|
|
|
|
2013-10-11 23:15:08 +02:00
|
|
|
$store.bind($scope, "host", "localhost");
|
|
|
|
$store.bind($scope, "port", "9001");
|
2013-10-05 16:05:16 +02:00
|
|
|
$store.bind($scope, "proto", "weechat");
|
|
|
|
$store.bind($scope, "password", "");
|
2013-10-09 17:53:25 +02:00
|
|
|
$store.bind($scope, "ssl", false);
|
2013-10-11 23:21:51 +02:00
|
|
|
$store.bind($scope, "lines", "40");
|
2013-10-05 16:05:16 +02:00
|
|
|
// TODO checkbox for saving password or not?
|
|
|
|
// $scope.password = "";
|
2013-10-16 15:45:38 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
$store.bind($scope, "onlyUnread", false);
|
2013-10-02 02:32:18 +02:00
|
|
|
|
|
|
|
|
2013-07-30 15:22:37 +02:00
|
|
|
$scope.setActiveBuffer = function(key) {
|
2013-10-08 15:55:07 +02:00
|
|
|
models.setActiveBuffer(key);
|
2013-07-30 15:22:37 +02:00
|
|
|
};
|
|
|
|
|
2013-10-07 16:58:41 +02:00
|
|
|
$rootScope.scrollToBottom = function() {
|
2013-10-11 13:41:36 +02:00
|
|
|
// FIXME doesn't work if the settimeout runs without a short delay
|
|
|
|
// 300 ms seems to do the trick but creates a noticable flickr
|
|
|
|
$timeout(function() {
|
2013-10-12 20:44:40 +02:00
|
|
|
var readmarker = document.getElementById('readmarker');
|
|
|
|
if(readmarker) {
|
|
|
|
readmarker.scrollIntoView();
|
|
|
|
}else{
|
2013-10-12 21:16:40 +02:00
|
|
|
window.scroll(0, document.documentElement.scrollHeight - document.documentElement.clientHeight);
|
2013-10-11 18:45:01 +02:00
|
|
|
}
|
2013-10-11 13:41:36 +02:00
|
|
|
}, 300);
|
2013-10-07 16:58:41 +02:00
|
|
|
}
|
|
|
|
|
2013-02-18 00:49:42 +01:00
|
|
|
$scope.sendMessage = function() {
|
|
|
|
connection.sendMessage($scope.command);
|
|
|
|
$scope.command = "";
|
2013-07-30 15:22:37 +02:00
|
|
|
};
|
2013-02-16 19:18:14 +01:00
|
|
|
|
2013-02-18 00:49:42 +01:00
|
|
|
$scope.connect = function() {
|
2013-10-11 23:15:08 +02:00
|
|
|
connection.connect($scope.host, $scope.port, $scope.password, $scope.ssl);
|
2013-02-16 19:18:14 +01:00
|
|
|
}
|
2013-10-16 14:44:44 +02:00
|
|
|
$scope.disconnect = function() {
|
2013-10-16 14:25:07 +02:00
|
|
|
connection.disconnect();
|
|
|
|
}
|
2013-10-06 12:34:41 +02:00
|
|
|
|
|
|
|
/* Function gets called from bufferLineAdded code if user should be notified */
|
2013-10-09 17:53:25 +02:00
|
|
|
$rootScope.createHighlight = function(buffer, message) {
|
2013-10-06 12:34:41 +02:00
|
|
|
var messages = "";
|
2013-10-09 17:53:25 +02:00
|
|
|
message.content.forEach(function(part) {
|
|
|
|
if (part.text != undefined)
|
|
|
|
messages += part.text + " ";
|
|
|
|
});
|
2013-10-06 12:34:41 +02:00
|
|
|
|
2013-10-09 17:53:25 +02:00
|
|
|
var title = buffer.fullName;
|
|
|
|
var content = messages;
|
2013-10-06 12:34:41 +02:00
|
|
|
|
|
|
|
var timeout = 15*1000;
|
2013-10-16 01:09:31 +02:00
|
|
|
$log.info('Displaying notification:buffer:',buffer,',message:',message,',with timeout:',timeout);
|
2013-10-06 12:34:41 +02:00
|
|
|
var notification = new Notification(title, {body:content, icon:'img/favicon.png'});
|
|
|
|
// Cancel notification automatically
|
|
|
|
notification.onshow = function() {
|
|
|
|
setTimeout(function() { notification.close() }, timeout);
|
|
|
|
}
|
|
|
|
};
|
2013-10-11 14:44:05 +02:00
|
|
|
|
|
|
|
$scope.hasUnread = function(buffer) {
|
|
|
|
if($scope.onlyUnread) {
|
2013-10-11 23:47:47 +02:00
|
|
|
// Always show current buffer in list
|
|
|
|
if (models.getActiveBuffer() == buffer) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-15 15:21:13 +02:00
|
|
|
return buffer.unread > 0;
|
2013-10-11 14:44:05 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
2013-10-11 15:59:55 +02:00
|
|
|
|
|
|
|
$rootScope.switchToActivityBuffer = function() {
|
|
|
|
// Find next buffer with activity and switch to it
|
2013-10-11 22:43:01 +02:00
|
|
|
for(i in $scope.buffers) {
|
|
|
|
var buffer = $scope.buffers[i];
|
2013-10-15 14:59:06 +02:00
|
|
|
if(buffer.notification > 0) {
|
2013-10-11 15:59:55 +02:00
|
|
|
$scope.setActiveBuffer(buffer.id);
|
2013-10-11 22:43:01 +02:00
|
|
|
break;
|
2013-10-15 14:59:06 +02:00
|
|
|
}else if(buffer.unread > 0) {
|
2013-10-11 15:59:55 +02:00
|
|
|
$scope.setActiveBuffer(buffer.id);
|
2013-10-11 22:43:01 +02:00
|
|
|
break;
|
2013-10-11 15:59:55 +02:00
|
|
|
}
|
2013-10-11 22:43:01 +02:00
|
|
|
}
|
2013-10-11 15:59:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.handleKeyPress = function($event) {
|
2013-10-11 16:24:25 +02:00
|
|
|
// Support different browser quirks
|
|
|
|
var code = $event.keyCode ? $event.keyCode : $event.charCode;
|
|
|
|
|
2013-10-12 18:54:13 +02:00
|
|
|
if ($event.altKey && (code > 47 && code < 58)) {
|
|
|
|
if (code == 48) {
|
|
|
|
code = 58;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bufferNumber = code - 48;
|
|
|
|
var activeBuffer = models.getBufferByIndex(bufferNumber);
|
|
|
|
if (activeBuffer) {
|
|
|
|
models.setActiveBuffer(activeBuffer.id);
|
|
|
|
$event.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-16 01:09:31 +02:00
|
|
|
//log('keypress', $event.charCode, $event.altKey);
|
2013-10-11 16:24:25 +02:00
|
|
|
|
2013-10-11 15:59:55 +02:00
|
|
|
// Handle alt-a
|
2013-10-11 16:24:25 +02:00
|
|
|
if($event.altKey && (code == 97 || code == 65)) {
|
2013-10-12 20:44:40 +02:00
|
|
|
$event.preventDefault();
|
2013-10-11 15:59:55 +02:00
|
|
|
$rootScope.switchToActivityBuffer();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Handle ctrl-g
|
2013-10-11 16:24:25 +02:00
|
|
|
if($event.ctrlKey && (code == 103 || code == 71)) {
|
2013-10-12 20:44:40 +02:00
|
|
|
document.getElementById('bufferFilter').focus();
|
2013-10-11 15:59:55 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2013-10-15 15:21:13 +02:00
|
|
|
|
2013-08-02 03:54:12 +02:00
|
|
|
}]
|
|
|
|
);
|