Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
ansuz 8 years ago
commit 36ab38f3ac

@ -440,11 +440,9 @@
.cryptpad-toolbar-leftside { .cryptpad-toolbar-leftside {
float: left; float: left;
margin-bottom: -1px; margin-bottom: -1px;
.cryptpad-user-list { .cryptpad-dropdown-users {
//float: right;
pre { pre {
white-space: pre; margin: 5px 0px;
margin: 0;
} }
} }
button { button {

@ -517,9 +517,8 @@
float: left; float: left;
margin-bottom: -1px; margin-bottom: -1px;
} }
.cryptpad-toolbar-leftside .cryptpad-user-list pre { .cryptpad-toolbar-leftside .cryptpad-dropdown-users pre {
white-space: pre; margin: 5px 0px;
margin: 0;
} }
.cryptpad-toolbar-leftside button { .cryptpad-toolbar-leftside button {
margin: 2px 4px 2px 0px; margin: 2px 4px 2px 0px;

@ -120,33 +120,7 @@ define([
editor.setOption('readOnly', !bool); editor.setOption('readOnly', !bool);
}; };
var userData = module.userData = {}; // List of pretty name of all users (mapped with their server ID) var UserList;
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 userData) {
if (users.indexOf(userKey) === -1) {
delete userData[userKey];
}
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
};
var myData = {};
var myUserName = ''; // My "pretty name"
var myID; // My server ID
var setMyID = function(info) {
myID = info.myID || null;
myUserName = myID;
};
var config = { var config = {
initialState: '{}', initialState: '{}',
@ -156,7 +130,6 @@ define([
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
readOnly: readOnly, readOnly: readOnly,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
setMyID: setMyID,
network: Cryptpad.getNetwork(), network: Cryptpad.getNetwork(),
transformFunction: JsonOT.validate, transformFunction: JsonOT.validate,
}; };
@ -182,7 +155,7 @@ define([
var obj = { var obj = {
content: textValue, content: textValue,
metadata: { metadata: {
users: userData, users: UserList.userData,
defaultTitle: defaultName defaultTitle: defaultName
} }
}; };
@ -213,28 +186,6 @@ define([
} }
}; };
var setName = module.setName = function (newName) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', myUserName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
onLocal();
});
};
var getHeadingText = function () { var getHeadingText = function () {
var lines = editor.getValue().split(/\n/); var lines = editor.getValue().split(/\n/);
@ -362,7 +313,7 @@ define([
if (json.metadata.users) { if (json.metadata.users) {
var userData = json.metadata.users; var userData = json.metadata.users;
// Update the local user data // Update the local user data
addToUserData(userData); UserList.addToUserData(userData);
} }
if (json.metadata.defaultTitle) { if (json.metadata.defaultTitle) {
updateDefaultTitle(json.metadata.defaultTitle); updateDefaultTitle(json.metadata.defaultTitle);
@ -378,17 +329,11 @@ define([
}; };
config.onInit = function (info) { config.onInit = function (info) {
userList = info.userList; UserList = Cryptpad.createUserList(info, config.onLocal, Cryptget, Cryptpad);
var configTb = { var configTb = {
displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userList: { userList: UserList.getToolbarConfig(),
data: userData,
list: userList,
userNetfluxId: info.myID
},
readOnly: readOnly,
ifrw: ifrw,
share: { share: {
secret: secret, secret: secret,
channel: info.channel channel: info.channel
@ -399,14 +344,15 @@ define([
suggestName: suggestName suggestName: suggestName
}, },
common: Cryptpad, common: Cryptpad,
readOnly: readOnly,
ifrw: ifrw,
realtime: info.realtime, realtime: info.realtime,
network: info.network, network: info.network,
$container: $bar $container: $bar
}; };
toolbar = module.toolbar = Toolbar.create(configTb); toolbar = module.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $rightside = toolbar.$rightside;
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
var editHash; var editHash;
if (!readOnly) { if (!readOnly) {
@ -554,8 +500,6 @@ define([
// set the hash // set the hash
if (!readOnly) { Cryptpad.replaceHash(editHash); } if (!readOnly) { Cryptpad.replaceHash(editHash); }
Cryptpad.onDisplayNameChanged(setName);
}; };
var unnotify = module.unnotify = function () { var unnotify = module.unnotify = function () {
@ -573,7 +517,6 @@ define([
}; };
config.onReady = function (info) { config.onReady = function (info) {
module.users = info.userList.users;
if (module.realtime !== info.realtime) { if (module.realtime !== info.realtime) {
var realtime = module.realtime = info.realtime; var realtime = module.realtime = info.realtime;
module.patchText = TextPatcher.create({ module.patchText = TextPatcher.create({
@ -630,33 +573,11 @@ define([
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
setEditable(true); setEditable(true);
initializing = false; initializing = false;
//Cryptpad.log("Your document is ready");
onLocal(); // push local state to avoid parse errors later. onLocal(); // push local state to avoid parse errors later.
Cryptpad.getLastName(function (err, lastName) {
if (err) {
console.log("Could not get previous name");
console.error(err);
return;
}
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; } if (readOnly) { return; }
if (typeof(lastName) === 'string') { UserList.getLastName(toolbar.$userNameButton, isNew);
setName(lastName);
} else {
myData[myID] = {
name: "",
uid: Cryptpad.getUid(),
};
addToUserData(myData);
onLocal();
module.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('code', info.realtime, Cryptget);
}
});
}; };
var cursorToPos = function(cursor, oldText) { var cursorToPos = function(cursor, oldText) {

@ -41,6 +41,7 @@ define([
var ret = {}; var ret = {};
if (!href) { return ret; } if (!href) { return ret; }
if (href.slice(-1) !== '/') { href += '/'; }
if (!/^https*:\/\//.test(href)) { if (!/^https*:\/\//.test(href)) {
var idx = href.indexOf('/#'); var idx = href.indexOf('/#');

@ -0,0 +1,97 @@
define(function () {
var module = {};
module.create = function (info, onLocal, Cryptget, Cryptpad) {
var exp = {};
var userData = exp.userData = {};
var userList = exp.userList = info.userList;
var myData = exp.myData = {};
var myUserName = exp.myUserName = info.myID;
var myNetfluxId = exp.myNetfluxId = info.myID;
var parsed = Cryptpad.parsePadUrl(window.location.href);
var appType = parsed ? parsed.type : undefined;
var users = userList.users;
var addToUserData = exp.addToUserData = function(data) {
for (var attrname in data) { userData[attrname] = data[attrname]; }
if (users && users.length) {
for (var userKey in userData) {
if (users.indexOf(userKey) === -1) {
delete userData[userKey];
}
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
};
exp.getToolbarConfig = function () {
return {
data: userData,
list: userList,
userNetfluxId: myNetfluxId
};
};
var setName = exp.setName = function (newName, cb) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(myUserNameTemp.length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myNetfluxId] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', myUserName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
if (typeof cb === "function") { cb(); }
});
};
exp.getLastName = function ($changeNameButton, isNew) {
Cryptpad.getLastName(function (err, lastName) {
if (err) {
console.log("Could not get previous name");
console.error(err);
return;
}
// Update the toolbar list:
// Add the current user in the metadata
if (typeof(lastName) === 'string') {
setName(lastName, onLocal);
} else {
myData[myNetfluxId] = {
name: "",
uid: Cryptpad.getUid(),
};
addToUserData(myData);
onLocal();
$changeNameButton.click();
}
if (isNew && appType) {
Cryptpad.selectTemplate(appType, info.realtime, Cryptget);
}
});
};
Cryptpad.onDisplayNameChanged(function (newName) {
setName(newName, onLocal);
});
return exp;
};
return module;
});

@ -7,11 +7,12 @@ define([
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-history.js', '/common/common-history.js',
'/common/common-userlist.js',
'/common/clipboard.js', '/common/clipboard.js',
'/common/pinpad.js', '/common/pinpad.js',
'/customize/application_config.js' '/customize/application_config.js'
], function ($, Config, Messages, Store, Util, Hash, UI, History, Clipboard, Pinpad, AppConfig) { ], function ($, Config, Messages, Store, Util, Hash, UI, History, UserList, Clipboard, Pinpad, AppConfig) {
/* This file exposes functionality which is specific to Cryptpad, but not to /* This file exposes functionality which is specific to Cryptpad, but not to
any particular pad type. This includes functions for committing metadata any particular pad type. This includes functions for committing metadata
@ -84,6 +85,9 @@ define([
common.findStronger = Hash.findStronger; common.findStronger = Hash.findStronger;
common.serializeHash = Hash.serializeHash; common.serializeHash = Hash.serializeHash;
// Userlist
common.createUserList = UserList.create;
// History // History
common.getHistory = function (config) { return History.create(common, config); }; common.getHistory = function (config) { return History.create(common, config); };
@ -300,10 +304,14 @@ define([
pads.forEach(function (pad, i) { pads.forEach(function (pad, i) {
if (pad && typeof(pad) === 'object') { if (pad && typeof(pad) === 'object') {
var hash = checkObjectData(pad); var hash = checkObjectData(pad);
if (!hash || !common.parseHash(hash)) { return; } if (!hash || !common.parseHash(hash)) {
console.error("[Cryptpad.checkRecentPads] pad had unexpected value", pad);
getStore().removeData(i);
return;
}
return pad; return pad;
} }
console.error("[Cryptpad.migrateRecentPads] pad had unexpected value"); console.error("[Cryptpad.checkRecentPads] pad had unexpected value", pad);
getStore().removeData(i); getStore().removeData(i);
}); });
}; };
@ -572,7 +580,7 @@ define([
return pad; return pad;
}); });
if (!contains) { if (!contains && href) {
var data = makePad(href, name); var data = makePad(href, name);
getStore().pushData(data, function (e) { getStore().pushData(data, function (e) {
if (e) { if (e) {

@ -558,7 +558,8 @@ define([
$userButton.click(function (e) { $userButton.click(function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
Cryptpad.getLastName(function (lastName) { Cryptpad.getLastName(function (err, lastName) {
if (err) { return void console.error("Cannot get last name", err); }
Cryptpad.prompt(Messages.changeNamePrompt, lastName || '', function (newName) { Cryptpad.prompt(Messages.changeNamePrompt, lastName || '', function (newName) {
if (newName === null && typeof(lastName) === "string") { return; } if (newName === null && typeof(lastName) === "string") { return; }
if (newName === null) { newName = ''; } if (newName === null) { newName = ''; }

@ -102,7 +102,7 @@ define([
var checkSynchronizing = function (toolbar, config) { var checkSynchronizing = function (toolbar, config) {
if (!toolbar.state) { return; } if (!toolbar.state) { return; }
var userList = config.userList.list.users; var userList = config.userList.list.users;
var userNetfluxId = config.userList.userNetfluxId; // TODO var userNetfluxId = config.userList.userNetfluxId;
var meIdx = userList.indexOf(userNetfluxId); var meIdx = userList.indexOf(userNetfluxId);
if (meIdx === -1) { if (meIdx === -1) {
toolbar.state.text(Messages.synchronizing); toolbar.state.text(Messages.synchronizing);
@ -113,7 +113,7 @@ define([
var getOtherUsers = function(config) { var getOtherUsers = function(config) {
var userList = config.userList.list.users; var userList = config.userList.list.users;
var userData = config.userList.data; var userData = config.userList.data;
var userNetfluxId = config.userList.userNetfluxId; // TODO var userNetfluxId = config.userList.userNetfluxId;
var i = 0; // duplicates counter var i = 0; // duplicates counter
var list = []; var list = [];
@ -121,7 +121,6 @@ define([
// Display only one time each user (if he is connected in multiple tabs) // Display only one time each user (if he is connected in multiple tabs)
var myUid = userData[userNetfluxId] ? userData[userNetfluxId].uid : undefined; var myUid = userData[userNetfluxId] ? userData[userNetfluxId].uid : undefined;
var uids = []; var uids = [];
userList.forEach(function(user) { userList.forEach(function(user) {
if (user !== userNetfluxId) { if (user !== userNetfluxId) {
var data = userData[user] || {}; var data = userData[user] || {};
@ -130,7 +129,7 @@ define([
if (userName && uids.indexOf(userId) === -1 && (!myUid || userId !== myUid)) { if (userName && uids.indexOf(userId) === -1 && (!myUid || userId !== myUid)) {
uids.push(userId); uids.push(userId);
list.push(userName); list.push(userName);
} else { i++; } } else if (userName) { i++; }
} }
}); });
return { return {
@ -261,8 +260,6 @@ define([
$block.attr('id', 'userButtons'); $block.attr('id', 'userButtons');
toolbar.$leftside.prepend($block); toolbar.$leftside.prepend($block);
initUserList(toolbar, config);
return $block; return $block;
}; };
@ -597,7 +594,7 @@ define([
'class': 'synced fa fa-check', 'class': 'synced fa fa-check',
title: Messages.synced title: Messages.synced
}).appendTo($spin); }).appendTo($spin);
toolbar.$userAdmin.prepend($spin); // TODO: put at the corretc position in userAdmin toolbar.$userAdmin.prepend($spin);
if (config.realtime) { if (config.realtime) {
config.realtime.onPatch(ks(toolbar, config)); config.realtime.onPatch(ks(toolbar, config));
config.realtime.onMessage(ks(toolbar, config, true)); config.realtime.onMessage(ks(toolbar, config, true));
@ -674,11 +671,12 @@ define([
} }
Cryptpad.createUserAdminMenu(userMenuCfg); Cryptpad.createUserAdminMenu(userMenuCfg);
var $userButton = $userAdmin.find('a.' + USERBUTTON_CLS); var $userButton = toolbar.$userNameButton = $userAdmin.find('a.' + USERBUTTON_CLS);
$userButton.click(function (e) { $userButton.click(function (e) {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
Cryptpad.getLastName(function (lastName) { Cryptpad.getLastName(function (err, lastName) {
if (err) { return void console.error("Cannot get last name", err); }
Cryptpad.prompt(Messages.changeNamePrompt, lastName || '', function (newName) { Cryptpad.prompt(Messages.changeNamePrompt, lastName || '', function (newName) {
if (newName === null && typeof(lastName) === "string") { return; } if (newName === null && typeof(lastName) === "string") { return; }
if (newName === null) { newName = ''; } if (newName === null) { newName = ''; }
@ -845,7 +843,7 @@ define([
tb['userlist'] = createUserList; tb['userlist'] = createUserList;
tb['share'] = createShare; tb['share'] = createShare;
tb['fileshare'] = createFileShare; tb['fileshare'] = createFileShare;
tb['title'] = createTitle; // TODO: New one, add it to the displayed in main.js ? tb['title'] = createTitle;
tb['lag'] = createLag; tb['lag'] = createLag;
tb['spinner'] = createSpinner; tb['spinner'] = createSpinner;
tb['state'] = createState; tb['state'] = createState;
@ -867,6 +865,7 @@ define([
}; };
addElement(config.displayed, {}, true); addElement(config.displayed, {}, true);
initUserList(toolbar, config);
toolbar['linkToMain'] = createLinkToMain(toolbar, config); toolbar['linkToMain'] = createLinkToMain(toolbar, config);

@ -883,6 +883,11 @@ define([
toClean.push(el); toClean.push(el);
return; return;
} }
if (!el.href) {
debug("Rmoving an element in filesData with a missing href.", el);
toClean.push(el);
return;
}
if (rootFiles.indexOf(el.href) === -1) { if (rootFiles.indexOf(el.href) === -1) {
debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", el); debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", el);
var name = el.title || NEW_FILE_NAME; var name = el.title || NEW_FILE_NAME;

@ -6,7 +6,7 @@ define([
'json.sortify', 'json.sortify',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/userObject.js', '/common/userObject.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/customize/application_config.js', '/customize/application_config.js',
'/common/cryptget.js', '/common/cryptget.js',
'/common/mergeDrive.js' '/common/mergeDrive.js'
@ -2583,21 +2583,26 @@ define([
var userList = APP.userList = info.userList; var userList = APP.userList = info.userList;
var config = { var config = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit'], displayed: ['useradmin', 'spinner', 'lag', 'state', 'limit'],
userList: {
list: userList,
userNetfluxId: info.myID
},
common: Cryptpad,
readOnly: readOnly, readOnly: readOnly,
ifrw: window, ifrw: window,
common: Cryptpad, realtime: info.realtime,
hideShare: true network: info.network,
$container: APP.$bar
}; };
APP.toolbar = info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); var toolbar = APP.toolbar = Toolbar.create(config);
var $bar = APP.$bar; var $rightside = toolbar.$rightside;
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $leftside = toolbar.$leftside;
var $leftside = $bar.find('.' + Toolbar.constants.leftside); var $userBlock = toolbar.$userAdmin;
var $userBlock = $bar.find('.' + Toolbar.constants.userAdmin); APP.$displayName = APP.$bar.find('.' + Toolbar.constants.username);
APP.$displayName = $bar.find('.' + Toolbar.constants.username);
if (APP.homePageIframe) { if (APP.homePageIframe) {
var $linkToMain = $bar.find('.cryptpad-link a'); var $linkToMain = toolbar.linkToMain;
$linkToMain.attr('href', '#'); $linkToMain.attr('href', '#');
$linkToMain.attr('title', ''); $linkToMain.attr('title', '');
$linkToMain.css('cursor', 'default'); $linkToMain.css('cursor', 'default');
@ -2669,7 +2674,7 @@ define([
// Called when the history is loaded and the UI displayed // Called when the history is loaded and the UI displayed
setHistory(true); setHistory(true);
}; };
histConfig.$toolbar = $bar; histConfig.$toolbar = APP.$bar;
histConfig.href = window.location.origin + window.location.pathname + APP.hash; histConfig.href = window.location.origin + window.location.pathname + APP.hash;
var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig}); var $hist = Cryptpad.createButton('history', true, {histConfig: histConfig});
$rightside.append($hist); $rightside.append($hist);

@ -3,7 +3,7 @@ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/hyperjson/hyperjson.js', '/bower_components/hyperjson/hyperjson.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/common/cursor.js', '/common/cursor.js',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/TypingTests.js', '/common/TypingTests.js',
@ -277,51 +277,7 @@ define([
}; };
var initializing = true; var initializing = true;
var userData = module.userData = {}; // List of pretty names for all users (mapped with their ID) var UserList;
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 userData) {
if (users.indexOf(userKey) === -1) { delete userData[userKey]; }
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
};
var myData = {};
var myUserName = ''; // My "pretty name"
var myID; // My server ID
var setMyID = function(info) {
myID = info.myID || null;
};
var setName = module.setName = function (newName) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(myUserNameTemp.length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', newName, function (err) {
if (err) {
console.error("Couldn't set username");
return;
}
editor.fire('change');
});
};
var getHeadingText = function () { var getHeadingText = function () {
var text; var text;
@ -359,7 +315,7 @@ define([
var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter); var hjson = Hyperjson.fromDOM(dom, isNotMagicLine, brFilter);
hjson[3] = { hjson[3] = {
metadata: { metadata: {
users: userData, users: UserList.userData,
defaultTitle: defaultName defaultTitle: defaultName
} }
}; };
@ -385,9 +341,6 @@ define([
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
readOnly: readOnly, readOnly: readOnly,
// method which allows us to get the id of the user
setMyID: setMyID,
// Pass in encrypt and decrypt methods // Pass in encrypt and decrypt methods
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
@ -449,7 +402,7 @@ define([
if (peerMetadata.metadata.users) { if (peerMetadata.metadata.users) {
var userData = peerMetadata.metadata.users; var userData = peerMetadata.metadata.users;
// Update the local user data // Update the local user data
addToUserData(userData); UserList.addToUserData(userData);
} }
if (peerMetadata.metadata.defaultTitle) { if (peerMetadata.metadata.defaultTitle) {
updateDefaultTitle(peerMetadata.metadata.defaultTitle); updateDefaultTitle(peerMetadata.metadata.defaultTitle);
@ -570,13 +523,11 @@ define([
}; };
realtimeOptions.onInit = function (info) { realtimeOptions.onInit = function (info) {
userList = info.userList; UserList = Cryptpad.createUserList(info, realtimeOptions.onLocal, Cryptget, Cryptpad);
var configTb = { var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData, userList: UserList.getToolbarConfig(),
readOnly: readOnly,
ifrw: ifrw,
share: { share: {
secret: secret, secret: secret,
channel: info.channel channel: info.channel
@ -586,13 +537,16 @@ define([
defaultName: defaultName, defaultName: defaultName,
suggestName: suggestName suggestName: suggestName
}, },
common: Cryptpad common: Cryptpad,
readOnly: readOnly,
ifrw: ifrw,
realtime: info.realtime,
network: info.network,
$container: $bar
}; };
toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, configTb); toolbar = info.realtime.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $rightside = toolbar.$rightside;
$bar.find('.' + Toolbar.constants.username);
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
var editHash; var editHash;
@ -667,10 +621,6 @@ define([
/* add an import button */ /* add an import button */
var $import = Cryptpad.createButton('import', true, {}, importFile); var $import = Cryptpad.createButton('import', true, {}, importFile);
$rightside.append($import); $rightside.append($import);
/* add a rename button */
//var $setTitle = Cryptpad.createButton('rename', true, {suggestName: suggestName}, renameCb);
//$rightside.append($setTitle);
} }
/* add a forget button */ /* add a forget button */
@ -683,8 +633,6 @@ define([
// set the hash // set the hash
if (!readOnly) { Cryptpad.replaceHash(editHash); } if (!readOnly) { Cryptpad.replaceHash(editHash); }
Cryptpad.onDisplayNameChanged(setName);
}; };
// this should only ever get called once, when the chain syncs // this should only ever get called once, when the chain syncs
@ -707,7 +655,6 @@ define([
}); });
} }
module.users = info.userList.users;
module.realtime = info.realtime; module.realtime = info.realtime;
var shjson = module.realtime.getUserDoc(); var shjson = module.realtime.getUserDoc();
@ -743,35 +690,18 @@ define([
documentBody.innerHTML = Messages.initialState; documentBody.innerHTML = Messages.initialState;
} }
Cryptpad.getLastName(function (err, lastName) { Cryptpad.removeLoadingScreen(emitResize);
console.log("Unlocking editor");
setEditable(!readOnly); setEditable(!readOnly);
initializing = false; initializing = false;
Cryptpad.removeLoadingScreen(emitResize);
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; } if (readOnly) { return; }
if (typeof(lastName) === 'string') { UserList.getLastName(toolbar.$userNameButton, newPad);
setName(lastName);
} else {
myData[myID] = {
name: "",
uid: Cryptpad.getUid()
};
addToUserData(myData);
realtimeOptions.onLocal();
module.$userNameButton.click();
}
editor.focus(); editor.focus();
if (newPad) { if (newPad) {
Cryptpad.selectTemplate('pad', info.realtime, Cryptget);
cursor.setToEnd(); cursor.setToEnd();
} else { } else {
cursor.setToStart(); cursor.setToStart();
} }
});
}; };
realtimeOptions.onAbort = function () { realtimeOptions.onAbort = function () {

@ -7,7 +7,7 @@ define([
'/common/cryptget.js', '/common/cryptget.js',
'/bower_components/hyperjson/hyperjson.js', '/bower_components/hyperjson/hyperjson.js',
'render.js', 'render.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/common/visible.js', '/common/visible.js',
'/common/notify.js', '/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js' '/bower_components/file-saver/FileSaver.min.js'
@ -442,47 +442,7 @@ define([
}); });
}; };
var userData = APP.userData = {}; // List of pretty names for all users (mapped with their ID) var UserList;
var userList; // List of users still connected to the channel (server IDs)
var addToUserData = function(data) {
var users = userList ? userList.users : undefined;
//var userData = APP.proxy.info.userData;
for (var attrname in data) { userData[attrname] = data[attrname]; }
if (users && users.length) {
for (var userKey in userData) {
if (users.indexOf(userKey) === -1) { delete userData[userKey]; }
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
APP.proxy.info.userData = userData;
};
var setName = APP.setName = function (newName) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(myUserNameTemp.length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
var myUserName = myUserNameTemp;
var myID = APP.myID;
var myData = {};
myData[myID] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', newName, function (err) {
if (err) {
console.error("Couldn't set username");
return;
}
});
};
var updateTitle = function (newTitle) { var updateTitle = function (newTitle) {
if (newTitle === document.title) { return; } if (newTitle === document.title) { return; }
@ -629,7 +589,7 @@ define([
updateTitle(n); updateTitle(n);
notify(); notify();
} else if (p[1] === "userData") { } else if (p[1] === "userData") {
addToUserData(APP.proxy.info.userData); UserList.addToUserData(APP.proxy.info.userData);
} else if (p[1] === 'description') { } else if (p[1] === 'description') {
var op = TextPatcher.diff(o, n); var op = TextPatcher.diff(o, n);
var el = $description[0]; var el = $description[0];
@ -650,7 +610,7 @@ define([
.on('change', ['table'], change) .on('change', ['table'], change)
.on('remove', [], change); .on('remove', [], change);
addToUserData(APP.proxy.info.userData); UserList.addToUserData(APP.proxy.info.userData);
if (Visible.isSupported()) { if (Visible.isSupported()) {
Visible.onChange(function (yes) { Visible.onChange(function (yes) {
@ -659,9 +619,7 @@ define([
} }
Cryptpad.getLastName(function (err, lastName) {
APP.ready = true; APP.ready = true;
if (!proxy.published) { if (!proxy.published) {
publish(false); publish(false);
} else { } else {
@ -669,35 +627,19 @@ define([
} }
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; } if (readOnly) { return; }
if (typeof(lastName) === 'string') { UserList.getLastName(APP.toolbar.$userNameButton, isNew);
setName(lastName);
} else {
var myData = {};
myData[info.myId] = {
name: "",
uid: Cryptpad.getUid(),
};
addToUserData(myData);
APP.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('poll', info.realtime, Cryptget);
}
});
}; };
var disconnect = function () { var disconnect = function () {
//setEditable(false); // TODO //setEditable(false); // TODO
APP.realtime.toolbar.failed(); APP.toolbar.failed();
Cryptpad.alert(Messages.common_connectionLost, undefined, true); Cryptpad.alert(Messages.common_connectionLost, undefined, true);
}; };
var reconnect = function (info) { var reconnect = function (info) {
//setEditable(true); // TODO //setEditable(true); // TODO
APP.realtime.toolbar.reconnecting(info.myId); APP.toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click(); Cryptpad.findOKButton().click();
}; };
@ -717,12 +659,14 @@ define([
}); });
} }
userList = APP.userList = info.userList; var onLocal = function () {
APP.proxy.info.userData = UserList.userData;
};
UserList = Cryptpad.createUserList(info, onLocal, Cryptget, Cryptpad);
var config = { var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData, userList: UserList.getToolbarConfig(),
readOnly: readOnly,
share: { share: {
secret: secret, secret: secret,
channel: info.channel channel: info.channel
@ -732,17 +676,16 @@ define([
defaultName: defaultName, defaultName: defaultName,
suggestName: suggestName suggestName: suggestName
}, },
ifrw: window,
common: Cryptpad, common: Cryptpad,
readOnly: readOnly,
ifrw: window,
realtime: info.realtime,
network: info.network,
$container: APP.$bar
}; };
info.realtime.toolbar = Toolbar.create(APP.$bar, info.myID, info.realtime, info.getLag, userList, config); APP.toolbar = Toolbar.create(configTb);
var $bar = APP.$bar; var $rightside = APP.toolbar.$rightside;
var $rightside = $bar.find('.' + Toolbar.constants.rightside);
$bar.find('.' + Toolbar.constants.username);
$bar.find('.' + Toolbar.constants.editShare);
$bar.find('.' + Toolbar.constants.viewShare);
APP.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
/* add a forget button */ /* add a forget button */
var forgetCb = function (err) { var forgetCb = function (err) {
@ -765,8 +708,6 @@ define([
var $templateButton = Cryptpad.createButton('template', true, templateObj); var $templateButton = Cryptpad.createButton('template', true, templateObj);
$rightside.append($templateButton); $rightside.append($templateButton);
} }
Cryptpad.onDisplayNameChanged(setName);
}; };
// don't initialize until the store is ready. // don't initialize until the store is ready.

@ -3,7 +3,7 @@ define([
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/textpatcher/TextPatcher.js', '/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar.js', '/common/toolbar2.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
@ -167,37 +167,11 @@ define([
editor.setOption('readOnly', !bool); editor.setOption('readOnly', !bool);
}; };
var userData = module.userData = {}; // List of pretty name of all users (mapped with their server ID) var UserList;
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 userData) {
if (users.indexOf(userKey) === -1) {
delete userData[userKey];
}
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
};
var textColor; var textColor;
var backColor; var backColor;
var myData = {};
var myUserName = ''; // My "pretty name"
var myID; // My server ID
var setMyID = function(info) {
myID = info.myID || null;
myUserName = myID;
};
var config = { var config = {
//initialState: Messages.codeInitialState, //initialState: Messages.codeInitialState,
initialState: '{}', initialState: '{}',
@ -207,7 +181,6 @@ define([
validateKey: secret.keys.validateKey || undefined, validateKey: secret.keys.validateKey || undefined,
readOnly: readOnly, readOnly: readOnly,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
setMyID: setMyID,
transformFunction: JsonOT.validate, transformFunction: JsonOT.validate,
network: Cryptpad.getNetwork() network: Cryptpad.getNetwork()
}; };
@ -228,7 +201,7 @@ define([
var obj = { var obj = {
content: textValue, content: textValue,
metadata: { metadata: {
users: userData, users: UserList.userData,
defaultTitle: defaultName, defaultTitle: defaultName,
slideOptions: slideOptions slideOptions: slideOptions
} }
@ -264,28 +237,6 @@ define([
} }
}; };
var setName = module.setName = function (newName) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', myUserName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
onLocal();
});
};
var getHeadingText = function () { var getHeadingText = function () {
var lines = editor.getValue().split(/\n/); var lines = editor.getValue().split(/\n/);
@ -413,7 +364,7 @@ define([
if (json.metadata.users) { if (json.metadata.users) {
var userData = json.metadata.users; var userData = json.metadata.users;
// Update the local user data // Update the local user data
addToUserData(userData); UserList.addToUserData(userData);
} }
if (json.metadata.defaultTitle) { if (json.metadata.defaultTitle) {
updateDefaultTitle(json.metadata.defaultTitle); updateDefaultTitle(json.metadata.defaultTitle);
@ -508,13 +459,11 @@ define([
}; };
config.onInit = function (info) { config.onInit = function (info) {
userList = info.userList; UserList = Cryptpad.createUserList(info, config.onLocal, Cryptget, Cryptpad);
var configTb = { var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData, userList: UserList.getToolbarConfig(),
readOnly: readOnly,
ifrw: ifrw,
share: { share: {
secret: secret, secret: secret,
channel: info.channel channel: info.channel
@ -524,13 +473,16 @@ define([
defaultName: defaultName, defaultName: defaultName,
suggestName: suggestName suggestName: suggestName
}, },
common: Cryptpad common: Cryptpad,
readOnly: readOnly,
ifrw: ifrw,
realtime: info.realtime,
network: info.network,
$container: $bar
}; };
toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, configTb); toolbar = module.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $rightside = toolbar.$rightside;
$bar.find('.' + Toolbar.constants.username);
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
var editHash; var editHash;
@ -733,8 +685,6 @@ define([
if (!window.location.hash || window.location.hash === '#') { if (!window.location.hash || window.location.hash === '#') {
Cryptpad.replaceHash(editHash); Cryptpad.replaceHash(editHash);
} }
Cryptpad.onDisplayNameChanged(setName);
}; };
var unnotify = module.unnotify = function () { var unnotify = module.unnotify = function () {
@ -752,8 +702,6 @@ define([
}; };
config.onReady = function (info) { config.onReady = function (info) {
module.users = info.userList.users;
if (module.realtime !== info.realtime) { if (module.realtime !== info.realtime) {
var realtime = module.realtime = info.realtime; var realtime = module.realtime = info.realtime;
module.patchText = TextPatcher.create({ module.patchText = TextPatcher.create({
@ -816,33 +764,11 @@ define([
Cryptpad.removeLoadingScreen(); Cryptpad.removeLoadingScreen();
setEditable(true); setEditable(true);
initializing = false; initializing = false;
//Cryptpad.log("Your document is ready");
onLocal(); // push local state to avoid parse errors later. onLocal(); // push local state to avoid parse errors later.
Cryptpad.getLastName(function (err, lastName) {
if (err) {
console.log("Could not get previous name");
console.error(err);
return;
}
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; } if (readOnly) { return; }
if (typeof(lastName) === 'string') { UserList.getLastName(toolbar.$userNameButton, isNew);
setName(lastName);
} else {
myData[myID] = {
name: "",
uid: Cryptpad.getUid(),
};
addToUserData(myData);
onLocal();
module.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('slide', info.realtime, Cryptget);
}
});
}; };
var cursorToPos = function(cursor, oldText) { var cursorToPos = function(cursor, oldText) {

@ -3,7 +3,7 @@ define([
'/api/config', '/api/config',
'/bower_components/chainpad-netflux/chainpad-netflux.js', '/bower_components/chainpad-netflux/chainpad-netflux.js',
'/bower_components/chainpad-crypto/crypto.js', '/bower_components/chainpad-crypto/crypto.js',
'/common/toolbar.js', '/common/toolbar2.js',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js', '/bower_components/chainpad-json-validator/json-ot.js',
@ -214,33 +214,7 @@ window.canvas = canvas;
var $bar = $('#toolbar'); var $bar = $('#toolbar');
var parsedHash = Cryptpad.parsePadUrl(window.location.href); var parsedHash = Cryptpad.parsePadUrl(window.location.href);
var defaultName = Cryptpad.getDefaultName(parsedHash); var defaultName = Cryptpad.getDefaultName(parsedHash);
var userData = module.userData = {}; // List of pretty name of all users (mapped with their server ID) var UserList;
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 userData) {
if (users.indexOf(userKey) === -1) {
delete userData[userKey];
}
}
}
if(userList && typeof userList.onChange === "function") {
userList.onChange(userData);
}
};
var myData = {};
var myUserName = ''; // My "pretty name"
var myID; // My server ID
var setMyID = function(info) {
myID = info.myID || null;
myUserName = myID;
};
var config = module.config = { var config = module.config = {
initialState: '{}', initialState: '{}',
@ -249,7 +223,6 @@ window.canvas = canvas;
readOnly: readOnly, readOnly: readOnly,
channel: secret.channel, channel: secret.channel,
crypto: Crypto.createEncryptor(secret.keys), crypto: Crypto.createEncryptor(secret.keys),
setMyID: setMyID,
transformFunction: JsonOT.transform, transformFunction: JsonOT.transform,
}; };
@ -331,29 +304,30 @@ window.canvas = canvas;
}; };
config.onInit = function (info) { config.onInit = function (info) {
userList = info.userList; UserList = Cryptpad.createUserList(info, config.onLocal, Cryptget, Cryptpad);
var config = { var configTb = {
displayed: ['useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'], displayed: ['title', 'useradmin', 'spinner', 'lag', 'state', 'share', 'userlist', 'newpad', 'limit'],
userData: userData, userList: UserList.getToolbarConfig(),
readOnly: readOnly,
share: { share: {
secret: secret, secret: secret,
channel: info.channel channel: info.channel
}, },
ifrw: window,
title: { title: {
onRename: renameCb, onRename: renameCb,
defaultName: defaultName, defaultName: defaultName,
suggestName: suggestName suggestName: suggestName
}, },
common: Cryptpad common: Cryptpad,
readOnly: readOnly,
ifrw: window,
realtime: info.realtime,
network: info.network,
$container: $bar
}; };
if (readOnly) {delete config.changeNameID; }
toolbar = module.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, userList, config); toolbar = module.toolbar = Toolbar.create(configTb);
var $rightside = $bar.find('.' + Toolbar.constants.rightside); var $rightside = toolbar.$rightside;
module.$userNameButton = $($bar.find('.' + Toolbar.constants.changeUsername));
/* save as template */ /* save as template */
if (!Cryptpad.isTemplate(window.location.href)) { if (!Cryptpad.isTemplate(window.location.href)) {
@ -384,8 +358,6 @@ window.canvas = canvas;
editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys); editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
} }
if (!readOnly) { Cryptpad.replaceHash(editHash); } if (!readOnly) { Cryptpad.replaceHash(editHash); }
Cryptpad.onDisplayNameChanged(module.setName);
}; };
// used for debugging, feel free to remove // used for debugging, feel free to remove
@ -431,7 +403,7 @@ window.canvas = canvas;
if (json.metadata.users) { if (json.metadata.users) {
var userData = json.metadata.users; var userData = json.metadata.users;
// Update the local user data // Update the local user data
addToUserData(userData); UserList.addToUserData(userData);
} }
if (json.metadata.defaultTitle) { if (json.metadata.defaultTitle) {
updateDefaultTitle(json.metadata.defaultTitle); updateDefaultTitle(json.metadata.defaultTitle);
@ -486,7 +458,7 @@ window.canvas = canvas;
var obj = { var obj = {
content: textValue, content: textValue,
metadata: { metadata: {
users: userData, users: UserList.userData,
palette: palette, palette: palette,
defaultTitle: defaultName defaultTitle: defaultName
} }
@ -508,28 +480,6 @@ window.canvas = canvas;
module.patchText(content); module.patchText(content);
}); });
var setName = module.setName = function (newName) {
if (typeof(newName) !== 'string') { return; }
var myUserNameTemp = newName.trim();
if(newName.trim().length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
myUserName = myUserNameTemp;
myData[myID] = {
name: myUserName,
uid: Cryptpad.getUid(),
};
addToUserData(myData);
Cryptpad.setAttribute('username', myUserName, function (err) {
if (err) {
console.log("Couldn't set username");
console.error(err);
return;
}
onLocal();
});
};
config.onReady = function (info) { config.onReady = function (info) {
var realtime = module.realtime = info.realtime; var realtime = module.realtime = info.realtime;
module.patchText = TextPatcher.create({ module.patchText = TextPatcher.create({
@ -550,30 +500,9 @@ window.canvas = canvas;
} }
/* TODO: restore palette from metadata.palette */ /* TODO: restore palette from metadata.palette */
Cryptpad.getLastName(function (err, lastName) {
if (err) {
console.log("Could not get previous name");
console.error(err);
return;
}
// Update the toolbar list:
// Add the current user in the metadata if he has edit rights
if (readOnly) { return; } if (readOnly) { return; }
if (typeof(lastName) === 'string') { UserList.getLastName(toolbar.$userNameButton, isNew);
setName(lastName);
} else {
myData[myID] = {
name: "",
uid: Cryptpad.getUid(),
};
addToUserData(myData);
onLocal();
module.$userNameButton.click();
}
if (isNew) {
Cryptpad.selectTemplate('whiteboard', info.realtime, Cryptget);
}
});
}; };
config.onAbort = function () { config.onAbort = function () {

Loading…
Cancel
Save