Skip to content

Commit dbc777d

Browse files
committed
Merge pull request #2871 from tiblu/pad_userlist_add_usersOnline_fix_bug_in_users
pad_userlist.js: BUGFIX: users() returning duplicates on several calls. FEATURE: usersOnline() returns only online users
2 parents 239f517 + ccbcf0d commit dbc777d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/static/js/collab_client.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This code is mostly from the old Etherpad. Please help us to comment this code.
2+
* This code is mostly from the old Etherpad. Please help us to comment this code.
33
* This helps other people to understand this code better and helps them to improve it.
44
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
55
*/
@@ -351,7 +351,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
351351
msg.userInfo.colorId = initialUserInfo.globalUserColor;
352352
}
353353

354-
354+
355355
if (userSet[id])
356356
{
357357
userSet[id] = userInfo;
@@ -405,7 +405,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
405405
$("#chatloadmessagesball").css("display", "none");
406406

407407
// there are less than 100 messages or we reached the top
408-
if(chat.historyPointer <= 0)
408+
if(chat.historyPointer <= 0)
409409
$("#chatloadmessagesbutton").css("display", "none");
410410
else // there are still more messages, re-show the load-button
411411
$("#chatloadmessagesbutton").css("display", "block");
@@ -414,6 +414,12 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
414414
{
415415
callbacks.onServerMessage(msg.payload);
416416
}
417+
418+
//HACKISH: User messages do not have "payload" but "userInfo", so that all "handleClientMessage_USER_" hooks would work, populate payload
419+
//FIXME: USER_* messages to have "payload" property instead of "userInfo", seems like a quite a big work
420+
if(msg.type.indexOf("USER_") > -1) {
421+
msg.payload = msg.userInfo;
422+
}
417423
hooks.callAll('handleClientMessage_' + msg.type, {payload: msg.payload});
418424
}
419425

@@ -441,7 +447,7 @@ function getCollabClient(ace2editor, serverVars, initialUserInfo, options, _pad)
441447
{
442448
colorId = clientVars.colorPalette[colorId];
443449
}
444-
450+
445451
var cssColor = colorId;
446452
if (inactive)
447453
{

src/static/js/pad_userlist.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,18 @@ var paduserlist = (function()
508508
});
509509
//
510510
},
511-
users: function(){
512-
// Returns an object of users who have been on this pad
513-
// Firstly we have to get live data..
514-
var userList = otherUsersInfo;
511+
usersOnline: function()
512+
{
513+
// Returns an object of users who are currently online on this pad
514+
var userList = [].concat(otherUsersInfo); // Make a copy of the otherUsersInfo, otherwise every call to users modifies the referenced array
515515
// Now we need to add ourselves..
516516
userList.push(myUserInfo);
517+
return userList;
518+
},
519+
users: function(){
520+
// Returns an object of users who have been on this pad
521+
var userList = self.usersOnline();
522+
517523
// Now we add historical authors
518524
var historical = clientVars.collab_client_vars.historicalAuthorData;
519525
for (var key in historical){
@@ -528,7 +534,6 @@ var paduserlist = (function()
528534
if(exists === false){
529535
userList.push(historical[key]);
530536
}
531-
532537
}
533538
return userList;
534539
},

0 commit comments

Comments
 (0)