mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-20 14:39:53 +01:00
Cleaning up switchToPad functionality so that we only need one call to the server("SWITCH_TO_PAD") instead of two (cleaning session info and client ready).
Also Clearing chat messages when switchToPad is called in pad.js instead of having the server tell the client to clear the chat messages.
This commit is contained in:
parent
070ba40f4f
commit
7861cae763
4 changed files with 32 additions and 50 deletions
|
@ -217,8 +217,8 @@ exports.handleMessage = function(client, message)
|
||||||
} else {
|
} else {
|
||||||
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
messageLogger.warn("Dropped message, unknown COLLABROOM Data Type " + message.data.type);
|
||||||
}
|
}
|
||||||
} else if(message.type == "CLEAR_SESSION_INFO") {
|
} else if(message.type == "SWITCH_TO_PAD") {
|
||||||
handleClearSessionInfo(client, message);
|
handleSwitchToPad(client, message);
|
||||||
} else {
|
} else {
|
||||||
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
messageLogger.warn("Dropped message, unknown Message Type " + message.type);
|
||||||
}
|
}
|
||||||
|
@ -232,18 +232,7 @@ exports.handleMessage = function(client, message)
|
||||||
{
|
{
|
||||||
// client tried to auth for the first time (first msg from the client)
|
// client tried to auth for the first time (first msg from the client)
|
||||||
if(message.type == "CLIENT_READY") {
|
if(message.type == "CLIENT_READY") {
|
||||||
// Remember this information since we won't
|
createSessionInfo(client, message);
|
||||||
// have the cookie in further socket.io messages.
|
|
||||||
// This information will be used to check if
|
|
||||||
// the sessionId of this connection is still valid
|
|
||||||
// since it could have been deleted by the API.
|
|
||||||
sessioninfos[client.id].auth =
|
|
||||||
{
|
|
||||||
sessionID: message.sessionID,
|
|
||||||
padID: message.padId,
|
|
||||||
token : message.token,
|
|
||||||
password: message.password
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: message.sessionID is an entirely different kind of
|
// Note: message.sessionID is an entirely different kind of
|
||||||
|
@ -874,18 +863,8 @@ function _correctMarkersInPad(atext, apool) {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleClearSessionInfo(client, message)
|
function handleSwitchToPad(client, message)
|
||||||
{
|
{
|
||||||
var infoMsg = {
|
|
||||||
type: "COLLABROOM",
|
|
||||||
data: {
|
|
||||||
type: "CLEAR_CHAT_MESSAGES"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// send the messages back to the client to clear the chat messages
|
|
||||||
client.json.send(infoMsg);
|
|
||||||
|
|
||||||
// clear the session and leave the room
|
// clear the session and leave the room
|
||||||
var currentSession = sessioninfos[client.id];
|
var currentSession = sessioninfos[client.id];
|
||||||
var padId = currentSession.padId;
|
var padId = currentSession.padId;
|
||||||
|
@ -898,6 +877,26 @@ function handleClearSessionInfo(client, message)
|
||||||
roomClients[i].leave(padId);
|
roomClients[i].leave(padId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// start up the new pad
|
||||||
|
createSessionInfo(client, message);
|
||||||
|
handleClientReady(client, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createSessionInfo(client, message)
|
||||||
|
{
|
||||||
|
// Remember this information since we won't
|
||||||
|
// have the cookie in further socket.io messages.
|
||||||
|
// This information will be used to check if
|
||||||
|
// the sessionId of this connection is still valid
|
||||||
|
// since it could have been deleted by the API.
|
||||||
|
sessioninfos[client.id].auth =
|
||||||
|
{
|
||||||
|
sessionID: message.sessionID,
|
||||||
|
padID: message.padId,
|
||||||
|
token : message.token,
|
||||||
|
password: message.password
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -79,10 +79,6 @@ var chat = (function()
|
||||||
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
|
this._pad.collabClient.sendMessage({"type": "CHAT_MESSAGE", "text": text});
|
||||||
$("#chatinput").val("");
|
$("#chatinput").val("");
|
||||||
},
|
},
|
||||||
clearChatMessages: function()
|
|
||||||
{
|
|
||||||
$('#chattext p').remove();
|
|
||||||
},
|
|
||||||
addMessage: function(msg, increment, isHistoryAdd)
|
addMessage: function(msg, increment, isHistoryAdd)
|
||||||
{
|
{
|
||||||
//correct the time
|
//correct the time
|
||||||
|
|
|
@ -388,10 +388,6 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
{
|
{
|
||||||
chat.addMessage(msg, true, false);
|
chat.addMessage(msg, true, false);
|
||||||
}
|
}
|
||||||
else if (msg.type == "CLEAR_CHAT_MESSAGES")
|
|
||||||
{
|
|
||||||
chat.clearChatMessages();
|
|
||||||
}
|
|
||||||
else if (msg.type == "CHAT_MESSAGES")
|
else if (msg.type == "CHAT_MESSAGES")
|
||||||
{
|
{
|
||||||
for(var i = msg.messages.length - 1; i >= 0; i--)
|
for(var i = msg.messages.length - 1; i >= 0; i--)
|
||||||
|
|
|
@ -162,19 +162,9 @@ function savePassword()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendClearSessionInfo()
|
function sendClientReady(isReconnect, messageType)
|
||||||
{
|
|
||||||
var msg = {
|
|
||||||
"component": "pad",
|
|
||||||
"type": "CLEAR_SESSION_INFO",
|
|
||||||
"protocolVersion": 2
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.json.send(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendClientReady(isReconnect)
|
|
||||||
{
|
{
|
||||||
|
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||||
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
|
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf("/") + 1);
|
||||||
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
||||||
|
|
||||||
|
@ -197,7 +187,7 @@ function sendClientReady(isReconnect)
|
||||||
|
|
||||||
var msg = {
|
var msg = {
|
||||||
"component": "pad",
|
"component": "pad",
|
||||||
"type": "CLIENT_READY",
|
"type": messageType,
|
||||||
"padId": padId,
|
"padId": padId,
|
||||||
"sessionID": sessionID,
|
"sessionID": sessionID,
|
||||||
"password": password,
|
"password": password,
|
||||||
|
@ -442,9 +432,10 @@ var pad = {
|
||||||
{
|
{
|
||||||
return pad.myUserInfo.name;
|
return pad.myUserInfo.name;
|
||||||
},
|
},
|
||||||
sendClientReady: function(isReconnect)
|
sendClientReady: function(isReconnect, messageType)
|
||||||
{
|
{
|
||||||
sendClientReady(isReconnect);
|
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||||
|
sendClientReady(isReconnect, messageType);
|
||||||
},
|
},
|
||||||
switchToPad: function(padId)
|
switchToPad: function(padId)
|
||||||
{
|
{
|
||||||
|
@ -455,10 +446,10 @@ var pad = {
|
||||||
|
|
||||||
if(window.history && window.history.pushState)
|
if(window.history && window.history.pushState)
|
||||||
{
|
{
|
||||||
|
$('#chattext p').remove(); //clear the chat messages
|
||||||
window.history.pushState("", "", newHref);
|
window.history.pushState("", "", newHref);
|
||||||
sendClearSessionInfo();
|
|
||||||
receivedClientVars = false;
|
receivedClientVars = false;
|
||||||
sendClientReady(false);
|
sendClientReady(false, 'SWITCH_TO_PAD');
|
||||||
}
|
}
|
||||||
else // fallback
|
else // fallback
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue