From 5a2afb5c95224f4680cfe35d860ee27fb134e3e8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 13 Nov 2017 17:01:09 +0100 Subject: [PATCH] Remove Realtime and Messaging from common --- customize.dist/main.js | 8 +++---- www/common/common-messaging.js | 2 +- www/common/common-messenger.js | 15 ------------- www/common/common-realtime.js | 4 ++-- www/common/cryptpad-common.js | 37 +++++++++++++++---------------- www/common/sframe-common-outer.js | 7 ++++-- www/login/main.js | 5 +++-- www/profile/inner.js | 8 ++++--- www/register/main.js | 5 +++-- www/settings/main.js | 6 ++--- 10 files changed, 44 insertions(+), 53 deletions(-) diff --git a/customize.dist/main.js b/customize.dist/main.js index ce74a4d32..f0d310e67 100644 --- a/customize.dist/main.js +++ b/customize.dist/main.js @@ -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/'; }); diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js index e640b86a8..d9d376cbc 100644 --- a/www/common/common-messaging.js +++ b/www/common/common-messaging.js @@ -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); } diff --git a/www/common/common-messenger.js b/www/common/common-messenger.js index d8975420a..5e4a714a8 100644 --- a/www/common/common-messenger.js +++ b/www/common/common-messenger.js @@ -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; diff --git a/www/common/common-realtime.js b/www/common/common-realtime.js index 26c33c4d4..6480d7e6b 100644 --- a/www/common/common-realtime.js +++ b/www/common/common-realtime.js @@ -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; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index faf6577e5..cf72ba248 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -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 () { diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index e2f9ce53d..b7caec948 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -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) { diff --git a/www/login/main.js b/www/login/main.js index cf8075fcd..47e626753 100644 --- a/www/login/main.js +++ b/www/login/main.js @@ -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) { diff --git a/www/profile/inner.js b/www/profile/inner.js index 53ef82dbf..7acac0320 100644 --- a/www/profile/inner.js +++ b/www/profile/inner.js @@ -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(); }); diff --git a/www/register/main.js b/www/register/main.js index 7f6da1fb5..e88ea90ec 100644 --- a/www/register/main.js +++ b/www/register/main.js @@ -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) { diff --git a/www/settings/main.js b/www/settings/main.js index 32fe9f838..a7f8f5ef2 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -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();