mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
expose method for getting a full user list on the client including historical data
This commit is contained in:
parent
64034ee1c6
commit
e9d8c3b53a
3 changed files with 77 additions and 10 deletions
|
@ -3731,32 +3731,71 @@ function Ace2Inner(){
|
||||||
var apool = rep.apool;
|
var apool = rep.apool;
|
||||||
|
|
||||||
// TODO: support selection ranges
|
// TODO: support selection ranges
|
||||||
// TODO: Support multiple authors
|
|
||||||
// TODO: Still work when authorship colors have been cleared
|
// TODO: Still work when authorship colors have been cleared
|
||||||
// TODO: i18n
|
// TODO: i18n
|
||||||
// TODO: There appears to be a race condition or so.
|
// TODO: There appears to be a race condition or so.
|
||||||
|
|
||||||
var author = null;
|
var author = null;
|
||||||
if (alineAttrs) {
|
if (alineAttrs) {
|
||||||
|
var authors = [];
|
||||||
|
var authorNames = [];
|
||||||
var opIter = Changeset.opIterator(alineAttrs);
|
var opIter = Changeset.opIterator(alineAttrs);
|
||||||
if (opIter.hasNext()) {
|
|
||||||
|
while (opIter.hasNext()){
|
||||||
var op = opIter.next();
|
var op = opIter.next();
|
||||||
authorId = Changeset.opAttributeValue(op, 'author', apool);
|
authorId = Changeset.opAttributeValue(op, 'author', apool);
|
||||||
|
|
||||||
|
// Only push unique authors and ones with values
|
||||||
|
if(authors.indexOf(authorId) === -1 && authorId !== ""){
|
||||||
|
authors.push(authorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// No author information is available IE on a new pad.
|
||||||
|
if(authors.length === 0){
|
||||||
|
var authorString = "No author information is available";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// Known authors info, both current and historical
|
||||||
|
var padAuthors = parent.parent.pad.userList();
|
||||||
|
var authorObj = {};
|
||||||
|
authors.forEach(function(authorId){
|
||||||
|
padAuthors.forEach(function(padAuthor){
|
||||||
|
// If the person doing the lookup is the author..
|
||||||
|
if(padAuthor.userId === authorId){
|
||||||
|
if(parent.parent.clientVars.userId === authorId){
|
||||||
|
authorObj = {
|
||||||
|
name: "Me"
|
||||||
}
|
}
|
||||||
if(authorId.length === 0){
|
|
||||||
author = "not available";
|
|
||||||
}else{
|
}else{
|
||||||
var authorObj = parent.parent.clientVars.collab_client_vars.historicalAuthorData[authorId];
|
authorObj = padAuthor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(!authorObj){
|
||||||
|
author = "Unknown";
|
||||||
|
return;
|
||||||
|
}
|
||||||
author = authorObj.name;
|
author = authorObj.name;
|
||||||
if(author === "") author = "not available";
|
if(!author) author = "Unknown";
|
||||||
|
authorNames.push(author);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if(authors.length === 1){
|
||||||
|
var authorString = "The author of this line is " + authorNames;
|
||||||
|
}
|
||||||
|
if(authors.length > 1){
|
||||||
|
var authorString = "The authors of this line are " + authorNames.join(" & ");
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.parent.$.gritter.add({
|
parent.parent.$.gritter.add({
|
||||||
// (string | mandatory) the heading of the notification
|
// (string | mandatory) the heading of the notification
|
||||||
title: 'Authors',
|
title: 'Line Authors',
|
||||||
// (string | mandatory) the text inside the notification
|
// (string | mandatory) the text inside the notification
|
||||||
text: 'The author of this line is ' + author,
|
text: authorString,
|
||||||
// (bool | optional) if you want it to fade out on its own or just sit there
|
// (bool | optional) if you want it to fade out on its own or just sit there
|
||||||
sticky: false,
|
sticky: false,
|
||||||
// (int | optional) the time you want it to be alive for before fading out
|
// (int | optional) the time you want it to be alive for before fading out
|
||||||
|
|
|
@ -433,6 +433,10 @@ var pad = {
|
||||||
{
|
{
|
||||||
return pad.myUserInfo.name;
|
return pad.myUserInfo.name;
|
||||||
},
|
},
|
||||||
|
userList: function()
|
||||||
|
{
|
||||||
|
return paduserlist.users();
|
||||||
|
},
|
||||||
sendClientReady: function(isReconnect, messageType)
|
sendClientReady: function(isReconnect, messageType)
|
||||||
{
|
{
|
||||||
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||||
|
|
|
@ -508,6 +508,30 @@ var paduserlist = (function()
|
||||||
});
|
});
|
||||||
//
|
//
|
||||||
},
|
},
|
||||||
|
users: function(){
|
||||||
|
// Returns an object of users who have been on this pad
|
||||||
|
// Firstly we have to get live data..
|
||||||
|
var userList = otherUsersInfo;
|
||||||
|
// Now we need to add ourselves..
|
||||||
|
userList.push(myUserInfo);
|
||||||
|
// Now we add historical authors
|
||||||
|
var historical = clientVars.collab_client_vars.historicalAuthorData;
|
||||||
|
for (var key in historical){
|
||||||
|
var userId = historical[key].userId;
|
||||||
|
// Check we don't already have this author in our array
|
||||||
|
var exists = false;
|
||||||
|
|
||||||
|
userList.forEach(function(user){
|
||||||
|
if(user.userId === userId) exists = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if(exists === false){
|
||||||
|
userList.push(historical[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return userList;
|
||||||
|
},
|
||||||
setMyUserInfo: function(info)
|
setMyUserInfo: function(info)
|
||||||
{
|
{
|
||||||
//translate the colorId
|
//translate the colorId
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue