From 6d1e06cca3f0ea63b73815b4ddc74bb1cd9e6544 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 26 Oct 2016 15:02:30 +0200 Subject: [PATCH] Add notifications when a user joins or leaves the channel --- customize.dist/translations/messages.fr.js | 13 +- customize.dist/translations/messages.js | 13 +- www/code/main.js | 39 ++--- www/common/toolbar.js | 168 ++++++++++++++------- www/pad/main.js | 41 ++--- www/slide/main.js | 37 ++--- 6 files changed, 191 insertions(+), 120 deletions(-) diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 299bcd5b3..44a35ea05 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -28,8 +28,9 @@ define(function () { out.yourself = "Vous-même"; out.anonymousUsers = "utilisateurs anonymes"; out.anonymousUser = "utilisateur anonyme"; - out.share = "Partage"; - out.users = "Utilisateurs"; + out.shareView = "URL de lecture seule"; + out.shareEdit = "URL d'édition"; + out.users = "Éditeurs"; out.greenLight = "Tout fonctionne bien"; out.orangeLight = "Votre connexion est lente, ce qui réduit la qualité de l'éditeur"; @@ -59,7 +60,7 @@ define(function () { out.forgetButtonTitle = 'Enlever ce document de la liste en page d\'accueil'; out.forgetPrompt = 'Cliquer sur OK supprimera l\'URL de ce document de la mémoire de votre navigateur (localStorage), êtes-vous sûr ?'; - out.shareButton = 'PARTAGER'; + out.shareButton = 'Partager'; out.shareButtonTitle = "Copier l'URL dans le presse-papiers"; out.shareSuccess = 'URL copiée dans le presse-papiers'; out.shareFailed = "Échec de la copie de l'URL dans le presse-papiers"; @@ -84,13 +85,17 @@ define(function () { out.openReadOnly = "Ouvrir dans un nouvel onglet"; out.editing = "éditeur(s)"; out.viewing = "lecteur(s)"; - out.editShare = "Partager l'URL"; + out.editShare = "Partager l'URL d'édition"; out.editShareTitle = "Copier l'URL d'édition dans le presse-papiers"; out.viewShare = "Partager l'URL de lecture"; out.viewShareTitle = "Copier l'URL d'accès en lecture seule dans le presse-papiers"; out.viewOpen = "Voir dans un nouvel onglet"; out.viewOpenTitle = "Ouvrir le document en lecture seule dans un nouvel onglet"; + out.notifyJoined = "{0} a rejoint la session collaborative"; + out.notifyRenamed = "{0} a changé son nom en {1}"; + out.notifyLeft = "{0} a quitté la session collaborative"; + out.disconnectAlert = 'Perte de la connexion au réseau !'; out.tryIt = 'Essayez-le !'; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index 69cb4a4e7..89ec12f95 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -28,8 +28,9 @@ define(function () { out.yourself = "Yourself"; out.anonymousUsers = "anonymous users"; out.anonymousUser = "anonymous user"; - out.share = "Share"; - out.users = "Users"; + out.shareView = "Read-only URL"; + out.shareEdit = "Edit URL"; + out.users = "Editing users"; out.greenLight = "Everything is working fine"; out.orangeLight = "Your slow connection may impact your experience"; @@ -59,7 +60,7 @@ define(function () { out.forgetButtonTitle = 'Remove this document from your home page listings'; out.forgetPrompt = 'Clicking OK will remove the URL for this pad from localStorage, are you sure?'; - out.shareButton = 'SHARE'; + out.shareButton = 'Share'; out.shareButtonTitle = "Copy URL to clipboard"; out.shareSuccess = 'Copied URL to clipboard'; out.shareFailed = "Failed to copy URL to clipboard"; @@ -84,13 +85,17 @@ define(function () { out.openReadOnly = "Open in a new tab"; out.editing = "editor(s)"; out.viewing = "viewer(s)"; - out.editShare = "Share"; + out.editShare = "Share edit URL"; out.editShareTitle = "Copy the edit URL to clipboard"; out.viewShare = "Share view URL"; out.viewShareTitle = "Copy the read-only URL to clipboard"; out.viewOpen = "View in new tab"; out.viewOpenTitle = "Open the document in read-only mode in a new tab"; + out.notifyJoined = "{0} has joined the collaborative session"; + out.notifyRenamed = "{0} is now known as {1}"; + out.notifyLeft = "{0} has left the collaborative session"; + out.disconnectAlert = 'Network connection lost!'; out.tryIt = 'Try it out!'; diff --git a/www/code/main.js b/www/code/main.js index 0483c1bf6..a5d7af164 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -115,21 +115,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); } }; @@ -168,7 +169,7 @@ define([ var obj = { content: textValue, metadata: { - users: userList, + users: userData, defaultTitle: defaultName } }; @@ -206,7 +207,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"); @@ -347,7 +348,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); @@ -359,9 +360,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: { @@ -372,7 +373,7 @@ define([ common: Cryptpad }; if (readOnly) {delete config.changeNameID; } - toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, config); + toolbar = module.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); @@ -573,16 +574,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(); }); }; diff --git a/www/common/toolbar.js b/www/common/toolbar.js index 26ade0842..1a5b9bde1 100644 --- a/www/common/toolbar.js +++ b/www/common/toolbar.js @@ -105,60 +105,61 @@ define([ 'class': USERBUTTONS_CONTAINER_CLS }).appendTo($userlistElement); + var createHandler = function ($elmt) { + return function () { + if ($elmt.is(':visible')) { + $elmt.hide(); + return; + } + $userlistElement.find('.' + DROPDOWN_CLS).hide(); + $elmt.show(); + }; + }; + + var fa_caretdown = ''; + + // User list button var $editIcon = $('