merge staging

This commit is contained in:
ansuz
2018-06-28 13:33:54 +02:00
19 changed files with 149 additions and 57 deletions

View File

@@ -119,5 +119,12 @@ define(function() {
// You can use config.afterLogin to import these values in the users' drive.
//config.disableProfile = true;
// Disable the use of webworkers and sharedworkers in CryptPad.
// Workers allow us to run the websockets connection and open the user drive in a separate thread.
// SharedWorkers allow us to load only one websocket and one user drive for all the browser tabs,
// making it much faster to open new tabs.
// Warning: This is an experimental feature. It will be enabled by default once we're sure it's stable.
config.disableWorkers = true;
return config;
});

View File

@@ -187,7 +187,7 @@ define([
if (!yes) { return; }
sframeChan.query("Q_PAD_PASSWORD_CHANGE", {
href: data.href,
password: $(newPassword).val()
password: $(newPassword).find('input').val()
}, function (err, data) {
if (err || data.error) {
return void UI.alert(Messages.properties_passwordError);

View File

@@ -954,7 +954,7 @@ define([
},
// Messaging
Q_FRIEND_REQUEST: common.messaging.onFriendRequest.fire,
EV_FIREND_COMPLETE: common.messaging.onFriendComplete.fire,
EV_FRIEND_COMPLETE: common.messaging.onFriendComplete.fire,
// Network
NETWORK_DISCONNECT: common.onNetworkDisconnect.fire,
NETWORK_RECONNECT: function (data) {
@@ -1076,7 +1076,6 @@ define([
}).nThen(function (waitFor) {
var cfg = {
init: true,
//query: onMessage, // TODO temporary, will be replaced by a webworker channel
userHash: LocalStore.getUserHash(),
anonHash: LocalStore.getFSHash(),
localToken: tryParsing(localStorage.getItem(Constants.tokenKey)),
@@ -1093,11 +1092,32 @@ define([
var msgEv = Util.mkEvent();
var postMsg, worker;
var noWorker = AppConfig.disableWorkers || false;
if (localStorage.CryptPad_noWorkers) {
noWorker = localStorage.CryptPad_noWorkers === '1';
console.error('WebWorker/SharedWorker state forced to ' + !noWorker);
}
Nthen(function (waitFor2) {
if (typeof(SharedWorker) !== "undefined") {
if (Worker) {
var w = waitFor2();
worker = new Worker('/common/outer/testworker.js?' + urlArgs);
worker.onerror = function (errEv) {
errEv.preventDefault();
errEv.stopPropagation();
noWorker = true;
w();
};
worker.onmessage = function (ev) {
if (ev.data === "OK") {
w();
}
};
}
}).nThen(function (waitFor2) {
if (!noWorker && typeof(SharedWorker) !== "undefined") {
worker = new SharedWorker('/common/outer/sharedworker.js?' + urlArgs);
worker.onerror = function (e) {
console.error(e);
console.error(e.message);
};
worker.port.onmessage = function (ev) {
if (ev.data === "SW_READY") {
@@ -1113,7 +1133,7 @@ define([
window.addEventListener('beforeunload', function () {
postMsg('CLOSE');
});
} else if (false && 'serviceWorker' in navigator) {
} else if (false && !noWorker && 'serviceWorker' in navigator) {
var initializing = true;
var stopWaiting = waitFor2(); // Call this function when we're ready
@@ -1163,8 +1183,11 @@ define([
window.addEventListener('beforeunload', function () {
postMsg('CLOSE');
});
} else if (Worker) {
} else if (!noWorker && Worker) {
worker = new Worker('/common/outer/webworker.js?' + urlArgs);
worker.onerror = function (e) {
console.error(e.message);
};
worker.onmessage = function (ev) {
msgEv.fire(ev);
};
@@ -1172,6 +1195,7 @@ define([
worker.postMessage(data);
};
} else {
// Use the async store in the main thread if workers are not available
require(['/common/outer/noworker.js'], waitFor2(function (NoWorker) {
NoWorker.onMessage(function (data) {
msgEv.fire({data: data});

View File

@@ -894,7 +894,7 @@ define([
};
Store.messenger = {
getFriendList: function (data, cb) {
getFriendList: function (clientId, data, cb) {
store.messenger.getFriendList(function (e, keys) {
cb({
error: e,
@@ -902,7 +902,7 @@ define([
});
});
},
getMyInfo: function (data, cb) {
getMyInfo: function (clientId, data, cb) {
store.messenger.getMyInfo(function (e, info) {
cb({
error: e,
@@ -910,7 +910,7 @@ define([
});
});
},
getFriendInfo: function (data, cb) {
getFriendInfo: function (clientId, data, cb) {
store.messenger.getFriendInfo(data, function (e, info) {
cb({
error: e,
@@ -918,7 +918,7 @@ define([
});
});
},
removeFriend: function (data, cb) {
removeFriend: function (clientId, data, cb) {
store.messenger.removeFriend(data, function (e, info) {
cb({
error: e,
@@ -926,12 +926,12 @@ define([
});
});
},
openFriendChannel: function (data, cb) {
openFriendChannel: function (clientId, data, cb) {
store.messenger.openFriendChannel(data, function (e) {
cb({ error: e, });
});
},
getFriendStatus: function (data, cb) {
getFriendStatus: function (clientId, data, cb) {
store.messenger.getStatus(data, function (e, online) {
cb({
error: e,
@@ -939,7 +939,7 @@ define([
});
});
},
getMoreHistory: function (data, cb) {
getMoreHistory: function (clientId, data, cb) {
store.messenger.getMoreHistory(data.curvePublic, data.sig, data.count, function (e, history) {
cb({
error: e,
@@ -947,14 +947,14 @@ define([
});
});
},
sendMessage: function (data, cb) {
sendMessage: function (clientId, data, cb) {
store.messenger.sendMessage(data.curvePublic, data.content, function (e) {
cb({
error: e,
});
});
},
setChannelHead: function (data, cb) {
setChannelHead: function (clientId, data, cb) {
store.messenger.setChannelHead(data.curvePublic, data.sig, function (e) {
cb({
error: e

View File

@@ -0,0 +1,4 @@
if (!self.crypto && !self.msCrypto) {
throw new Error("E_NOCRYPTO");
}
self.postMessage("OK");

View File

@@ -41,7 +41,6 @@ define([
if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); }
var data = exp.getFileData(id);
data[attr] = clone(value);
console.log(data);
cb(null);
};
exp.getPadAttribute = function (href, attr, cb) {

View File

@@ -584,7 +584,9 @@ define([
onRemote: onRemote,
setHistory: setHistoryMode,
applyVal: function (val) {
contentUpdate(JSON.parse(val) || ["BODY",{},[]]);
contentUpdate(JSON.parse(val) || ["BODY",{},[]], function (h) {
return h;
});
},
$toolbar: $(toolbarContainer)
};

View File

@@ -79,7 +79,7 @@ define([
isComplete = data.isFull;
Array.prototype.unshift.apply(allMessages, data.messages); // Destructive concat
fillChainPad(realtime, allMessages);
cb (null, realtime);
cb (null, realtime, data.isFull);
});
};
@@ -142,7 +142,8 @@ define([
loading = true;
$loadMore.removeClass('fa fa-ellipsis-h')
.append($('<span>', {'class': 'fa fa-refresh fa-spin fa-3x fa-fw'}));
loadMoreHistory(config, common, function (err, newRt) {
loadMoreHistory(config, common, function (err, newRt, isFull) {
if (err === 'EFULL') {
$loadMore.off('click').hide();
get(c);
@@ -154,6 +155,10 @@ define([
update(newRt);
$loadMore.addClass('fa fa-ellipsis-h').html('');
get(c);
if (isFull) {
$loadMore.off('click').hide();
$version.show();
}
if (cb) { cb(); }
});
};
@@ -181,7 +186,7 @@ define([
$hist.find('.cp-toolbar-history-fast-next').css('visibility', 'hidden');
}
var $pos = $hist.find('.cp-toolbar-history-pos');
var p = 100 * (1 - (-c / (states.length-1)));
var p = 100 * (1 - (-c / (states.length-2)));
$pos.css('margin-left', p+'%');
// Display the version when the full history is loaded
@@ -317,13 +322,17 @@ define([
};
// Load all the history messages into a new chainpad object
loadMoreHistory(config, common, function (err, newRt) {
loadMoreHistory(config, common, function (err, newRt, isFull) {
History.readOnly = common.getMetadataMgr().getPrivateData().readOnly;
History.loading = false;
if (err) { throw new Error(err); }
update(newRt);
c = states.length - 1;
display();
if (isFull) {
$loadMore.off('click').hide();
$version.show();
}
});
};