Fix issues and replace chat module
This commit is contained in:
parent
c6a4f78097
commit
641b69446d
@ -774,7 +774,7 @@ define([
|
|||||||
edPublic: t.edPublic,
|
edPublic: t.edPublic,
|
||||||
avatar: t.avatar,
|
avatar: t.avatar,
|
||||||
id: id
|
id: id
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
var teamsList = UIElements.getFriendsList('Share with a team', {
|
var teamsList = UIElements.getFriendsList('Share with a team', {
|
||||||
common: common,
|
common: common,
|
||||||
|
|||||||
@ -40,7 +40,6 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
MessengerUI.create = function ($container, common, toolbar) {
|
MessengerUI.create = function ($container, common, toolbar) {
|
||||||
var sframeChan = common.getSframeChannel();
|
|
||||||
var metadataMgr = common.getMetadataMgr();
|
var metadataMgr = common.getMetadataMgr();
|
||||||
var origin = metadataMgr.getPrivateData().origin;
|
var origin = metadataMgr.getPrivateData().origin;
|
||||||
var readOnly = metadataMgr.getPrivateData().readOnly;
|
var readOnly = metadataMgr.getPrivateData().readOnly;
|
||||||
@ -76,12 +75,17 @@ define([
|
|||||||
]),
|
]),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
var execCommand = function () {
|
||||||
|
console.warn(arguments);
|
||||||
|
};
|
||||||
|
/*
|
||||||
var execCommand = function (cmd, data, cb) {
|
var execCommand = function (cmd, data, cb) {
|
||||||
sframeChan.query('Q_CHAT_COMMAND', {cmd: cmd, data: data}, function (err, obj) {
|
sframeChan.query('Q_CHAT_COMMAND', {cmd: cmd, data: data}, function (err, obj) {
|
||||||
if (err || (obj && obj.error)) { return void cb(err || (obj && obj.error)); }
|
if (err || (obj && obj.error)) { return void cb(err || (obj && obj.error)); }
|
||||||
cb(void 0, obj);
|
cb(void 0, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
var $userlist = $(friendList).appendTo($container);
|
var $userlist = $(friendList).appendTo($container);
|
||||||
var $messages = $(messaging).appendTo($container);
|
var $messages = $(messaging).appendTo($container);
|
||||||
@ -780,10 +784,6 @@ define([
|
|||||||
// var onLeaveRoom
|
// var onLeaveRoom
|
||||||
|
|
||||||
|
|
||||||
execCommand('GET_MY_INFO', null, function (e, info) {
|
|
||||||
contactsData[info.curvePublic] = info;
|
|
||||||
});
|
|
||||||
|
|
||||||
var ready = false;
|
var ready = false;
|
||||||
var onMessengerReady = function () {
|
var onMessengerReady = function () {
|
||||||
if (isApp) { return; }
|
if (isApp) { return; }
|
||||||
@ -826,15 +826,8 @@ define([
|
|||||||
$messages.find('.cp-app-contacts-input textarea').prop('disabled', false);
|
$messages.find('.cp-app-contacts-input textarea').prop('disabled', false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize chat when outer is ready (all channels loaded)
|
//sframeChan.on('EV_CHAT_EVENT', function (obj) {
|
||||||
// TODO: try again in outer if fail to load a channel
|
var onEvent = function (obj) {
|
||||||
if (!isApp) {
|
|
||||||
execCommand('INIT_FRIENDS', null, function () {});
|
|
||||||
execCommand('IS_READY', null, function (err, yes) {
|
|
||||||
if (yes) { onMessengerReady(); }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
sframeChan.on('EV_CHAT_EVENT', function (obj) {
|
|
||||||
var cmd = obj.ev;
|
var cmd = obj.ev;
|
||||||
var data = obj.data;
|
var data = obj.data;
|
||||||
if (cmd === 'READY') {
|
if (cmd === 'READY') {
|
||||||
@ -881,7 +874,30 @@ define([
|
|||||||
onUnfriend(data);
|
onUnfriend(data);
|
||||||
return;
|
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;
|
return MessengerUI;
|
||||||
|
|||||||
@ -9,7 +9,6 @@ define([
|
|||||||
'/common/common-feedback.js',
|
'/common/common-feedback.js',
|
||||||
'/common/common-realtime.js',
|
'/common/common-realtime.js',
|
||||||
'/common/common-messaging.js',
|
'/common/common-messaging.js',
|
||||||
'/common/common-messenger.js',
|
|
||||||
'/common/outer/sharedfolder.js',
|
'/common/outer/sharedfolder.js',
|
||||||
'/common/outer/cursor.js',
|
'/common/outer/cursor.js',
|
||||||
'/common/outer/onlyoffice.js',
|
'/common/outer/onlyoffice.js',
|
||||||
@ -27,8 +26,8 @@ define([
|
|||||||
'/bower_components/nthen/index.js',
|
'/bower_components/nthen/index.js',
|
||||||
'/bower_components/saferphore/index.js',
|
'/bower_components/saferphore/index.js',
|
||||||
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
|
], function (Sortify, UserObject, ProxyManager, Migrate, Hash, Util, Constants, Feedback,
|
||||||
Realtime, Messaging, Messenger,
|
Realtime, Messaging,
|
||||||
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, _Messenger,
|
SF, Cursor, OnlyOffice, Mailbox, Profile, Team, Messenger,
|
||||||
NetConfig, AppConfig,
|
NetConfig, AppConfig,
|
||||||
Crypto, ChainPad, CpNetflux, Listmap, nThen, Saferphore) {
|
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
|
// OnlyOffice
|
||||||
Store.onlyoffice = {
|
Store.onlyoffice = {
|
||||||
execCommand: function (clientId, data, cb) {
|
execCommand: function (clientId, data, cb) {
|
||||||
@ -1755,7 +1746,6 @@ define([
|
|||||||
|
|
||||||
// Clients management
|
// Clients management
|
||||||
var driveEventClients = [];
|
var driveEventClients = [];
|
||||||
var messengerEventClients = [];
|
|
||||||
|
|
||||||
var dropChannel = function (chanId) {
|
var dropChannel = function (chanId) {
|
||||||
try {
|
try {
|
||||||
@ -1781,10 +1771,6 @@ define([
|
|||||||
if (driveIdx !== -1) {
|
if (driveIdx !== -1) {
|
||||||
driveEventClients.splice(driveIdx, 1);
|
driveEventClients.splice(driveIdx, 1);
|
||||||
}
|
}
|
||||||
var messengerIdx = messengerEventClients.indexOf(clientId);
|
|
||||||
if (messengerIdx !== -1) {
|
|
||||||
messengerEventClients.splice(messengerIdx, 1);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
store.cursor.removeClient(clientId);
|
store.cursor.removeClient(clientId);
|
||||||
} catch (e) { console.error(e); }
|
} 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) {
|
var loadProfile = function (waitFor) {
|
||||||
@ -2027,10 +1991,10 @@ define([
|
|||||||
});
|
});
|
||||||
userObject.fixFiles();
|
userObject.fixFiles();
|
||||||
SF.loadSharedFolders(Store, store.network, store, userObject, waitFor);
|
SF.loadSharedFolders(Store, store.network, store, userObject, waitFor);
|
||||||
loadMessenger();
|
|
||||||
loadCursor();
|
loadCursor();
|
||||||
loadOnlyOffice();
|
loadOnlyOffice();
|
||||||
loadUniversal(_Messenger, 'messenger', waitFor);
|
loadUniversal(Messenger, 'messenger', waitFor);
|
||||||
|
store.messenger = store.modules['messenger'];
|
||||||
loadUniversal(Profile, 'profile', waitFor);
|
loadUniversal(Profile, 'profile', waitFor);
|
||||||
loadUniversal(Team, 'team', waitFor);
|
loadUniversal(Team, 'team', waitFor);
|
||||||
cleanFriendRequests();
|
cleanFriendRequests();
|
||||||
|
|||||||
@ -160,8 +160,8 @@ define([
|
|||||||
|
|
||||||
var setChannelHead = function (ctx, id, hash, cb) {
|
var setChannelHead = function (ctx, id, hash, cb) {
|
||||||
var channel = ctx.channels[id];
|
var channel = ctx.channels[id];
|
||||||
if (channel.friend) {
|
if (channel.isFriendChat) {
|
||||||
var friend = channel.friend;
|
var friend = getFriendFromChannel(ctx, id);
|
||||||
if (!friend) { return void cb({error: 'NO_SUCH_FRIEND'}); }
|
if (!friend) { return void cb({error: 'NO_SUCH_FRIEND'}); }
|
||||||
friend.lastKnownHash = hash;
|
friend.lastKnownHash = hash;
|
||||||
} else if (channel.isPadChat) {
|
} else if (channel.isPadChat) {
|
||||||
@ -292,7 +292,7 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var onDirectMessage = function (ctx, msg, sender) {
|
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); }
|
if (sender !== hk) { return void onIdMessage(ctx, msg, sender); }
|
||||||
var parsed = JSON.parse(msg);
|
var parsed = JSON.parse(msg);
|
||||||
|
|
||||||
@ -356,7 +356,7 @@ define([
|
|||||||
|
|
||||||
orderMessages(channel, decrypted);
|
orderMessages(channel, decrypted);
|
||||||
req.cb(decrypted);
|
req.cb(decrypted);
|
||||||
return deleteRangeRequest(txid);
|
return deleteRangeRequest(ctx, txid);
|
||||||
} else {
|
} else {
|
||||||
console.log(parsed);
|
console.log(parsed);
|
||||||
}
|
}
|
||||||
@ -617,7 +617,7 @@ define([
|
|||||||
clients: clientId ? [clientId] : ctx.friendsClients,
|
clients: clientId ? [clientId] : ctx.friendsClients,
|
||||||
onReady: cb
|
onReady: cb
|
||||||
};
|
};
|
||||||
openChannel(data);
|
openChannel(ctx, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
var initFriends = function (ctx, clientId, cb) {
|
var initFriends = function (ctx, clientId, cb) {
|
||||||
@ -750,7 +750,7 @@ define([
|
|||||||
clients: [clientId],
|
clients: [clientId],
|
||||||
onReady: cb
|
onReady: cb
|
||||||
};
|
};
|
||||||
openChannel(chanData);
|
openChannel(ctx, chanData);
|
||||||
};
|
};
|
||||||
|
|
||||||
var clearOwnedChannel = function (ctx, id, cb) {
|
var clearOwnedChannel = function (ctx, id, cb) {
|
||||||
@ -882,7 +882,6 @@ define([
|
|||||||
removeClient(ctx, clientId);
|
removeClient(ctx, clientId);
|
||||||
};
|
};
|
||||||
messenger.execCommand = function (clientId, obj, cb) {
|
messenger.execCommand = function (clientId, obj, cb) {
|
||||||
console.log(obj);
|
|
||||||
var cmd = obj.cmd;
|
var cmd = obj.cmd;
|
||||||
var data = obj.data;
|
var data = obj.data;
|
||||||
if (cmd === 'INIT_FRIENDS') {
|
if (cmd === 'INIT_FRIENDS') {
|
||||||
|
|||||||
@ -54,9 +54,6 @@ define([
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
cb(data);
|
cb(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -75,9 +75,6 @@ var init = function (client, cb) {
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
return void cb(self.store);
|
return void cb(self.store);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +101,6 @@ var init = function (client, cb) {
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
if (data && data.state === "ALREADY_INIT") {
|
if (data && data.state === "ALREADY_INIT") {
|
||||||
self.store = data.returned;
|
self.store = data.returned;
|
||||||
return void cb(data.returned);
|
return void cb(data.returned);
|
||||||
|
|||||||
@ -75,9 +75,6 @@ var init = function (client, cb) {
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
return void cb(self.store);
|
return void cb(self.store);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,9 +101,6 @@ var init = function (client, cb) {
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
if (data && data.state === "ALREADY_INIT") {
|
if (data && data.state === "ALREADY_INIT") {
|
||||||
self.store = data.returned;
|
self.store = data.returned;
|
||||||
return void cb(data.returned);
|
return void cb(data.returned);
|
||||||
|
|||||||
@ -59,8 +59,6 @@ define([
|
|||||||
// Messaging
|
// Messaging
|
||||||
ANSWER_FRIEND_REQUEST: Store.answerFriendRequest,
|
ANSWER_FRIEND_REQUEST: Store.answerFriendRequest,
|
||||||
SEND_FRIEND_REQUEST: Store.sendFriendRequest,
|
SEND_FRIEND_REQUEST: Store.sendFriendRequest,
|
||||||
// Chat
|
|
||||||
CHAT_COMMAND: Store.messenger.execCommand,
|
|
||||||
// OnlyOffice
|
// OnlyOffice
|
||||||
OO_COMMAND: Store.onlyoffice.execCommand,
|
OO_COMMAND: Store.onlyoffice.execCommand,
|
||||||
// Cursor
|
// Cursor
|
||||||
@ -100,7 +98,6 @@ define([
|
|||||||
// Internal calls
|
// Internal calls
|
||||||
Rpc._removeClient = Store._removeClient;
|
Rpc._removeClient = Store._removeClient;
|
||||||
Rpc._subscribeToDrive = Store._subscribeToDrive;
|
Rpc._subscribeToDrive = Store._subscribeToDrive;
|
||||||
Rpc._subscribeToMessenger = Store._subscribeToMessenger;
|
|
||||||
|
|
||||||
return Rpc;
|
return Rpc;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -63,9 +63,6 @@ require(['/api/config?cb=' + (+new Date()).toString(16)], function (ApiConfig) {
|
|||||||
if (cfg.driveEvents) {
|
if (cfg.driveEvents) {
|
||||||
Rpc._subscribeToDrive(clientId);
|
Rpc._subscribeToDrive(clientId);
|
||||||
}
|
}
|
||||||
if (cfg.messenger) {
|
|
||||||
Rpc._subscribeToMessenger(clientId);
|
|
||||||
}
|
|
||||||
cb(data);
|
cb(data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1091,20 +1091,25 @@ define([
|
|||||||
Notifier.getPermission();
|
Notifier.getPermission();
|
||||||
|
|
||||||
sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) {
|
sframeChan.on('Q_CHAT_OPENPADCHAT', function (data, cb) {
|
||||||
Cryptpad.messenger.execCommand({
|
Cryptpad.universal.execCommand({
|
||||||
cmd: 'OPEN_PAD_CHAT',
|
type: 'messenger',
|
||||||
data: {
|
data: {
|
||||||
channel: data,
|
cmd: 'OPEN_PAD_CHAT',
|
||||||
secret: secret
|
data: {
|
||||||
|
channel: data,
|
||||||
|
secret: secret
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, cb);
|
}, cb);
|
||||||
});
|
});
|
||||||
|
/* DEPRECATED
|
||||||
sframeChan.on('Q_CHAT_COMMAND', function (data, cb) {
|
sframeChan.on('Q_CHAT_COMMAND', function (data, cb) {
|
||||||
Cryptpad.messenger.execCommand(data, cb);
|
Cryptpad.messenger.execCommand(data, cb);
|
||||||
});
|
});
|
||||||
Cryptpad.messenger.onEvent.reg(function (data) {
|
Cryptpad.messenger.onEvent.reg(function (data) {
|
||||||
sframeChan.event('EV_CHAT_EVENT', data);
|
sframeChan.event('EV_CHAT_EVENT', data);
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chrome 68 on Mac contains a bug resulting in the page turning white after a few seconds
|
// Chrome 68 on Mac contains a bug resulting in the page turning white after a few seconds
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user