From 83a820b720cb6659dcd2e11ea1103459563839d8 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 12 Mar 2013 16:59:15 +0000 Subject: [PATCH 1/2] new function for handling custom messages, allows objects to be sent, before we only allowed strings --- src/node/handler/PadMessageHandler.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/node/handler/PadMessageHandler.js b/src/node/handler/PadMessageHandler.js index c046f130a..076f31a58 100644 --- a/src/node/handler/PadMessageHandler.js +++ b/src/node/handler/PadMessageHandler.js @@ -254,6 +254,23 @@ function handleSaveRevisionMessage(client, message){ }); } +/** + * Handles a custom message, different to the function below as it handles objects not strings and you can direct the message to specific sessionID + * + * @param msg {Object} the message we're sending + * @param sessionID {string} the socketIO session to which we're sending this message + */ +exports.handleCustomObjectMessage = function (msg, sessionID, cb) { + if(sessionID){ // If a sessionID is targeted then send directly to this sessionID + io.sockets.socket(sessionID).emit(msg); // send a targeted message + }else{ + socketio.sockets.in(msg.data.padId).json.send(msg); // broadcast to all clients on this pad + } + + cb(null, {}); +} + + /** * Handles a custom message (sent via HTTP API request) * From 5639bde5ad0c65edd6d513cd4c38da8d2218d654 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 12 Mar 2013 17:34:15 +0000 Subject: [PATCH 2/2] add authorId to chat and userlist, possibly privacy/security issue? --- src/static/js/chat.js | 2 +- src/static/js/pad_userlist.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 2dff2edf3..83a487dee 100644 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -111,7 +111,7 @@ var chat = (function() var authorName = msg.userName == null ? _('pad.userlist.unnamed') : padutils.escapeHtml(msg.userName); - var html = "

" + authorName + ":" + timeStr + " " + text + "

"; + var html = "

" + authorName + ":" + timeStr + " " + text + "

"; if(isHistoryAdd) $(html).insertAfter('#chatloadmessagesbutton'); else diff --git a/src/static/js/pad_userlist.js b/src/static/js/pad_userlist.js index 962595d2b..c8f8e2c9e 100644 --- a/src/static/js/pad_userlist.js +++ b/src/static/js/pad_userlist.js @@ -119,9 +119,9 @@ var paduserlist = (function() return ['
 
', '', nameHtml, '', '', padutils.escapeHtml(data.activity), ''].join(''); } - function getRowHtml(id, innerHtml) + function getRowHtml(id, innerHtml, authorId) { - return '' + innerHtml + ''; + return '' + innerHtml + ''; } function rowNode(row) @@ -191,18 +191,20 @@ var paduserlist = (function() domId: domId, animationPower: animationPower }; + var authorId = data.id; + handleRowData(row); rowsPresent.splice(position, 0, row); var tr; if (animationPower == 0) { - tr = $(getRowHtml(domId, getUserRowHtml(getAnimationHeight(0), data))); + tr = $(getRowHtml(domId, getUserRowHtml(getAnimationHeight(0), data), authorId)); row.animationStep = 0; } else { rowsFadingIn.push(row); - tr = $(getRowHtml(domId, getEmptyRowHtml(getAnimationHeight(ANIMATION_START)))); + tr = $(getRowHtml(domId, getEmptyRowHtml(getAnimationHeight(ANIMATION_START)), authorId)); } handleRowNode(tr, data); if (position == 0)