Remove Realtime and Messaging from common

This commit is contained in:
yflory 2017-11-13 17:01:09 +01:00
parent 30c8c253dd
commit 5a2afb5c95
10 changed files with 44 additions and 53 deletions

View file

@ -3,14 +3,14 @@ define([
'/customize/application_config.js',
'/common/cryptpad-common.js',
'/common/common-interface.js',
], function ($, Config, Cryptpad, UI) {
'/common/common-realtime.js',
'/customize/messages.js',
], function ($, Config, Cryptpad, UI, Realtime, Messages) {
window.APP = {
Cryptpad: Cryptpad,
};
var Messages = Cryptpad.Messages;
$(function () {
var $main = $('#mainBlock');
@ -107,7 +107,7 @@ define([
proxy.edPrivate = result.edPrivate;
proxy.edPublic = result.edPublic;
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Realtime.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
document.location.href = '/drive/';
});

View file

@ -82,7 +82,7 @@ define([
friends[pubKey] = data;
Realtime.whenRealtimeSyncs(common, common.getRealtime(), function () {
Realtime.whenRealtimeSyncs(common.getRealtime(), function () {
cb();
common.pinPads([data.channel], function (e) {
if (e) { console.error(e); }

View file

@ -50,21 +50,6 @@ define([
return proxy.friends;
};
var eachFriend = function (friends, cb) {
Object.keys(friends).forEach(function (id) {
if (id === 'me') { return; }
cb(friends[id], id, friends);
});
};
Msg.getFriendChannelsList = function (proxy) {
var list = [];
eachFriend(proxy, function (friend) {
list.push(friend.channel);
});
return list;
};
var msgAlreadyKnown = function (channel, sig) {
return channel.messages.some(function (message) {
return message[0] === sig;

View file

@ -16,7 +16,7 @@ define([
/*
TODO make this not blow up when disconnected or lagging...
*/
common.whenRealtimeSyncs = function (Cryptpad, realtime, cb) {
common.whenRealtimeSyncs = function (realtime, cb) {
if (typeof(realtime.getAuthDoc) !== 'function') {
return void console.error('improper use of this function');
}
@ -29,7 +29,7 @@ define([
}, 0);
};
common.beginDetectingInfiniteSpinner = function (Cryptpad, realtime) {
common.beginDetectingInfiniteSpinner = function (realtime) {
if (intr) { return; }
intr = window.setInterval(function () {
var l;

View file

@ -98,22 +98,21 @@ define([
//common.createInviteUrl = Hash.createInviteUrl;
// Messaging
common.addDirectMessageHandler = Messaging.addDirectMessageHandler;
common.inviteFromUserlist = Messaging.inviteFromUserlist;
common.getFriendList = Messaging.getFriendList;
common.getFriendChannelsList = Messaging.getFriendChannelsList;
common.createData = Messaging.createData;
common.getPendingInvites = Messaging.getPending;
common.getLatestMessages = Messaging.getLatestMessages;
//common.addDirectMessageHandler = Messaging.addDirectMessageHandler;
//common.inviteFromUserlist = Messaging.inviteFromUserlist;
//common.getFriendList = Messaging.getFriendList;
//common.getFriendChannelsList = Messaging.getFriendChannelsList;
//common.createData = Messaging.createData;
//common.getPendingInvites = Messaging.getPending;
//common.getLatestMessages = Messaging.getLatestMessages;
// Realtime
// REFACTOR: common is not needed anymore so we should just pull common-reealtime directly
var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) {
Realtime.whenRealtimeSyncs(common, realtime, cb);
};
common.beginDetectingInfiniteSpinner = function (realtime) {
Realtime.beginDetectingInfiniteSpinner(common, realtime);
};
//var whenRealtimeSyncs = common.whenRealtimeSyncs = function (realtime, cb) {
//Realtime.whenRealtimeSyncs(common, realtime, cb);
//};
//common.beginDetectingInfiniteSpinner = function (realtime) {
//Realtime.beginDetectingInfiniteSpinner(common, realtime);
//};
var getStore = common.getStore = function () {
if (store) { return store; }
@ -429,7 +428,7 @@ define([
if (getProxy()) {
getProxy()[common.displayNameKey] = value;
}
if (typeof cb === "function") { whenRealtimeSyncs(getRealtime(), cb); }
if (typeof cb === "function") { Realtime.whenRealtimeSyncs(getRealtime(), cb); }
};
common.setAttribute = function (attr, value, cb) {
getStore().setAttribute(attr, value, function (err, data) {
@ -814,7 +813,7 @@ define([
}
if (getProxy().friends) {
var fList = common.getFriendChannelsList(common);
var fList = Messaging.getFriendChannelsList(common);
list = list.concat(fList);
}
@ -1018,7 +1017,7 @@ define([
var n = getNetwork();
var r = getRealtime();
if (n && r) {
whenRealtimeSyncs(r, function () {
Realtime.whenRealtimeSyncs(r, function () {
n.disconnect();
cb();
});
@ -1037,7 +1036,7 @@ define([
Cryptput(hash, data.toSave, function (e) {
if (e) { throw new Error(e); }
common.addTemplate(makePad(href, data.title));
whenRealtimeSyncs(getStore().getProxy().info.realtime, function () {
Realtime.whenRealtimeSyncs(getRealtime(), function () {
cb();
});
});
@ -1185,7 +1184,7 @@ define([
Nthen(function (waitFor) {
Store.ready(waitFor(function (err, storeObj) {
store = common.store = env.store = storeObj;
common.addDirectMessageHandler(common);
Messaging.addDirectMessageHandler(common);
proxy = getProxy();
network = getNetwork();
network.on('disconnect', function () {

View file

@ -18,6 +18,7 @@ define([
var sframeChan;
var FilePicker;
var Messenger;
var Messaging;
var Notifier;
var Utils = {};
@ -31,18 +32,20 @@ define([
'/common/sframe-channel.js',
'/filepicker/main.js',
'/common/common-messenger.js',
'/common/common-messaging.js',
'/common/common-notifier.js',
'/common/common-hash.js',
'/common/common-util.js',
'/common/common-realtime.js',
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel,
_FilePicker, _Messenger, _Notifier, _Hash, _Util, _Realtime) {
_FilePicker, _Messenger, _Messaging, _Notifier, _Hash, _Util, _Realtime) {
CpNfOuter = _CpNfOuter;
Cryptpad = _Cryptpad;
Crypto = _Crypto;
Cryptget = _Cryptget;
FilePicker = _FilePicker;
Messenger = _Messenger;
Messaging = _Messaging;
Notifier = _Notifier;
Utils.Hash = _Hash;
Utils.Util = _Util;
@ -246,7 +249,7 @@ define([
});
sframeChan.on('Q_SEND_FRIEND_REQUEST', function (netfluxId, cb) {
Cryptpad.inviteFromUserlist(Cryptpad, netfluxId);
Messaging.inviteFromUserlist(Cryptpad, netfluxId);
cb();
});
Cryptpad.onFriendRequest = function (confirmText, cb) {

View file

@ -3,9 +3,10 @@ define([
'/common/cryptpad-common.js',
'/common/login.js',
'/common/common-interface.js',
'/common/common-realtime.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
], function ($, Cryptpad, Login, UI) {
], function ($, Cryptpad, Login, UI, Realtime) {
$(function () {
var $main = $('#mainBlock');
var Messages = Cryptpad.Messages;
@ -83,7 +84,7 @@ define([
proxy.curvePublic = result.curvePublic;
Cryptpad.feedback('LOGIN', true);
Cryptpad.whenRealtimeSyncs(result.realtime, function() {
Realtime.whenRealtimeSyncs(result.realtime, function() {
Cryptpad.login(result.userHash, result.userName, function () {
hashing = false;
if (sessionStorage.redirectTo) {

View file

@ -8,6 +8,7 @@ define([
'/common/sframe-common.js',
'/common/common-util.js',
'/common/common-interface.js',
'/common/common-realtime.js',
'/bower_components/marked/marked.min.js',
'cm/lib/codemirror',
'cm/mode/markdown/markdown',
@ -28,6 +29,7 @@ define([
SFCommon,
Util,
UI,
Realtime,
Marked,
CodeMirror
)
@ -225,7 +227,7 @@ define([
}
var setValue = function (value, cb) {
APP.lm.proxy.name = value;
Cryptpad.whenRealtimeSyncs(APP.lm.realtime, cb);
Realtime.whenRealtimeSyncs(APP.lm.realtime, cb);
};
createEditableInput($block, DISPLAYNAME_ID, placeholder, getValue, setValue, Messages.anonymous);
};
@ -251,7 +253,7 @@ define([
}
var setValue = function (value, cb) {
APP.lm.proxy.url = value;
Cryptpad.whenRealtimeSyncs(APP.lm.realtime, cb);
Realtime.whenRealtimeSyncs(APP.lm.realtime, cb);
};
var placeholder = Messages.profile_urlPlaceholder;
createEditableInput($block, LINK_ID, placeholder, getValue, setValue);
@ -370,7 +372,7 @@ define([
$spinner.show();
var val = editor.getValue();
APP.lm.proxy.description = val;
Cryptpad.whenRealtimeSyncs(APP.lm.realtime, function () {
Realtime.whenRealtimeSyncs(APP.lm.realtime, function () {
$ok.show();
$spinner.hide();
});

View file

@ -6,9 +6,10 @@ define([
'/common/credential.js', // preloaded for login.js
'/common/common-interface.js',
'/common/common-util.js',
'/common/common-realtime.js',
'less!/bower_components/components-font-awesome/css/font-awesome.min.css',
], function ($, Login, Cryptpad, Test, Cred, UI, Util) {
], function ($, Login, Cryptpad, Test, Cred, UI, Util, Realtime) {
var Messages = Cryptpad.Messages;
$(function () {
@ -66,7 +67,7 @@ define([
Cryptpad.feedback('REGISTRATION', true);
Cryptpad.whenRealtimeSyncs(result.realtime, function () {
Realtime.whenRealtimeSyncs(result.realtime, function () {
Cryptpad.login(result.userHash, result.userName, function () {
registering = false;
if (sessionStorage.redirectTo) {

View file

@ -47,7 +47,7 @@ define([
}
});
*/
var addRpc = function (sframeChan, Cryptpad) {
var addRpc = function (sframeChan, Cryptpad, Utils) {
sframeChan.on('Q_THUMBNAIL_CLEAR', function (d, cb) {
Cryptpad.clearThumbnail(function (err, data) {
cb({err:err, data:data});
@ -69,7 +69,7 @@ define([
var proxy = Cryptpad.getProxy();
var realtime = Cryptpad.getRealtime();
proxy.drive = Cryptpad.getStore().getEmptyObject();
Cryptpad.whenRealtimeSyncs(realtime, cb);
Utils.Realtime.whenRealtimeSyncs(realtime, cb);
});
sframeChan.on('Q_SETTINGS_LOGOUT', function (data, cb) {
var proxy = Cryptpad.getProxy();
@ -77,7 +77,7 @@ define([
var token = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);
localStorage.setItem('loginToken', token);
proxy.loginToken = token;
Cryptpad.whenRealtimeSyncs(realtime, cb);
Utils.Realtime.whenRealtimeSyncs(realtime, cb);
});
sframeChan.on('Q_SETTINGS_IMPORT_LOCAL', function (data, cb) {
var proxyData = Cryptpad.getStore().getProxy();