diff --git a/move-merge-src.js b/move-merge-src.js index 2a5683584..e7e8cc251 100644 --- a/move-merge-src.js +++ b/move-merge-src.js @@ -16,7 +16,6 @@ const map = { './src/common/common-credential.js': './www/common/common-credential.js', './src/common/common-feedback.js': './www/common/common-feedback.js', './src/common/common-hash.js': './www/common/common-hash.js', - './src/common/common-messaging.js': './www/common/common-messaging.js', './src/common/common-realtime.js': './www/common/common-realtime.js', './src/common/common-signing-keys.js': './www/common/common-signing-keys.js', './src/common/common-util.js': './www/common/common-util.js', diff --git a/src/worker/async-store.js b/src/worker/async-store.js index 40355d419..aee254d0a 100644 --- a/src/worker/async-store.js +++ b/src/worker/async-store.js @@ -3453,7 +3453,7 @@ if (typeof(module) !== 'undefined' && module.exports) { require('../common/common-constants'), require('../common/common-feedback'), require('../common/common-realtime'), - require('../common/common-messaging'), + require('./components/messaging'), require('../common/pinpad'), require('../common/rpc'), require('./components/merge-drive'), @@ -3493,7 +3493,7 @@ if (typeof(module) !== 'undefined' && module.exports) { '/common/common-constants.js', // OK '/common/common-feedback.js', // OK '/common/common-realtime.js', // OK - '/common/common-messaging.js', // OK + '/common/outer/messaging.js', // OK '/common/pinpad.js', // OK '/common/rpc.js', // OK '/common/merge-drive.js', // OK diff --git a/src/worker/components/mailbox-handlers.js b/src/worker/components/mailbox-handlers.js index 3f918e519..f5b00b386 100644 --- a/src/worker/components/mailbox-handlers.js +++ b/src/worker/components/mailbox-handlers.js @@ -985,7 +985,7 @@ const factory = (Messaging, Hash, Util, Crypto, Block) => { if (typeof(module) !== 'undefined' && module.exports) { module.exports = factory( - require('../../common/common-messaging'), + require('./messaging'), require('../../common/common-hash'), require('../../common/common-util'), require('chainpad-crypto'), @@ -993,7 +993,7 @@ if (typeof(module) !== 'undefined' && module.exports) { ); } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { define([ - '/common/common-messaging.js', + '/common/outer/messaging.js', '/common/common-hash.js', '/common/common-util.js', '/components/chainpad-crypto/crypto.js', diff --git a/src/common/common-messaging.js b/src/worker/components/messaging.js similarity index 96% rename from src/common/common-messaging.js rename to src/worker/components/messaging.js index f9b7fde24..5fe20f0e7 100644 --- a/src/common/common-messaging.js +++ b/src/worker/components/messaging.js @@ -142,10 +142,10 @@ const factory = (Crypto, Hash, Util, Constants, Realtime) => { if (typeof(module) !== 'undefined' && module.exports) { module.exports = factory( require('chainpad-crypto'), - require('./common-hash'), - require('./common-util'), - require('./common-constants'), - require('./common-realtime') + require('../../common/common-hash'), + require('../../common/common-util'), + require('../../common/common-constants'), + require('../../common/common-realtime') ); } else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { define([ diff --git a/src/worker/components/migrate-user-object.js b/src/worker/components/migrate-user-object.js index 638c062a6..23ef1103a 100644 --- a/src/worker/components/migrate-user-object.js +++ b/src/worker/components/migrate-user-object.js @@ -512,7 +512,7 @@ if (typeof(module) !== 'undefined' && module.exports) { require('../../common/common-feedback'), require('../../common/common-hash'), require('../../common/common-util'), - require('../../common/common-messaging'), + require('./messaging'), require('../../common/cryptget'), require('../modules/mailbox'), undefined, @@ -525,7 +525,7 @@ if (typeof(module) !== 'undefined' && module.exports) { '/common/common-feedback.js', '/common/common-hash.js', '/common/common-util.js', - '/common/common-messaging.js', + '/common/outer/messaging.js', '/common/cryptget.js', '/common/outer/mailbox.js', '/customize/messages.js', diff --git a/src/worker/modules/mailbox.js b/src/worker/modules/mailbox.js index 42e6d5a24..e47a77007 100644 --- a/src/worker/modules/mailbox.js +++ b/src/worker/modules/mailbox.js @@ -679,7 +679,7 @@ if (typeof(module) !== 'undefined' && module.exports) { require('../../common/common-util'), require('../../common/common-hash'), require('../../common/common-realtime'), - require('../../common/common-messaging'), + require('../components/messaging'), require('../../common/notify'), require('../components/mailbox-handlers'), require('chainpad-netflux'), @@ -691,7 +691,7 @@ if (typeof(module) !== 'undefined' && module.exports) { '/common/common-util.js', '/common/common-hash.js', '/common/common-realtime.js', - '/common/common-messaging.js', + '/common/outer/messaging.js', '/common/notify.js', '/common/outer/mailbox-handlers.js', 'chainpad-netflux', diff --git a/src/worker/modules/messenger.js b/src/worker/modules/messenger.js index 30cf1908d..281fc13d5 100644 --- a/src/worker/modules/messenger.js +++ b/src/worker/modules/messenger.js @@ -1126,7 +1126,7 @@ if (typeof(module) !== 'undefined' && module.exports) { require('../../common/common-hash'), require('../../common/common-util'), require('../../common/common-realtime'), - require('../../common/common-messaging'), + require('../components/messaging'), require('../../common/common-constants'), undefined, require('../../common/pad-types'), @@ -1138,7 +1138,7 @@ if (typeof(module) !== 'undefined' && module.exports) { '/common/common-hash.js', '/common/common-util.js', '/common/common-realtime.js', - '/common/common-messaging.js', + '/common/outer/messaging.js', '/common/common-constants.js', '/customize/messages.js', '/common/pad-types.js', diff --git a/src/worker/modules/team.js b/src/worker/modules/team.js index 1e27ab1dd..07ae8834f 100644 --- a/src/worker/modules/team.js +++ b/src/worker/modules/team.js @@ -2237,7 +2237,7 @@ if (typeof(module) !== 'undefined' && module.exports) { require('../../common/user-object'), require('../components/sharedfolder'), require('../components/roster'), - require('../../common/common-messaging'), + require('../components/messaging'), require('../../common/common-feedback'), require('../components/invitation'), require('../../common/cryptget'), @@ -2262,7 +2262,7 @@ if (typeof(module) !== 'undefined' && module.exports) { '/common/user-object.js', '/common/outer/sharedfolder.js', '/common/outer/roster.js', - '/common/common-messaging.js', + '/common/outer/messaging.js', '/common/common-feedback.js', '/common/outer/invitation.js', '/common/cryptget.js', diff --git a/src/worker/store.ts b/src/worker/store.ts index e02087423..6e71a912c 100644 --- a/src/worker/store.ts +++ b/src/worker/store.ts @@ -11,7 +11,6 @@ import * as Util from '../common/common-util.js'; import * as Hash from '../common/common-hash.js'; import * as Feedback from '../common/common-feedback.js'; import * as Realtime from '../common/common-realtime.js'; -import * as Messaging from '../common/common-messaging.js'; import * as Constants from '../common/common-constants.js'; import * as Credential from '../common/common-credential.js'; import * as ProxyManager from '../common/proxy-manager.js'; @@ -32,6 +31,7 @@ import * as AsyncConnector from './core/async-connector.js'; // Components import * as Migrate from './components/migrate-user-object.js'; +import * as Messaging from './components/messaging.js'; // Modules import * as Mailbox from './modules/mailbox.js'; diff --git a/www/common/common-messaging.js b/www/common/common-messaging.js deleted file mode 100644 index f9b7fde24..000000000 --- a/www/common/common-messaging.js +++ /dev/null @@ -1,161 +0,0 @@ -// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -(() => { -const factory = (Crypto, Hash, Util, Constants, Realtime) => { - var Msg = {}; - - var createData = Msg.createData = function (proxy, hash) { - var data = { - channel: hash || Hash.createChannelId(), - displayName: proxy['cryptpad.username'], - profile: proxy.profile && proxy.profile.view, - edPublic: proxy.edPublic, - curvePublic: proxy.curvePublic, - notifications: Util.find(proxy, ['mailboxes', 'notifications', 'channel']), - avatar: proxy.profile && proxy.profile.avatar, - uid: proxy.uid, - }; - if (hash === false) { delete data.channel; } - return data; - }; - - var getFriend = Msg.getFriend = function (proxy, pubkey) { - if (!pubkey) { return; } - if (pubkey === proxy.curvePublic) { - var data = createData(proxy); - delete data.channel; - return data; - } - return proxy.friends ? proxy.friends[pubkey] : undefined; - }; - - var getFriendList = Msg.getFriendList = function (proxy) { - if (!proxy.friends) { proxy.friends = {}; } - 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.friends, function (friend) { - list.push(friend.channel); - }); - return list; - }; - - Msg.declineFriendRequest = function (store, data, cb) { - store.mailbox.sendTo('DECLINE_FRIEND_REQUEST', {}, { - channel: data.notifications, - curvePublic: data.curvePublic - }, function (obj) { - cb(obj); - }); - }; - Msg.acceptFriendRequest = function (store, data, cb) { - var friend = getFriend(store.proxy, data.curvePublic) || {}; - var myData = createData(store.proxy, friend.channel || data.channel); - store.mailbox.sendTo('ACCEPT_FRIEND_REQUEST', { user: myData }, { - channel: data.notifications, - curvePublic: data.curvePublic - }, function (obj) { - cb(obj); - }); - }; - Msg.addToFriendList = function (cfg, data, cb) { - var proxy = cfg.proxy; - var friends = getFriendList(proxy); - var pubKey = data.curvePublic; // todo validata data - - if (pubKey === proxy.curvePublic) { return void cb("E_MYKEY"); } - - friends[pubKey] = data; - - Realtime.whenRealtimeSyncs(cfg.realtime, function () { - cb(); - cfg.pinPads([data.channel], function (res) { - if (res.error) { console.error(res.error); } - }); - }); - }; - - Msg.updateMyData = function (store, curve) { - var myData = createData(store.proxy, false); - if (store.proxy.friends) { - store.proxy.friends.me = Util.clone(myData); - delete store.proxy.friends.me.channel; - } - if (store.modules['team']) { - store.modules['team'].updateMyData(myData); - } - var todo = function (friend) { - if (!friend || !friend.notifications) { return; } - delete friend.user; - myData.channel = friend.channel; - store.mailbox.sendTo('UPDATE_DATA', myData, { - channel: friend.notifications, - curvePublic: friend.curvePublic - }, function (obj) { - if (obj && obj.error) { console.error(obj); } - }); - }; - if (curve) { - var friend = getFriend(store.proxy, curve); - return void todo(friend); - } - eachFriend(store.proxy.friends || {}, todo); - }; - - Msg.removeFriend = function (store, curvePublic, cb) { - var proxy = store.proxy; - var friend = proxy.friends[curvePublic]; - if (!friend) { return void cb({error: 'ENOENT'}); } - if (!friend.notifications) { return void cb({error: 'EINVAL'}); } - - store.mailbox.sendTo('UNFRIEND', { - curvePublic: proxy.curvePublic - }, { - channel: friend.notifications, - curvePublic: friend.curvePublic - }, function (obj) { - if (obj && obj.error) { - return void cb(obj); - } - store.messenger.onFriendRemoved(curvePublic, friend.channel); - delete proxy.friends[curvePublic]; - Realtime.whenRealtimeSyncs(store.realtime, function () { - cb(obj); - }); - }); - }; - - return Msg; -}; - -if (typeof(module) !== 'undefined' && module.exports) { - module.exports = factory( - require('chainpad-crypto'), - require('./common-hash'), - require('./common-util'), - require('./common-constants'), - require('./common-realtime') - ); -} else if ((typeof(define) !== 'undefined' && define !== null) && (define.amd !== null)) { - define([ - '/components/chainpad-crypto/crypto.js', - '/common/common-hash.js', - '/common/common-util.js', - '/common/common-constants.js', - '/common/common-realtime.js', - ], factory); -} else { - // unsupported initialization -} -})(); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 934c02e43..1ef3b3246 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -9,7 +9,6 @@ define([ '/common/common-util.js', '/common/common-hash.js', '/common/outer/cache-store.js', - '/common/common-messaging.js', '/common/common-constants.js', '/common/common-feedback.js', '/common/visible.js', @@ -25,7 +24,7 @@ define([ '/components/nthen/index.js', '/components/tweetnacl/nacl-fast.min.js' ], function (Config, Broadcast, Messages, Util, Hash, Cache, - Messaging, Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block, + Constants, Feedback, Visible, UserObject, LocalStore, Channel, Block, Cred, Login, Store, AppConfig, nThen) { /* This file exposes functionality which is specific to Cryptpad, but not to