diff --git a/src/js/chat.js b/src/js/chat.js index 2bf881a..ac2aae8 100644 --- a/src/js/chat.js +++ b/src/js/chat.js @@ -156,6 +156,7 @@ export default class Chat { command: 'nick', description: 'Changes nickname.', paramaters: ['{username}'], + multiple: false, usage: '/nick {username}', action: () => { let newUsername = trigger.params[0] || false; @@ -186,13 +187,37 @@ export default class Chat { command: 'help', description: 'Shows a list of commands.', paramaters: [], + multiple: false, usage: '/help', action: () => { validCommands = validCommands.map((command) => { return '/' + command; }); - this.log('Valid commands: ' + validCommands.join(', '), {info: true}); + this.log('Valid commands: ' + validCommands.sort().join(', '), {info: true}); + } + }, { + command: 'me', + description: 'Invoke virtual action', + paramaters: ['{action}'], + multiple: true, + usage: '/me {action}', + action: () => { + + expectedParams = 100; + + let actionMessage = trigger.params.join(' '); + + this.darkwire.encodeMessage(actionMessage, 'action').then((socketData) => { + this.addChatMessage({ + username: username, + message: actionMessage, + messageType: 'action' + }); + this.socket.emit('new message', socketData); + }).catch((err) => { + console.log(err); + }); } }]; @@ -208,9 +233,12 @@ export default class Chat { if (commandToTrigger) { expectedParams = commandToTrigger.paramaters.length; - if (trigger.params.length > expectedParams || trigger.params.length < expectedParams) { - return this.log('Missing or too many paramater. Usage: ' + commandToTrigger.usage, {error: true}); + if (expectedParams && trigger.params.length > expectedParams || expectedParams && trigger.params.length < expectedParams) { + if (!commandToTrigger.multple && trigger.params.length < 1) { + return this.log('Missing or too many paramater. Usage: ' + commandToTrigger.usage, {error: true}); + } } + return commandToTrigger.action.call(); } @@ -267,18 +295,25 @@ export default class Chat { let $usernameDiv = $('') .text(data.username) .css('color', this.getUsernameColor(data.username)); + let $messageBodyDiv = $(''); - if (messageType !== 'text') { - $messageBodyDiv.html(this.darkwire.addFileToQueue(data)); - } else { + + if (messageType === 'text' || messageType === 'action') { + if (messageType === 'action') { + $usernameDiv.css('color','').prepend('*'); + } $messageBodyDiv.html(unescape(data.message)); + } else { + $messageBodyDiv.html(this.darkwire.addFileToQueue(data)); } let typingClass = data.typing ? 'typing' : ''; + let actionClass = data.messageType === 'action' ? 'action' : ''; let $messageDiv = $('
  • ') .data('username', data.username) .addClass(typingClass) + .addClass(actionClass) .append($usernameDiv, $messageBodyDiv); this.addMessageElement($messageDiv, options); diff --git a/src/js/main.js b/src/js/main.js index 72403f8..2cb959a 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -3,6 +3,7 @@ import Darkwire from './darkwire'; import WindowHandler from './window'; import CryptoUtil from './crypto'; import Chat from './chat'; +import moment from 'moment'; let fs = window.RequestFileSystem || window.webkitRequestFileSystem; @@ -49,6 +50,7 @@ $(function() { }); } + chat.log(moment().format('MMMM Do YYYY, h:mm:ss a'), {info: true}); darkwire.updateUsername(username).then((socketData) => { chat.chatPage.show(); chat.inputMessage.focus(); diff --git a/src/public/style.css b/src/public/style.css index 9d3b61e..619489a 100644 --- a/src/public/style.css +++ b/src/public/style.css @@ -312,3 +312,8 @@ html.no-touchevents .chat #input-icons { color: yellow; font-weight: bold; } + +.action { + font-style: italic; + color: #00FF7F; +}