summaryrefslogtreecommitdiffstats
path: root/webchat/public
diff options
context:
space:
mode:
authorlassulus <lassulus@googlemail.com>2013-11-12 04:08:38 +0100
committerlassulus <lassulus@googlemail.com>2013-11-12 04:08:38 +0100
commitb749c216ae84f02330da7396135be11259ec12d9 (patch)
treeb9a6f98f3f2b4f4c5ee60d36e1d11acdf57da267 /webchat/public
parent721b4fb1b32ee47f158fb3b9a1ad0747ff579044 (diff)
webchat: fix nicklist
Diffstat (limited to 'webchat/public')
-rw-r--r--webchat/public/client.js22
-rw-r--r--webchat/public/functions.js8
2 files changed, 17 insertions, 13 deletions
diff --git a/webchat/public/client.js b/webchat/public/client.js
index d7a5ecab..54ccfe34 100644
--- a/webchat/public/client.js
+++ b/webchat/public/client.js
@@ -3,16 +3,16 @@ settings.sock = new SockJS('/echo');
settings.waiting_callbacks = {}
var transport = make_sockjs_client_transport(settings.sock)
-var rpc = new RPC(transport)
+settings.rpc = new RPC(transport)
-rpc.register('msg', {type: 'string', nick: 'string', msg: 'string'}, function(params, callback) {
+settings.rpc.register('msg', {type: 'string', nick: 'string', msg: 'string'}, function(params, callback) {
var safe_message = $('<div/>').text(params.msg).html();
safe_message = replaceURLWithHTMLLinks(safe_message);
var safe_from = $('<div/>').text(params.nick).html();
chatboxAppend(safe_from, safe_message, 'web_msg')
return callback(null)
})
-rpc.register('nick', {type: 'string', newnick: 'string', oldnick: 'string'}, function(params, callback) {
+settings.rpc.register('nick', {type: 'string', newnick: 'string', oldnick: 'string'}, function(params, callback) {
var safe_oldnick = $('<div/>').text(params.oldnick).html();
var safe_newnick = $('<div/>').text(params.newnick).html();
var safe_type = $('<div/>').text(params.type).html();
@@ -25,20 +25,20 @@ rpc.register('nick', {type: 'string', newnick: 'string', oldnick: 'string'}, fun
chatboxAppend(safe_oldnick, 'is now known as ' + safe_newnick, 'nick');
return callback(null)
})
-rpc.register('your_nick', {nick: 'string'}, function(params, callback) {
+settings.rpc.register('your_nick', {nick: 'string'}, function(params, callback) {
var safe_nick = $('<div/>').text(params.nick).html();
settings.nick = safe_nick
$('#nick').html(settings.nick)
return callback(null)
})
-rpc.register('join', {type: 'string', nick: 'string'}, function(params, callback) {
+settings.rpc.register('join', {type: 'string', nick: 'string'}, function(params, callback) {
var safe_nick = $('<div/>').text(params.nick).html();
var safe_type = $('<div/>').text(params.type).html();
$('#nicklist').append('<div class="'+safe_type+'_name">' + safe_nick + '</div>') ;
chatboxAppend(safe_nick, 'has joined');
return callback(null)
})
-rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) {
+settings.rpc.register('part', {type: 'string', nick: 'string'}, function(params, callback) {
var safe_nick = $('<div/>').text(params.nick).html();
var safe_type = $('<div/>').text(params.type).html();
$(getNicklistElement(safe_nick,safe_type)).remove();
@@ -60,14 +60,10 @@ $(function() {
e.stopPropagation();
e.stopImmediatePropagation();
var input = ($('#input').val());
- $('#input').val('');
+ $('#input').val('')
- var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(input)
- if (match) {
- return rpc.send(match[1], match[2])
- } else {
- return rpc.send('msg', input)
- }
+ var command = inputParser(input)
+ return (commands[command.method] || commands.badcommand)(settings, command.params)
}
});
diff --git a/webchat/public/functions.js b/webchat/public/functions.js
index 318d0865..781fafce 100644
--- a/webchat/public/functions.js
+++ b/webchat/public/functions.js
@@ -1,3 +1,11 @@
+function inputParser (str) {
+ var match = /^\/([a-z]+)(?:\s+(.*\S))?\s*$/.exec(str)
+ if (match) {
+ return { method: match[1], params: match[2] }
+ } else {
+ return { method: 'msg', params: str }
+ }
+}
function replaceURLWithHTMLLinks (text) {
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;