Fix issues and replace chat module

pull/1/head
yflory 5 years ago
parent c6a4f78097
commit 641b69446d

@ -774,7 +774,7 @@ define([
edPublic: t.edPublic,
avatar: t.avatar,
id: id
}
};
});
var teamsList = UIElements.getFriendsList('Share with a team', {
common: common,

@ -40,7 +40,6 @@ define([
};
MessengerUI.create = function ($container, common, toolbar) {
var sframeChan = common.getSframeChannel();
var metadataMgr = common.getMetadataMgr();
var origin = metadataMgr.getPrivateData().origin;
var readOnly = metadataMgr.getPrivateData().readOnly;
@ -76,12 +75,17 @@ define([
]),
]);
var execCommand = function () {
console.warn(arguments);
};
/*
var execCommand = function (cmd, data, cb) {
sframeChan.query('Q_CHAT_COMMAND', {cmd: cmd, data: data}, function (err, obj) {
if (err || (obj && obj.error)) { return void cb(err || (obj && obj.error)); }
cb(void 0, obj);
});
};
*/
var $userlist = $(friendList).appendTo($container);
var $messages = $(messaging).appendTo($container);
@ -780,10 +784,6 @@ define([
// var onLeaveRoom
execCommand('GET_MY_INFO', null, function (e, info) {
contactsData[info.curvePublic] = info;
});
var ready = false;
var onMessengerReady = function () {
if (isApp) { return; }
@ -826,15 +826,8 @@ define([
$messages.find('.cp-app-contacts-input textarea').prop('disabled', false);
};
// Initialize chat when outer is ready (all channels loaded)
// TODO: try again in outer if fail to load a channel
if (!isApp) {
execCommand('INIT_FRIENDS', null, function () {});
execCommand('IS_READY', null, function (err, yes) {
if (yes) { onMessengerReady(); }
});
}
sframeChan.on('EV_CHAT_EVENT', function (obj) {
//sframeChan.on('EV_CHAT_EVENT', function (obj) {
var onEvent = function (obj) {
var cmd = obj.ev;
var data = obj.data;
if (cmd === 'READY') {
@ -881,8 +874,31 @@ define([
onUnfriend(data);
return;
}
};
var module = common.makeUniversal('messenger', {
onEvent: onEvent
});
execCommand = function (cmd, data, cb) {
module.execCommand(cmd, data, function (obj) {
if (obj && obj.error) { return void cb(obj.error); }
cb(void 0, obj);
});
};
//});
execCommand('GET_MY_INFO', null, function (e, info) {
contactsData[info.curvePublic] = info;
});
// Initialize chat when outer is ready (all channels loaded)
// TODO: try again in outer if fail to load a channel
if (!isApp) {
execCommand('INIT_FRIENDS', null, function () {
onMessengerReady();
});
}
};
return MessengerUI;
});

@ -9,7 +9,6 @@ define([
'/common/common-feedback.js',
'/common/common-realtime.js',
'/common/common-messaging.js',
'/common/common-messenger.js',
'/common/outer/sharedfolder.js',
'/common/outer/cursor.js',
'/common/outer/onlyoffice.js',
@ -27,8 +26,8 @@ define([
'/bower_components/nthen/index.js',
'/bower_components/saferphore/index.js',
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
Realtime, Messaging, Messenger,
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, _Messenger,
Realtime, Messaging,
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, Messenger,
NetConfig, AppConfig,
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
@ -1243,14 +1242,6 @@ define([
});
};
// Messenger
Store.messenger = {
execCommand: function (clientId, data, cb) {
if (!store.messenger) { return void cb({error: 'Messenger is disabled'}); }
store.messenger.execCommand(data, cb);
}
};
// OnlyOffice
Store.onlyoffice = {
execCommand: function (clientId, data, cb) {
@ -1755,7 +1746,6 @@ define([
// Clients management
var driveEventClients = [];
var messengerEventClients = [];
var dropChannel = function (chanId) {
try {
@ -1781,10 +1771,6 @@ define([
if (driveIdx !== -1) {
driveEventClients.splice(driveIdx, 1);
}
var messengerIdx = messengerEventClients.indexOf(clientId);
if (messengerIdx !== -1) {
messengerEventClients.splice(messengerIdx, 1);
}
try {
store.cursor.removeClient(clientId);
} catch (e) { console.error(e); }
@ -1875,28 +1861,6 @@ define([
}
};
var sendMessengerEvent = function (q, data) {
messengerEventClients.forEach(function (cId) {
postMessage(cId, q, data);
});
};
Store._subscribeToMessenger = function (clientId) {
if (messengerEventClients.indexOf(clientId) === -1) {
messengerEventClients.push(clientId);
}
};
var loadMessenger = function () {
if (AppConfig.availablePadTypes.indexOf('contacts') === -1) { return; }
var messenger = store.messenger = Messenger.messenger(store, function () {
broadcast([], "UPDATE_METADATA");
});
messenger.on('event', function (ev, data) {
sendMessengerEvent('CHAT_EVENT', {
ev: ev,
data: data
});
});
};
/*
var loadProfile = function (waitFor) {
@ -2027,10 +1991,10 @@ define([
});
userObject.fixFiles();
SF.loadSharedFolders(Store, store.network, store, userObject, waitFor);
loadMessenger();
loadCursor();
loadOnlyOffice();
loadUniversal(_Messenger, 'messenger', waitFor);
loadUniversal(Messenger, 'messenger', waitFor);
store.messenger = store.modules['messenger'];
loadUniversal(Profile, 'profile', waitFor);
loadUniversal(Team, 'team', waitFor);
cleanFriendRequests();

@ -160,8 +160,8 @@ define([
var setChannelHead = function (ctx, id, hash, cb) {
var channel = ctx.channels[id];
if (channel.friend) {
var friend = channel.friend;
if (channel.isFriendChat) {
var friend = getFriendFromChannel(ctx, id);
if (!friend) { return void cb({error: 'NO_SUCH_FRIEND'}); }
friend.lastKnownHash = hash;
} else if (channel.isPadChat) {
@ -292,7 +292,7 @@ define([
};
var onDirectMessage = function (ctx, msg, sender) {
var hk = ctx.store.etwork.historyKeeper;
var hk = ctx.store.network.historyKeeper;
if (sender !== hk) { return void onIdMessage(ctx, msg, sender); }
var parsed = JSON.parse(msg);
@ -356,7 +356,7 @@ define([
orderMessages(channel, decrypted);
req.cb(decrypted);
return deleteRangeRequest(txid);
return deleteRangeRequest(ctx, txid);
} else {
console.log(parsed);
}
@ -617,7 +617,7 @@ define([
clients: clientId ? [clientId] : ctx.friendsClients,
onReady: cb
};
openChannel(data);
openChannel(ctx, data);
};
var initFriends = function (ctx, clientId, cb) {
@ -750,7 +750,7 @@ define([
clients: [clientId],
onReady: cb
};
openChannel(chanData);
openChannel(ctx, chanData);
};
var clearOwnedChannel = function (ctx, id, cb) {
@ -882,7 +882,6 @@ define([
removeClient(ctx, clientId);
};
messenger.execCommand = function (clientId, obj, cb) {
console.log(obj);
var cmd = obj.cmd;
var data = obj.data;
if (cmd === 'INIT_FRIENDS') {

@ -54,9 +54,6 @@ define([
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
cb(data);
});
});

@ -75,9 +75,6 @@ var init = function (client, cb) {
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
return void cb(self.store);
}
@ -104,9 +101,6 @@ var init = function (client, cb) {
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
if (data && data.state === "ALREADY_INIT") {
self.store = data.returned;
return void cb(data.returned);

@ -75,9 +75,6 @@ var init = function (client, cb) {
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
return void cb(self.store);
}
@ -104,9 +101,6 @@ var init = function (client, cb) {
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
if (data && data.state === "ALREADY_INIT") {
self.store = data.returned;
return void cb(data.returned);

@ -59,8 +59,6 @@ define([
// Messaging
ANSWER_FRIEND_REQUEST: Store.answerFriendRequest,
SEND_FRIEND_REQUEST: Store.sendFriendRequest,
// Chat
CHAT_COMMAND: Store.messenger.execCommand,
// OnlyOffice
OO_COMMAND: Store.onlyoffice.execCommand,
// Cursor
@ -100,7 +98,6 @@ define([
// Internal calls
Rpc._removeClient = Store._removeClient;
Rpc._subscribeToDrive = Store._subscribeToDrive;
Rpc._subscribeToMessenger = Store._subscribeToMessenger;
return Rpc;
};

@ -63,9 +63,6 @@ require(['/api/config?cb=' + (+new Date()).toString(16)], function (ApiConfig) {
if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId);
}
if (cfg.messenger) {
Rpc._subscribeToMessenger(clientId);
}
cb(data);
});
});

@ -1091,20 +1091,25 @@ define([
Notifier.getPermission();
sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) {
Cryptpad.messenger.execCommand({
Cryptpad.universal.execCommand({
type: 'messenger',
data: {
cmd: 'OPEN_PAD_CHAT',
data: {
channel: data,
secret: secret
}
}
}, cb);
});
/* DEPRECATED
sframeChan.on('Q_CHAT_COMMAND', function (data, cb) {
Cryptpad.messenger.execCommand(data, cb);
});
Cryptpad.messenger.onEvent.reg(function (data) {
sframeChan.event('EV_CHAT_EVENT', data);
});
*/
}
// Chrome 68 on Mac contains a bug resulting in the page turning white after a few seconds

Loading…
Cancel
Save