', {'class': EDITSHARE_CLS}).append($shareTitle);
- var $dropdownShareP2 = $('
', {'class': VIEWSHARE_CLS}).append($shareTitle2);
+ var $dropdownSharePView = $('
', {'class': VIEWSHARE_CLS}).append($shareTitleView);
var $dropdownShareContainer = $('
', {'class': DROPDOWN_CONTAINER_CLS});
var $dropdownShare = $('
', {
id: "cryptpad-dropdown-share",
'class': DROPDOWN_CLS
- }).append($dropdownShareP).append($dropdownShareP2);
-
- var createHandler = function ($elmt) {
- return function () {
- if ($elmt.is(':visible')) {
- $elmt.hide();
- return;
- }
- $userlistElement.find('.' + DROPDOWN_CLS).hide();
- $elmt.show();
- };
- };
- $editIcon.click(createHandler($dropdownEdit));
- $editIconSmall.click(createHandler($dropdownEdit));
+ });
+ if (readOnly !== 1) {
+ // Hide the "Share edit URL" section when in read-only mode
+ $dropdownShare.append($dropdownShareP);
+ }
+ $dropdownShare.append($dropdownSharePView);
$shareIcon.click(createHandler($dropdownShare));
$shareIconSmall.click(createHandler($dropdownShare));
-
- $dropdownEditContainer.append($editIcon).append($editIconSmall).append($dropdownEdit);
$dropdownShareContainer.append($shareIcon).append($shareIconSmall).append($dropdownShare);
-
- $listElement.append($dropdownEditContainer);
-/* if (readOnly !== -1) {*/
- $listElement.append($dropdownShareContainer);
- /* }
-*/
-
+ $listElement.append($dropdownShareContainer);
};
var createUserList = function ($container, readOnly) {
@@ -206,27 +207,26 @@ define([
}
$stateElement.text('');
- // Make sure the user block elements are displayed
+ // Make sure the elements are displayed
var $userButtons = $(userlistElement).find("#userButtons");
$userButtons.show();
- var $userElement = $userAdminElement.find('.' + USERNAME_CLS);
- $userElement.show();
var numberOfUsers = userList.length;
// If we are using old pads (readonly unavailable), only editing users are in userList.
// With new pads, we also have readonly users in userList, so we have to intersect with
// the userData to have only the editing users. We can't use userData directly since it
- // contains data about users that have already left the channel.
+ // may contain data about users that have already left the channel.
userList = readOnly === -1 ? userList : arrayIntersect(userList, Object.keys(userData));
- var numberOfViewUsers = numberOfUsers - userList.length;
+ var numberOfEditUsers = userList.length;
+ var numberOfViewUsers = numberOfUsers - numberOfEditUsers;
// Names of editing users
var editUsersNames = getOtherUsers(myUserName, userList, userData);
// Number of anonymous editing users
- var anonymous = numberOfUsers - editUsersNames.length;
+ var anonymous = numberOfEditUsers - editUsersNames.length;
// Update the userlist
var editUsersList = '';
@@ -249,11 +249,12 @@ define([
var fa_caretdown = '';
var fa_editusers = '';
var fa_viewusers = '';
- $userButtons.find('.userlist.edit').html(fa_editusers + ' ' + userList.length + ' ' + Messages.editing + ', ' + fa_viewusers + ' ' + numberOfViewUsers + ' ' + Messages.viewing + ' ' + fa_caretdown);
- $userButtons.find('.userlist.edit.small').html(fa_editusers + ' ' + userList.length + ', ' + fa_viewusers + ' ' + numberOfViewUsers + ' ' + fa_caretdown);
- $userButtons.find('.userlist.share').html('SHARE ' + fa_caretdown);
- $userButtons.find('.userlist.share.small').html('SHARE SMALL ' + fa_caretdown);
+ $userButtons.find('.userlist.edit').html(fa_editusers + ' ' + userList.length + ' ' + Messages.editing + ' ' + fa_viewusers + ' ' + numberOfViewUsers + ' ' + Messages.viewing + ' ' + fa_caretdown);
+ $userButtons.find('.userlist.edit.small').html(fa_editusers + ' ' + userList.length + ' ' + fa_viewusers + ' ' + numberOfViewUsers + ' ' + fa_caretdown);
+ // Change username button
+ var $userElement = $userAdminElement.find('.' + USERNAME_CLS);
+ $userElement.show();
if (readOnly === 1) {
$userElement.html('' + Messages.readonly + '');
}
@@ -263,7 +264,6 @@ define([
if (!name) {
name = Messages.anonymous;
}
- console.log($userElement);
$userElement.find("button").show();
$userElement.find("button").html(icon + ' ' + name);
}
@@ -473,15 +473,71 @@ define([
}
}
- userList.onChange = function(newUserData) {
- var users = userList.users;
- if (users.indexOf(myUserName) !== -1) { connected = true; }
- if (!connected) { return; }
- if(newUserData) { // Someone has changed his name/color
- userData = newUserData;
- }
- updateUserList(myUserName, userListElement, users, userData, readOnly, $stateElement, $userAdminElement);
- };
+ // Update user list
+ userList.change.push(function (newUserData) {
+ var users = userList.users;
+ if (users.indexOf(myUserName) !== -1) { connected = true; }
+ if (!connected) { return; }
+ /*if (newUserData) { // Someone has changed his name/color
+ userData = newUserData;
+ }*/
+ updateUserList(myUserName, userListElement, users, userData, readOnly, $stateElement, $userAdminElement);
+ });
+ // Display notifications when users are joining/leaving the session
+ var oldUserData;
+ if (typeof Cryptpad !== "undefined") {
+ var notify = function(type, name, oldname) {
+ // type : 1 (+1 user), 0 (rename existing user), -1 (-1 user)
+ if (typeof name === "undefined") { return; }
+ name = (name === "") ? Messages.anonymous : name;
+ switch(type) {
+ case 1:
+ Cryptpad.log(Messages._getKey("notifyJoined", [name]));
+ break;
+ case 0:
+ oldname = (oldname === "") ? Messages.anonymous : oldname;
+ Cryptpad.log(Messages._getKey("notifyRenamed", [oldname, name]));
+ break;
+ case -1:
+ Cryptpad.log(Messages._getKey("notifyLeft", [name]));
+ break;
+ default:
+ console.log("Invalid type of notification");
+ break;
+ }
+ };
+ userList.change.push(function (newdata) {
+ // Notify for disconnected users
+ if (typeof oldUserData !== "undefined") {
+ for (var u in oldUserData) {
+ if (userList.users.indexOf(u) === -1) {
+ notify(-1, oldUserData[u].name);
+ delete oldUserData[u];
+ }
+ }
+ }
+ // Update the "oldUserData" object and notify for new users and names changed
+ if (typeof newdata === "undefined") { return; }
+ if (typeof oldUserData === "undefined") {
+ oldUserData = JSON.parse(JSON.stringify(newdata));
+ return;
+ }
+ if (readOnly === 0 && !oldUserData[myUserName]) {
+ oldUserData = JSON.parse(JSON.stringify(newdata));
+ return;
+ }
+ for (var k in newdata) {
+ if (k !== myUserName && userList.users.indexOf(k) !== -1) {
+ if (typeof oldUserData[k] === "undefined") {
+ notify(1, newdata[k].name);
+ } else if (oldUserData[k].name !== newdata[k].name) {
+ notify(0, newdata[k].name, oldUserData[k].name);
+ }
+ }
+ }
+ oldUserData = JSON.parse(JSON.stringify(newdata));
+ });
+ }
var ks = function () {
if (connected) { kickSpinner(spinner, false); }
diff --git a/www/pad/main.js b/www/pad/main.js
index 6b3845ee6..96489bc7a 100644
--- a/www/pad/main.js
+++ b/www/pad/main.js
@@ -253,19 +253,22 @@ define([
};
var initializing = true;
- var userList = module.userList = {}; // List of pretty names for all users (mapped with their ID)
- var toolbarList; // List of users still connected to the channel (server IDs)
- var addToUserList = function(data) {
+ var userData = module.userData = {}; // List of pretty names for all users (mapped with their ID)
+ var userList; // List of users still connected to the channel (server IDs)
+ var addToUserData = function(data) {
var users = module.users;
+ for (var attrname in data) { userData[attrname] = data[attrname]; }
+
if (users && users.length) {
- for (var userKey in userList) {
- if (users.indexOf(userKey) === -1) { delete userList[userKey]; }
+ for (var userKey in userData) {
+ console.log(userKey);
+ if (users.indexOf(userKey) === -1) { console.log('delete'); delete userData[userKey]; }
}
}
- for (var attrname in data) { userList[attrname] = data[attrname]; }
- if(toolbarList && typeof toolbarList.onChange === "function") {
- toolbarList.onChange(userList);
+ if(userList && typeof userList.onChange === "function") {
+ console.log(JSON.stringify(userData));
+ userList.onChange(userData);
}
};
@@ -293,7 +296,7 @@ define([
myData[myID] = {
name: myUserName
};
- addToUserList(myData);
+ addToUserData(myData);
Cryptpad.setAttribute('username', newName, function (err, data) {
if (err) {
console.error("Couldn't set username");
@@ -345,7 +348,7 @@ define([
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
hjson[3] = {
metadata: {
- users: userList,
+ users: userData,
defaultTitle: defaultName
}
};
@@ -421,7 +424,7 @@ define([
if (peerMetadata.metadata.users) {
var userData = peerMetadata.metadata.users;
// Update the local user data
- addToUserList(userData);
+ addToUserData(userData);
}
if (peerMetadata.metadata.defaultTitle) {
updateDefaultTitle(peerMetadata.metadata.defaultTitle);
@@ -530,9 +533,9 @@ define([
};
var onInit = realtimeOptions.onInit = function (info) {
- toolbarList = info.userList;
+ userList = info.userList;
var config = {
- userData: userList,
+ userData: userData,
readOnly: readOnly,
ifrw: ifrw,
title: {
@@ -543,7 +546,7 @@ define([
common: Cryptpad
};
if (readOnly) {delete config.changeNameID; }
- toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, config);
+ toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, config);
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
var $userBlock = $bar.find('.' + Toolbar.constants.username);
@@ -643,16 +646,16 @@ define([
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; }
- myData[myID] = {
- name: ""
- };
- addToUserList(myData);
if (typeof(lastName) === 'string' && lastName.length) {
setName(lastName);
} else {
+ myData[myID] = {
+ name: ""
+ };
+ addToUserData(myData);
+ realtimeOptions.onLocal();
module.$userNameButton.click();
}
- realtimeOptions.onLocal();
});
};
diff --git a/www/slide/main.js b/www/slide/main.js
index de07c8ff9..711280624 100644
--- a/www/slide/main.js
+++ b/www/slide/main.js
@@ -152,21 +152,22 @@ define([
editor.setOption('readOnly', !bool);
};
- var userList = module.userList = {}; // List of pretty name of all users (mapped with their server ID)
- var toolbarList; // List of users still connected to the channel (server IDs)
- var addToUserList = function(data) {
+ var userData = module.userData = {}; // List of pretty name of all users (mapped with their server ID)
+ var userList; // List of users still connected to the channel (server IDs)
+ var addToUserData = function(data) {
var users = module.users;
+ for (var attrname in data) { userData[attrname] = data[attrname]; }
+
if (users && users.length) {
- for (var userKey in userList) {
+ for (var userKey in userData) {
if (users.indexOf(userKey) === -1) {
- delete userList[userKey];
+ delete userData[userKey];
}
}
}
- for (var attrname in data) { userList[attrname] = data[attrname]; }
- if(toolbarList && typeof toolbarList.onChange === "function") {
- toolbarList.onChange(userList);
+ if(userList && typeof userList.onChange === "function") {
+ userList.onChange(userData);
}
};
@@ -208,7 +209,7 @@ define([
var obj = {
content: textValue,
metadata: {
- users: userList,
+ users: userData,
defaultTitle: defaultName
}
};
@@ -250,7 +251,7 @@ define([
myData[myID] = {
name: myUserName
};
- addToUserList(myData);
+ addToUserData(myData);
Cryptpad.setAttribute('username', myUserName, function (err, data) {
if (err) {
console.log("Couldn't set username");
@@ -384,7 +385,7 @@ define([
if (json.metadata.users) {
var userData = json.metadata.users;
// Update the local user data
- addToUserList(userData);
+ addToUserData(userData);
}
if (json.metadata.defaultTitle) {
updateDefaultTitle(json.metadata.defaultTitle);
@@ -404,9 +405,9 @@ define([
};
var onInit = config.onInit = function (info) {
- toolbarList = info.userList;
+ userList = info.userList;
var config = {
- userData: userList,
+ userData: userData,
readOnly: readOnly,
ifrw: ifrw,
title: {
@@ -672,16 +673,16 @@ define([
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; }
- myData[myID] = {
- name: ""
- };
- addToUserList(myData);
if (typeof(lastName) === 'string' && lastName.length) {
setName(lastName);
} else {
+ myData[myID] = {
+ name: ""
+ };
+ addToUserData(myData);
+ onLocal();
module.$userNameButton.click();
}
- onLocal();
});
};