WIP secure contacts
parent
08e0ae424d
commit
f9d27d2783
@ -1,17 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html class="cp-app-noscroll">
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
|
||||
<script src="/bower_components/jquery/dist/jquery.min.js"></script>
|
||||
<script async data-bootload="/contacts/inner.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||
<style>.loading-hidden, .loading-hidden * {display: none !important;}</style>
|
||||
<script async data-bootload="/contacts/inner.js" data-main="/common/sframe-boot.js?ver=1.4" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
|
||||
<style>
|
||||
.loading-hidden { display: none; }
|
||||
</style>
|
||||
</head>
|
||||
<body class="loading-hidden">
|
||||
<div id="toolbar" class="toolbar-container"></div>
|
||||
<div id="app">
|
||||
<div id="friendList"></div>
|
||||
<div id="messaging"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<body class="cp-app-contacts">
|
||||
|
||||
|
@ -1,13 +1,117 @@
|
||||
define([
|
||||
'jquery',
|
||||
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||
'/bower_components/chainpad-crypto/crypto.js',
|
||||
'/common/toolbar3.js',
|
||||
'/bower_components/chainpad-json-validator/json-ot.js',
|
||||
'/common/cryptpad-common.js',
|
||||
'/bower_components/nthen/index.js',
|
||||
'/common/sframe-common.js',
|
||||
'/common/hyperscript.js',
|
||||
'/contacts/messenger-ui.js',
|
||||
|
||||
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
|
||||
'less!/contacts/main.less',
|
||||
'less!/customize/src/less/toolbar.less',
|
||||
], function ($) {
|
||||
$('.loading-hidden').removeClass('loading-hidden');
|
||||
// dirty hack to get rid the flash of the lock background
|
||||
setTimeout(function () {
|
||||
$('#app').addClass('ready');
|
||||
}, 100);
|
||||
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||
'less!/customize/src/less2/main.less',
|
||||
], function (
|
||||
$,
|
||||
Crypto,
|
||||
Toolbar,
|
||||
JsonOT,
|
||||
Cryptpad,
|
||||
nThen,
|
||||
SFCommon,
|
||||
h,
|
||||
UI
|
||||
)
|
||||
{
|
||||
var Messages = Cryptpad.Messages;
|
||||
var APP = {};
|
||||
var onConnectError = function () {
|
||||
Cryptpad.errorLoadingScreen(Messages.websocketError);
|
||||
};
|
||||
|
||||
var common;
|
||||
var sFrameChan;
|
||||
nThen(function (waitFor) {
|
||||
$(waitFor(Cryptpad.addLoadingScreen));
|
||||
SFCommon.create(waitFor(function (c) { APP.common = common = c; }));
|
||||
}).nThen(function (waitFor) {
|
||||
sFrameChan = common.getSframeChannel();
|
||||
sFrameChan.onReady(waitFor());
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
Cryptpad.onError(function (info) {
|
||||
if (info && info.type === "store") {
|
||||
onConnectError();
|
||||
}
|
||||
});
|
||||
|
||||
var toolbarElement = h('div#toolbar.cp-toolbar-container');
|
||||
|
||||
document.body.appendChild(toolbarElement);
|
||||
|
||||
var messaging = h('div#messaging', [
|
||||
h('div.info', [
|
||||
h('h2', Messages.contacts_info1),
|
||||
h('ul', [
|
||||
h('li', Messages.contacts_info2),
|
||||
h('li', Messages.contacts_info3),
|
||||
])
|
||||
])
|
||||
]);
|
||||
|
||||
var friendList = h('div#friendList');
|
||||
|
||||
var appElement = h('div#app', [
|
||||
friendList,
|
||||
messaging,
|
||||
]);
|
||||
|
||||
document.body.appendChild(appElement);
|
||||
|
||||
var displayed = ['useradmin', 'newpad', 'limit', 'pageTitle'];
|
||||
var configTb = {
|
||||
displayed: displayed,
|
||||
common: Cryptpad,
|
||||
sfCommon: common,
|
||||
$container: $(toolbarElement),
|
||||
network: Cryptpad.getNetwork(),
|
||||
pageTitle: Messages.contacts_title,
|
||||
metadataMgr: common.getMetadataMgr(),
|
||||
};
|
||||
var toolbar = APP.toolbar = Toolbar.create(configTb);
|
||||
toolbar = toolbar; // FIXME;
|
||||
|
||||
var stub = function () {
|
||||
var p;
|
||||
var t = function(){
|
||||
console.error('called with arguments', Cryptpad.slice(arguments));
|
||||
return p;
|
||||
};
|
||||
p = new Proxy(t, {
|
||||
set: function (o, k, v) {
|
||||
console.error('setting %s to %s', k, v);
|
||||
o[k] = v;
|
||||
return true;
|
||||
}, get: function (o, k) {
|
||||
console.error('getting %s', k);
|
||||
return typeof(o[k]) !== 'undefined'? o[k]: p;
|
||||
}
|
||||
});
|
||||
return p;
|
||||
};
|
||||
|
||||
var messengerStub = stub();
|
||||
UI.create(messengerStub, $(friendList), $(messaging));
|
||||
|
||||
Cryptpad.removeLoadingScreen();
|
||||
/*
|
||||
sFrameChan.query('Q_HEY_BUDDY', null, function (err, data) {
|
||||
if (!data) { return; }
|
||||
if (data.error) {
|
||||
Cryptpad.warn(data.error);
|
||||
} else {
|
||||
Cryptpad.log(data.response);
|
||||
}
|
||||
});*/
|
||||
});
|
||||
});
|
||||
|
@ -1,62 +1,57 @@
|
||||
// Load #1, load as little as possible because we are in a race to get the loading screen up.
|
||||
define([
|
||||
'jquery',
|
||||
'/bower_components/chainpad-crypto/crypto.js',
|
||||
'/common/toolbar2.js',
|
||||
'/common/cryptpad-common.js',
|
||||
|
||||
'/common/common-messenger.js',
|
||||
'/contacts/messenger-ui.js',
|
||||
'/bower_components/nthen/index.js',
|
||||
|
||||
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
|
||||
'less!/customize/src/less/cryptpad.less',
|
||||
], function ($, Crypto, Toolbar, Cryptpad, Messenger, UI, Nthen) {
|
||||
var Messages = Cryptpad.Messages;
|
||||
var APP = window.APP = {
|
||||
Cryptpad: Cryptpad
|
||||
'/api/config',
|
||||
'jquery',
|
||||
'/common/requireconfig.js',
|
||||
'/common/sframe-common-outer.js'
|
||||
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
|
||||
var requireConfig = RequireConfig();
|
||||
var addRpc = function (sFrameChan, Cryptpad) {
|
||||
Cryptpad = Cryptpad;
|
||||
|
||||
// protocols must still be declared in sframe-protocol.js
|
||||
/*
|
||||
sFrameChan.on('Q_HEY_BUDDY', function (data, cb) {
|
||||
cb({
|
||||
error: null,
|
||||
response: "HEY BUDDY",
|
||||
});
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
Nthen(function (waitFor) {
|
||||
// Loaded in load #2
|
||||
nThen(function (waitFor) {
|
||||
$(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
Cryptpad.ready(waitFor(Cryptpad.reportAppUsage));
|
||||
}).nThen(function () {
|
||||
Cryptpad.addLoadingScreen();
|
||||
|
||||
var ifrw = $('#pad-iframe')[0].contentWindow;
|
||||
var $iframe = $('#pad-iframe').contents();
|
||||
var $list = $iframe.find('#friendList');
|
||||
var $messages = $iframe.find('#messaging');
|
||||
var $bar = $iframe.find('.toolbar-container');
|
||||
|
||||
var displayed = ['useradmin', 'newpad', 'limit', 'pageTitle'];
|
||||
|
||||
var configTb = {
|
||||
displayed: displayed,
|
||||
ifrw: ifrw,
|
||||
common: Cryptpad,
|
||||
$container: $bar,
|
||||
network: Cryptpad.getNetwork(),
|
||||
pageTitle: Messages.contacts_title,
|
||||
var req = {
|
||||
cfg: requireConfig,
|
||||
req: [ '/common/loading.js' ],
|
||||
pfx: window.location.origin
|
||||
};
|
||||
var toolbar = APP.toolbar = Toolbar.create(configTb);
|
||||
toolbar.$rightside.html(''); // Remove the drawer if we don't use it to hide the toolbar
|
||||
|
||||
Cryptpad.getProxy().on('disconnect', function () {
|
||||
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
|
||||
});
|
||||
Cryptpad.getProxy().on('reconnect', function (uid) {
|
||||
console.error('reconnecting: ', uid);
|
||||
Cryptpad.findOKButton().click();
|
||||
window.rc = requireConfig;
|
||||
window.apiconf = ApiConfig;
|
||||
$('#sbox-iframe').attr('src',
|
||||
ApiConfig.httpSafeOrigin + '/contacts/inner.html?' + requireConfig.urlArgs +
|
||||
'#' + encodeURIComponent(JSON.stringify(req)));
|
||||
|
||||
// This is a cheap trick to avoid loading sframe-channel in parallel with the
|
||||
// loading screen setup.
|
||||
var done = waitFor();
|
||||
var onMsg = function (msg) {
|
||||
var data = JSON.parse(msg.data);
|
||||
if (data.q !== 'READY') { return; }
|
||||
window.removeEventListener('message', onMsg);
|
||||
var _done = done;
|
||||
done = function () { };
|
||||
_done();
|
||||
};
|
||||
window.addEventListener('message', onMsg);
|
||||
}).nThen(function (/*waitFor*/) {
|
||||
SFCommonO.start({
|
||||
noRealtime: true,
|
||||
addRpc: addRpc,
|
||||
});
|
||||
|
||||
var $infoBlock = $('<div>', {'class': 'info'}).appendTo($messages);
|
||||
$('<h2>').text(Messages.contacts_info1).appendTo($infoBlock);
|
||||
var $ul = $('<ul>').appendTo($infoBlock);
|
||||
$('<li>').text(Messages.contacts_info2).appendTo($ul);
|
||||
$('<li>').text(Messages.contacts_info3).appendTo($ul);
|
||||
|
||||
var messenger = window.messenger = Messenger.messenger(Cryptpad);
|
||||
UI.create(messenger, $list, $messages);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue