mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
Merge branch 'master' of github.com:Pita/etherpad-lite into HEAD
This commit is contained in:
commit
7a10e1783a
11 changed files with 209 additions and 92 deletions
|
@ -145,7 +145,7 @@ exports.handleMessage = function(client, message)
|
|||
}
|
||||
if(!message.type)
|
||||
{
|
||||
throw "Message have no type attribute!";
|
||||
throw "Message has no type attribute!";
|
||||
}
|
||||
|
||||
//Check what type of message we get and delegate to the other methodes
|
||||
|
@ -163,6 +163,12 @@ exports.handleMessage = function(client, message)
|
|||
{
|
||||
handleUserInfoUpdate(client, message);
|
||||
}
|
||||
else if(message.type == "COLLABROOM" &&
|
||||
message.data.type == "CLIENT_MESSAGE" &&
|
||||
message.data.payload.type == "suggestUserName")
|
||||
{
|
||||
handleSuggestUserName(client, message);
|
||||
}
|
||||
//if the message type is unkown, throw an exception
|
||||
else
|
||||
{
|
||||
|
@ -170,6 +176,36 @@ exports.handleMessage = function(client, message)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a handleSuggestUserName, that means a user have suggest a userName for a other user
|
||||
* @param client the client that send this message
|
||||
* @param message the message from the client
|
||||
*/
|
||||
function handleSuggestUserName(client, message)
|
||||
{
|
||||
//check if all ok
|
||||
if(message.data.payload.newName == null)
|
||||
{
|
||||
throw "suggestUserName Message has no newName!";
|
||||
}
|
||||
if(message.data.payload.unnamedId == null)
|
||||
{
|
||||
throw "suggestUserName Message has no unnamedId!";
|
||||
}
|
||||
|
||||
var padId = session2pad[client.sessionId];
|
||||
|
||||
//search the author and send him this message
|
||||
for(var i in pad2sessions[padId])
|
||||
{
|
||||
if(sessioninfos[pad2sessions[padId][i]].author == message.data.payload.unnamedId)
|
||||
{
|
||||
socketio.clients[pad2sessions[padId][i]].send(message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a USERINFO_UPDATE, that means that a user have changed his color or name. Anyway, we get both informations
|
||||
* @param client the client that send this message
|
||||
|
@ -180,7 +216,7 @@ function handleUserInfoUpdate(client, message)
|
|||
//check if all ok
|
||||
if(message.data.userInfo.colorId == null)
|
||||
{
|
||||
throw "USERINFO_UPDATE Message have no colorId!";
|
||||
throw "USERINFO_UPDATE Message has no colorId!";
|
||||
}
|
||||
|
||||
//Find out the author name of this session
|
||||
|
@ -202,7 +238,7 @@ function handleUserInfoUpdate(client, message)
|
|||
message.data.type = "USER_NEWINFO";
|
||||
|
||||
//Send the other clients on the pad the update message
|
||||
for(i in pad2sessions[padId])
|
||||
for(var i in pad2sessions[padId])
|
||||
{
|
||||
if(pad2sessions[padId][i] != client.id)
|
||||
{
|
||||
|
@ -228,15 +264,15 @@ function handleUserChanges(client, message)
|
|||
//check if all ok
|
||||
if(message.data.baseRev == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no baseRev!";
|
||||
throw "USER_CHANGES Message has no baseRev!";
|
||||
}
|
||||
if(message.data.apool == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no apool!";
|
||||
throw "USER_CHANGES Message has no apool!";
|
||||
}
|
||||
if(message.data.changeset == null)
|
||||
{
|
||||
throw "USER_CHANGES Message have no changeset!";
|
||||
throw "USER_CHANGES Message has no changeset!";
|
||||
}
|
||||
|
||||
//get all Vars we need
|
||||
|
@ -451,25 +487,26 @@ function handleClientReady(client, message)
|
|||
//check if all ok
|
||||
if(!message.token)
|
||||
{
|
||||
throw "CLIENT_READY Message have no token!";
|
||||
throw "CLIENT_READY Message has no token!";
|
||||
}
|
||||
if(!message.padId)
|
||||
{
|
||||
throw "CLIENT_READY Message have no padId!";
|
||||
throw "CLIENT_READY Message has no padId!";
|
||||
}
|
||||
if(!message.protocolVersion)
|
||||
{
|
||||
throw "CLIENT_READY Message have no protocolVersion!";
|
||||
throw "CLIENT_READY Message has no protocolVersion!";
|
||||
}
|
||||
if(message.protocolVersion != 2)
|
||||
{
|
||||
throw "CLIENT_READY Message have a unkown protocolVersion '" + message.protocolVersion + "'!";
|
||||
throw "CLIENT_READY Message has a unkown protocolVersion '" + message.protocolVersion + "'!";
|
||||
}
|
||||
|
||||
var author;
|
||||
var authorName;
|
||||
var authorColorId;
|
||||
var pad;
|
||||
var historicalAuthorData = {};
|
||||
|
||||
async.series([
|
||||
//get all authordata of this new user
|
||||
|
@ -511,6 +548,20 @@ function handleClientReady(client, message)
|
|||
});
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
var authors = pad.getAllAuthors();
|
||||
|
||||
//get all author data out of the database
|
||||
async.forEach(authors, function(authorId, callback)
|
||||
{
|
||||
authorManager.getAuthor(authorId, function(err, author)
|
||||
{
|
||||
historicalAuthorData[authorId] = author;
|
||||
callback(err);
|
||||
});
|
||||
}, callback);
|
||||
},
|
||||
function(callback)
|
||||
{
|
||||
//Check if this author is already on the pad, if yes, kick the other sessions!
|
||||
if(pad2sessions[message.padId])
|
||||
|
@ -556,7 +607,7 @@ function handleClientReady(client, message)
|
|||
"clientIp": (client.request && client.request.connection) ? client.request.connection.remoteAddress : "127.0.0.1",
|
||||
//"clientAgent": "Anonymous Agent",
|
||||
"padId": message.padId,
|
||||
"historicalAuthorData": {},
|
||||
"historicalAuthorData": historicalAuthorData,
|
||||
"apool": apool,
|
||||
"rev": pad.getHeadRevisionNumber(),
|
||||
"globalPadId": message.padId
|
||||
|
@ -570,7 +621,7 @@ function handleClientReady(client, message)
|
|||
"opts": {},
|
||||
"chatHistory": {
|
||||
"start": 0,
|
||||
"historicalAuthorData": {},
|
||||
"historicalAuthorData": historicalAuthorData,
|
||||
"end": 0,
|
||||
"lines": []
|
||||
},
|
||||
|
@ -592,16 +643,6 @@ function handleClientReady(client, message)
|
|||
clientVars.userName = authorName;
|
||||
}
|
||||
|
||||
//Add all authors that worked on this pad, to the historicalAuthorData on clientVars
|
||||
var allAuthors = pad.getAllAuthors();
|
||||
for(i in allAuthors)
|
||||
{
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]] = {};
|
||||
if(authorName != null)
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]].name = authorName;
|
||||
clientVars.collab_client_vars.historicalAuthorData[allAuthors[i]].colorId = authorColorId;
|
||||
}
|
||||
|
||||
//Send the clientVars to the Client
|
||||
client.json.send(clientVars);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue