|
|
@ -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) {
|
|
|
|