lib/jschat/http/public/javascripts/app/controllers/chat_controller.js in jschat-0.3.3 vs lib/jschat/http/public/javascripts/app/controllers/chat_controller.js in jschat-0.3.5

- old
+ new

@@ -97,10 +97,12 @@ try { var element = Event.element(e); var message = $('message').value; $('message').value = ''; + this.tabCompletion.history.add(message); + if (message.length > 0) { var command_posted = $H(UserCommands).find(function(command) { var name = command[0]; var matches = message.match(new RegExp('^' + name + '$')); if (matches) { @@ -108,18 +110,16 @@ return true; } }.bind(this)); if (!command_posted) { - if (message.match(/^\//)) { + if (message.match(/^\/\s?\//)) { + this.postMessage(message.replace(/\//, '').strip()); + } else if (message.match(/^\//)) { Display.add_message('Error: Command not found. Use /help display commands.', 'error'); } else { - Display.message({ 'message': message.escapeHTML(), 'user': JsChat.user.name }, new Date()); - new Ajax.Request('/message', { - method: 'post', - parameters: { 'message': message, 'to': PageHelper.currentRoom() } - }); + this.postMessage(message); } } } } catch (exception) { console.log(exception); @@ -127,10 +127,25 @@ Event.stop(e); return false; }, + postMessage: function(message) { + Display.message({ 'message': message.escapeHTML(), 'user': JsChat.user.name }, new Date()); + new Ajax.Request('/message', { + method: 'post', + parameters: { 'message': message, 'to': PageHelper.currentRoom() } + }); + }, + + sendTweet: function(message) { + new Ajax.Request('/tweet', { + method: 'post', + parameters: { 'tweet': message } + }); + }, + initDisplay: function() { Display.unread = 0; Display.show_unread = false; Display.ignore_notices = false; @@ -291,10 +306,10 @@ } }.bind(this)); }, updateNames: function() { - UserCommands['/names'].apply(this); + JsChat.Request.get('/names', function(t) { this.displayMessages(t.responseText); }.bind(this)); }, showMessagesResponse: function(transport) { try { this.displayMessages(transport.responseText);