Fixes + auto-torch after configurable delay

This commit is contained in:
Hexagon 2016-01-02 19:13:25 +01:00
parent dd8529bd88
commit 10384f956d
8 changed files with 51 additions and 14 deletions

View File

@ -12,9 +12,9 @@ Features
* Client side AES-256-CBC encryption/decryption (the server is just a messenger)
* 256 bit key derived from your passphrase using PBKDF2
* Message is torched after a configurable delay, default is 600s.
* Optional nicknames
* Random (UUID v4) channel name generation for less guessability
* Quick-links (not recommended) using http://server/#Room:Passphrase
* Quick-links (not recommended!) using http://server/#Room:Passphrase
* Super simple setup
* Notification sounds (mutable)
* Native popup notifications

View File

@ -29,7 +29,6 @@ body, html {
.info { color: #99FFFF; }
.neutral { color: #eeeeee; }
/*------------------------------------*\
CHAT
\*------------------------------------*/
@ -47,7 +46,11 @@ body, html {
#chat li {
white-space: pre;
padding: 2px 15px;
color: #343434;
color: #606006;
}
#chat li .timestamp {
color: #808008;
}
/* Message types */

View File

@ -152,10 +152,13 @@ define(['fandango', 'websocket', 'aes', 'SHA1'], function (fandango, websocket,
for (var i = 0, len = this.length; i < len; i++) {
this[0].innerHTML += string;
}
return this;
};
proto.first = function () {
return this[0];
};
// Naive implementations of .on()
proto.on = function (eventName, callback) {
for (var i = 0, len = this.length; i < len; i++) {

View File

@ -4,7 +4,8 @@
mediator.on('command:help', ...);
mediator.on('command:nick', ...);
mediator.on('command:key', ...);
mediator.on('command:clear', ...);
mediator.on('command:key', ...);
mediator.on('command:torch', ...);
mediator.on('command:title', ...);
Emits:
@ -58,6 +59,8 @@ define(
clear = function () { mediator.emit('console:clear'); },
setTorch = function (payload) { mediator.emit('console:torch',payload); },
nick = function (payload) {
// Make sure the nick meets the length requirements
@ -87,6 +90,7 @@ define(
mediator.on('command:clear', clear);
mediator.on('command:nick', nick);
mediator.on('command:key', setKey);
mediator.on('command:torch', setTorch);
mediator.on('command:title', title);
});

View File

@ -2,6 +2,7 @@
Accepts:
mediator.on('console:clear', clear);
mediator.on('console:torch', ttl)
mediator.on('console:motd', motd);
mediator.on('console:info', info);
mediator.on('console:error', error);
@ -42,10 +43,12 @@ define({
commands = {
post: function (type, text, nick) {
var tpl = templates.post[type],
uniqueId = 'msg_' + new Date().getTime() + '_' + Math.round(Math.random()*1000000),
post,
data = fandango.merge({}, settings, {
nick: nick,
timestamp: new Date().toLocaleTimeString()
timestamp: new Date().toLocaleTimeString(),
id: uniqueId
});
data.text = $.template(text, data);
@ -54,10 +57,27 @@ define({
// Request a notification
commands.showNotification(type, nick, text);
// Expire message
setTimeout(function() {
var parent = components.chat.first(),
child = $('#'+uniqueId).first();
parent.removeChild(child);
}, settings.ttl);
// Append the post to the chat DOM element
components.chat.append(post);
},
torch: function (ttl) {
var ttl = parseInt(ttl);
if( ttl > 0 && ttl < 3600) {
mediator.emit('console:info', $.template(templates.messages.torch_is_now, { ttl: ttl }) );
settings.ttl = ttl*1000;
} else {
mediator.emit('console:error', $.template(templates.messages.torch_not_set) );
}
},
param: function (p) {
parameters = fandango.merge({}, parameters, p);
},

View File

@ -2,6 +2,8 @@ define({
title: "Cryptalk - Online",
ttl: 600000,
motd: '<pre>\n\n' +
'▄████▄ ██▀███ ▓██ ██▓ ██▓███ ▄▄▄█████▓ ▄▄▄ ██▓ ██ ▄█▀ \n' +
'▒██▀ ▀█ ▓██ ▒ ██▒▒██ ██▒▓██░ ██▒▓ ██▒ ▓▒▒████▄ ▓██▒ ██▄█▒ \n' +

View File

@ -15,6 +15,9 @@ define({
' /clear Clear on-screen buffer \n' +
' /help This \n' +
' /title Set your local page title \n' +
' /torch AfterSeconds Console messages are torched \n' +
' after this amount of seconds \n' +
' (default 600). \n' +
' \n' +
'Room: \n' +
' /join RoomId Join a room \n' +
@ -42,11 +45,11 @@ define({
// All post templates will have access to the properties in the 'settings' module,
// along with the current nick, room, mute-status and of course the message ('text').
post: {
motd: '<li><i class="motd">{text}</i></li>',
info: '<li><i class="timestamp">[{timestamp}] </i>INF&gt; <i class="info">{text}</i></li>',
server: '<li><i class="timestamp">[{timestamp}] </i>SRV&gt; <i class="server">{text}</i></li>',
error: '<li><i class="timestamp">[{timestamp}] </i>ERR&gt; <i class="error">{text}</i></li>',
message: '<li><i class="timestamp">[{timestamp}] </i>MSG&gt; <i class="nick">{nick}&gt;</i> <i class="message">{text}</i></li>'
motd: '<li id="{id}"><i class="motd">{text}</i></li>',
info: '<li id="{id}"><i class="timestamp">[{timestamp}] </i>INF&gt; <i class="info">{text}</i></li>',
server: '<li id="{id}"><i class="timestamp">[{timestamp}] </i>SRV&gt; <i class="server">{text}</i></li>',
error: '<li id="{id}"><i class="timestamp">[{timestamp}] </i>ERR&gt; <i class="error">{text}</i></li>',
message: '<li id="{id}"><i class="timestamp">[{timestamp}] </i>MSG&gt; <i class="nick">{nick}&gt;</i> <i class="message">{text}</i></li>'
},
// All message templates will have access to the properties in the 'settings' module,
@ -68,6 +71,9 @@ define({
msg_no_key: 'You have to set an encryption key before sending a message. See /help.',
leave_from_nowhere: 'How are you supposed to leave, while being nowhere?',
torch_is_now: 'Messages are now torched after {ttl} seconds.',
torch_not_set: 'Invalid torch delay entered, nothing changed. See /help.',
title_set: 'The title of this window is now \'{title}\'.',
muted: 'Notifications and sounds are now muted.',

View File

@ -1,7 +1,6 @@
#!/usr/bin/env node
var express = require('express.io'),
app = express();app.http().io();
app.use(express.static(__dirname + '/public'));