From c18d4297e17f0a76eb5204b0b9e3d909b4c90226 Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 15 Dec 2017 16:19:22 +0100 Subject: [PATCH] Fix friend requests from the userlist --- www/common/cryptpad-common.js | 11 +++++++---- www/common/outer/async-store.js | 8 ++++---- www/common/sframe-common-outer.js | 11 +++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 2ff827ee7..883538607 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -464,6 +464,11 @@ define([ common.onNetworkDisconnect = Util.mkEvent(); common.onNetworkReconnect = Util.mkEvent(); + // Messaging + var messaging = common.messaging = {}; + messaging.onFriendRequest = Util.mkEvent(); + messaging.onFriendComplete = Util.mkEvent(); + // Messenger var messenger = common.messenger = {}; messenger.getFriendList = function (cb) { @@ -600,13 +605,11 @@ define([ break; } case 'Q_FRIEND_REQUEST': { - if (!common.onFriendRequest) { break; } - common.onFriendRequest(data, cb); + common.messaging.onFriendRequest.fire(data, cb); break; } case 'EV_FRIEND_COMPLETE': { - if (!common.onFriendComplete) { break; } - common.onFriendComplete(data); + common.messaging.onFriendComplete.fire(data); break; } // Network diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 8e6c91f70..9ae0bd330 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -616,11 +616,11 @@ define([ postMessage("UPDATE_METADATA"); }, pinPads: Store.pinPads, - friendComplete: function (data, cb) { - postMessage("Q_FRIEND_COMPLETE", data, cb); + friendComplete: function (data) { + postMessage("EV_FRIEND_COMPLETE", data); }, - friendRequest: function (data) { - postMessage("EV_FRIEND_REQUEST", data); + friendRequest: function (data, cb) { + postMessage("Q_FRIEND_REQUEST", data, cb); }, }; }; diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index fc132b8cb..2dc46a592 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -307,17 +307,16 @@ define([ }); sframeChan.on('Q_SEND_FRIEND_REQUEST', function (netfluxId, cb) { - Messaging.inviteFromUserlist(Cryptpad, netfluxId); - cb(); + Cryptpad.inviteFromUserlist(netfluxId, cb); }); - Cryptpad.onFriendRequest = function (confirmText, cb) { + Cryptpad.messaging.onFriendRequest.reg(function (confirmText, cb) { sframeChan.query('Q_INCOMING_FRIEND_REQUEST', confirmText, function (err, data) { cb(data); }); - }; - Cryptpad.onFriendComplete = function (data) { + }); + Cryptpad.messaging.onFriendComplete.reg(function (data) { sframeChan.event('EV_FRIEND_REQUEST', data); - }; + }); sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) { var crypto = Crypto.createEncryptor(secret.keys);