Profile refactoring with friend request
This commit is contained in:
@@ -659,6 +659,14 @@ define([
|
||||
};
|
||||
mailbox.onEvent = Util.mkEvent();
|
||||
|
||||
// Universal
|
||||
var universal = common.universal = {};
|
||||
universal.execCommand = function (data, cb) {
|
||||
postMessage("UNIVERSAL_COMMAND", data, cb);
|
||||
};
|
||||
universal.onEvent = Util.mkEvent();
|
||||
|
||||
|
||||
// Pad RPC
|
||||
var pad = common.padRpc = {};
|
||||
pad.joinPad = function (data) {
|
||||
@@ -1097,6 +1105,8 @@ define([
|
||||
CURSOR_EVENT: common.cursor.onEvent.fire,
|
||||
// Mailbox
|
||||
MAILBOX_EVENT: common.mailbox.onEvent.fire,
|
||||
// Universal
|
||||
UNIVERSAL_EVENT: common.universal.onEvent.fire,
|
||||
// Pad
|
||||
PAD_READY: common.padRpc.onReadyEvent.fire,
|
||||
PAD_MESSAGE: common.padRpc.onMessageEvent.fire,
|
||||
|
||||
@@ -13,6 +13,7 @@ define([
|
||||
'/common/outer/cursor.js',
|
||||
'/common/outer/onlyoffice.js',
|
||||
'/common/outer/mailbox.js',
|
||||
'/common/outer/profile.js',
|
||||
'/common/outer/network-config.js',
|
||||
'/customize/application_config.js',
|
||||
|
||||
@@ -23,7 +24,7 @@ define([
|
||||
'/bower_components/nthen/index.js',
|
||||
'/bower_components/saferphore/index.js',
|
||||
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback, Realtime, Messaging, Messenger,
|
||||
Cursor, OnlyOffice, Mailbox, NetConfig, AppConfig,
|
||||
Cursor, OnlyOffice, Mailbox, Profile, NetConfig, AppConfig,
|
||||
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
||||
|
||||
var create = function () {
|
||||
@@ -35,7 +36,9 @@ define([
|
||||
|
||||
var storeHash;
|
||||
|
||||
var store = window.CryptPad_AsyncStore = {};
|
||||
var store = window.CryptPad_AsyncStore = {
|
||||
modules: {}
|
||||
};
|
||||
|
||||
var onSync = function (cb) {
|
||||
nThen(function (waitFor) {
|
||||
@@ -656,6 +659,9 @@ define([
|
||||
});
|
||||
});*/
|
||||
}
|
||||
if (store.profile) {
|
||||
store.profile.setName(value);
|
||||
}
|
||||
store.proxy[Constants.displayNameKey] = value;
|
||||
broadcast([clientId], "UPDATE_METADATA");
|
||||
if (store.messenger) { store.messenger.updateMyData(); }
|
||||
@@ -994,6 +1000,39 @@ define([
|
||||
cb();
|
||||
};
|
||||
|
||||
// Universal
|
||||
Store.universal = {
|
||||
execCommand: function (clientId, obj, cb) {
|
||||
var type = obj.type;
|
||||
var data = obj.data;
|
||||
if (store.modules[type]) {
|
||||
store.modules[type].execCommand(clientId, data, cb);
|
||||
} else {
|
||||
return void cb({error: type + ' is disabled'});
|
||||
}
|
||||
}
|
||||
};
|
||||
var loadUniversal = function (Module, type, waitFor) {
|
||||
if (store.modules[type]) { return; }
|
||||
store.modules[type] = Module.init({
|
||||
store: store,
|
||||
updateMetadata: function () {
|
||||
broadcast([], "UPDATE_METADATA");
|
||||
},
|
||||
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
|
||||
}, waitFor, function (ev, data, clients) {
|
||||
clients.forEach(function (cId) {
|
||||
postMessage(cId, 'UNIVERSAL_EVENT', {
|
||||
type: type,
|
||||
data: {
|
||||
ev: ev,
|
||||
data: data
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Messenger
|
||||
Store.messenger = {
|
||||
execCommand: function (clientId, data, cb) {
|
||||
@@ -1394,6 +1433,11 @@ define([
|
||||
try {
|
||||
store.mailbox.removeClient(clientId);
|
||||
} catch (e) { console.error(e); }
|
||||
Object.keys(store.modules).forEach(function (key) {
|
||||
try {
|
||||
store.modules[key].removeClient(clientId);
|
||||
} catch (e) { console.error(e); }
|
||||
});
|
||||
|
||||
Object.keys(Store.channels).forEach(function (chanId) {
|
||||
var chanIdx = Store.channels[chanId].clients.indexOf(clientId);
|
||||
@@ -1469,6 +1513,24 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
var loadProfile = function (waitFor) {
|
||||
store.profile = Profile.init({
|
||||
store: store,
|
||||
updateMetadata: function () {
|
||||
broadcast([], "UPDATE_METADATA");
|
||||
},
|
||||
pinPads: function (data, cb) { Store.pinPads(null, data, cb); },
|
||||
}, waitFor, function (ev, data, clients) {
|
||||
clients.forEach(function (cId) {
|
||||
postMessage(cId, 'PROFILE_EVENT', {
|
||||
ev: ev,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
*/
|
||||
var loadCursor = function () {
|
||||
store.cursor = Cursor.init(store, function (ev, data, clients) {
|
||||
clients.forEach(function (cId) {
|
||||
@@ -1618,6 +1680,7 @@ define([
|
||||
loadCursor();
|
||||
loadOnlyOffice();
|
||||
loadMailbox(waitFor);
|
||||
loadUniversal(Profile, 'profile', waitFor);
|
||||
cleanFriendRequests();
|
||||
}).nThen(function () {
|
||||
var requestLogin = function () {
|
||||
|
||||
@@ -68,6 +68,8 @@ define([
|
||||
CURSOR_COMMAND: Store.cursor.execCommand,
|
||||
// Mailbox
|
||||
MAILBOX_COMMAND: Store.mailbox.execCommand,
|
||||
// Universal
|
||||
UNIVERSAL_COMMAND: Store.universal.execCommand,
|
||||
// Pad
|
||||
SEND_PAD_MSG: Store.sendPadMsg,
|
||||
JOIN_PAD: Store.joinPad,
|
||||
|
||||
@@ -329,7 +329,7 @@ define([
|
||||
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
|
||||
|
||||
if (cfg.addData) {
|
||||
cfg.addData(metaObj.priv, Cryptpad);
|
||||
cfg.addData(metaObj.priv, Cryptpad, metaObj.user);
|
||||
}
|
||||
|
||||
sframeChan.event('EV_METADATA_UPDATE', metaObj);
|
||||
@@ -872,6 +872,13 @@ define([
|
||||
Cryptpad.cursor.execCommand(data, cb);
|
||||
});
|
||||
|
||||
Cryptpad.universal.onEvent.reg(function (data) {
|
||||
sframeChan.event('EV_UNIVERSAL_EVENT', data);
|
||||
});
|
||||
sframeChan.on('Q_UNIVERSAL_COMMAND', function (data, cb) {
|
||||
Cryptpad.universal.execCommand(data, cb);
|
||||
});
|
||||
|
||||
Cryptpad.mailbox.onEvent.reg(function (data) {
|
||||
sframeChan.event('EV_MAILBOX_EVENT', data);
|
||||
});
|
||||
|
||||
@@ -168,6 +168,31 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
// Universal direct channel
|
||||
var modules = {};
|
||||
funcs.makeUniversal = function (type, cfg) {
|
||||
if (modules[type]) { return; }
|
||||
var sframeChan = funcs.getSframeChannel();
|
||||
modules[type] = {
|
||||
onEvent: cfg.onEvent || function () {}
|
||||
};
|
||||
return {
|
||||
execCommand: function (cmd, data, cb) {
|
||||
sframeChan.query("Q_UNIVERSAL_COMMAND", {
|
||||
type: type,
|
||||
data: {
|
||||
cmd: cmd,
|
||||
data: data
|
||||
}
|
||||
}, function (err, obj) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
cb(obj);
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
// Chat
|
||||
var padChatChannel;
|
||||
// common-ui-elements needs to be able to get the chat channel to put it in metadata when
|
||||
@@ -575,6 +600,12 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
ctx.sframeChan.on('EV_UNIVERSAL_EVENT', function (obj) {
|
||||
var type = obj.type;
|
||||
if (!type || !modules[type]) { return; }
|
||||
modules[type].onEvent(obj.data);
|
||||
});
|
||||
|
||||
ctx.metadataMgr.onReady(waitFor());
|
||||
|
||||
funcs.addShortcuts();
|
||||
|
||||
Reference in New Issue
Block a user