Mostly done!

This commit is contained in:
Hexagon 2014-09-26 18:21:27 +02:00
parent 4f4f7c4325
commit 1ad2108e71
6 changed files with 29 additions and 9 deletions

View File

@ -5,6 +5,7 @@
mediator.on('command:nick', ...); mediator.on('command:nick', ...);
mediator.on('command:key', ...); mediator.on('command:key', ...);
mediator.on('command:clear', ...); mediator.on('command:clear', ...);
mediator.on('command:title', ...);
Emits: Emits:
mediator.emit('nick:changed',...); mediator.emit('nick:changed',...);
@ -53,7 +54,7 @@ define(
return mediator.emit('console:info', templates.messages.key_ok ); return mediator.emit('console:info', templates.messages.key_ok );
}, },
help = function (payload, done) { mediator.emit('console:motd', templates.help); }, help = function () { mediator.emit('console:motd', templates.help); },
clear = function () { mediator.emit('console:clear'); }, clear = function () { mediator.emit('console:clear'); },
@ -75,11 +76,17 @@ define(
// Inform that the nick has been set // Inform that the nick has been set
mediator.emit('console:info', $.template(templates.messages.nick_set, { nick: $.escapeHtml(nick)})); mediator.emit('console:info', $.template(templates.messages.nick_set, { nick: $.escapeHtml(nick)}));
},
title = function(payload) {
mediator.emit('window:title',payload);
mediator.emit('console:info', $.template(templates.messages.title_set, { title: $.escapeHtml(payload)}));
}; };
mediator.on('command:help', help); mediator.on('command:help', help);
mediator.on('command:clear', clear); mediator.on('command:clear', clear);
mediator.on('command:nick', nick); mediator.on('command:nick', nick);
mediator.on('command:key', setKey); mediator.on('command:key', setKey);
mediator.on('command:title', title);
}); });

View File

@ -89,12 +89,18 @@ define(
message = function (payload, done) { post('message', payload.message , payload.nick ); }, message = function (payload, done) { post('message', payload.message , payload.nick ); },
server = function (payload, done) { post('server', payload); }, server = function (payload, done) { post('server', payload); },
clear = function () { clearInput = function () {
fandango.subordinate(function () { fandango.subordinate(function () {
components.input[0].value = ''; components.input[0].value = '';
}); });
}, },
clear = function () {
fandango.subordinate(function () {
components.chat[0].innerHTML=''
});
},
lockInput = function () { lockInput = function () {
components.input[0].setAttribute('disabled', 'disabled'); components.input[0].setAttribute('disabled', 'disabled');
components.inputWrapper[0].className = 'loading'; components.inputWrapper[0].className = 'loading';
@ -140,7 +146,7 @@ define(
if(recipients == 0) { if(recipients == 0) {
return post('error', $.template(templates.messages.unrecognized_command, { commandName: command })); return post('error', $.template(templates.messages.unrecognized_command, { commandName: command }));
} else { } else {
clear(); clearInput();
} }
} }
); );
@ -152,8 +158,6 @@ define(
return (!parameters.room) ? post('error', templates.messages.msg_no_room) : post('error', templates.messages.msg_no_key); return (!parameters.room) ? post('error', templates.messages.msg_no_room) : post('error', templates.messages.msg_no_key);
} }
console.log(parameters.room);
// Before sending the message. // Before sending the message.
// Encrypt message using room UUID as salt and key as pepper. // Encrypt message using room UUID as salt and key as pepper.
mediator.emit( mediator.emit(
@ -169,7 +173,7 @@ define(
); );
// And clear the the buffer // And clear the the buffer
clear(); clearInput();
} }
}; };

View File

@ -34,7 +34,6 @@ define(
emit = function(payload) { emit = function(payload) {
// Route message from mediator to socket // Route message from mediator to socket
console.log('EMIT:',payload.data,payload.payload);
if(socket) socket.emit(payload.data,payload.payload); if(socket) socket.emit(payload.data,payload.payload);
}, },
@ -252,8 +251,6 @@ define(
param = function (p) { param = function (p) {
parameters = fandango.merge({}, parameters, p ); parameters = fandango.merge({}, parameters, p );
console.log(p);
console.log(parameters);
}; };
mediator.on('command:host', host); mediator.on('command:host', host);

View File

@ -31,6 +31,10 @@ define(
join = function(payload) { join = function(payload) {
if (room !== false) { if (room !== false) {
mediator.emit('console:error',$.template(templates.messages.already_in_room, { room: room })); mediator.emit('console:error',$.template(templates.messages.already_in_room, { room: room }));
} else if (payload.length >= settings.room.maxLen) {
mediator.emit('console:error',$.template(templates.messages.room_name_too_long));
} else if (payload.length < settings.room.minLen) {
mediator.emit('console:error',$.template(templates.messages.room_name_too_short));
} else { } else {
room = payload; room = payload;
mediator.emit('room:changed', room ); mediator.emit('room:changed', room );

View File

@ -29,6 +29,11 @@ define({
minLen: 8, minLen: 8,
}, },
room: {
minLen: 1,
maxLen: 64
},
notifications: { notifications: {
maxOnePerMs: 3000 maxOnePerMs: 3000
}, },

View File

@ -75,6 +75,9 @@ define({
unrecognized_command: 'Unrecognized command: "{commandName}"', unrecognized_command: 'Unrecognized command: "{commandName}"',
room_name_too_long: 'Isn\'t that a bit long?',
room_name_too_short: 'Nah, too short.',
joined_room: 'Joined room {roomName}.', joined_room: 'Joined room {roomName}.',
left_room: 'Left room {roomName}.', left_room: 'Left room {roomName}.',
already_in_room: 'You are already in a room ({room}), stoopid.', already_in_room: 'You are already in a room ({room}), stoopid.',