Ensure we have the correct apis and listeners during the pairing process. Catch upnp error. Remove redundant friend requests

This commit is contained in:
Beaudan Brown 2019-11-08 14:28:43 +11:00
parent c31535edb4
commit 370dee5abb
4 changed files with 27 additions and 20 deletions

View file

@ -244,10 +244,13 @@
// singleton to relay events to libtextsecure/message_receiver
window.lokiPublicChatAPI = new window.LokiPublicChatAPI(ourKey);
// singleton to interface the File server
window.lokiFileServerAPI = new window.LokiFileServerAPI(ourKey);
await window.lokiFileServerAPI.establishConnection(
window.getDefaultFileServer()
);
// If already exists we registered as a secondary device
if (!window.lokiFileServerAPI) {
window.lokiFileServerAPI = new window.LokiFileServerAPI(ourKey);
await window.lokiFileServerAPI.establishConnection(
window.getDefaultFileServer()
);
}
// are there limits on tracking, is this unneeded?
// window.mixpanel.track("Desktop boot");
window.lokiP2pAPI = new window.LokiP2pAPI(ourKey);
@ -262,7 +265,6 @@
if (storage.get('isSecondaryDevice')) {
window.lokiFileServerAPI.updateOurDeviceMapping();
}
Whisper.events.trigger('apisReady');
};
function mapOldThemeToNew(theme) {
@ -957,6 +959,10 @@
if (Whisper.Registration.ongoingSecondaryDeviceRegistration()) {
const ourKey = textsecure.storage.user.getNumber();
window.lokiMessageAPI = new window.LokiMessageAPI(ourKey);
window.lokiFileServerAPI = new window.LokiFileServerAPI(ourKey);
await window.lokiFileServerAPI.establishConnection(
window.getDefaultFileServer()
);
window.localLokiServer = null;
window.lokiPublicChatAPI = null;
window.feeds = [];
@ -967,6 +973,7 @@
options
);
messageReceiver.addEventListener('message', onMessageReceived);
messageReceiver.addEventListener('contact', onContactReceived);
window.textsecure.messaging = new textsecure.MessageSender(
USERNAME,
PASSWORD

View file

@ -38,15 +38,22 @@
let p2pPort = null;
let type;
if (!window.localLokiServer || !window.localLokiServer.isListening()) {
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
} else {
// clearnet change: getMyLokiAddress -> getMyClearIP
// const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
const myIp = await window.lokiSnodeAPI.getMyClearIp();
let myIp;
if (window.localLokiServer && window.localLokiServer.isListening()) {
try {
// clearnet change: getMyLokiAddress -> getMyClearIP
// const myLokiAddress = await window.lokiSnodeAPI.getMyLokiAddress();
myIp = await window.lokiSnodeAPI.getMyClearIp();
} catch (e) {
log.warn(`Failed to get clear IP for local server ${e}`);
}
}
if (myIp) {
p2pAddress = `https://${myIp}`;
p2pPort = window.localLokiServer.getPublicPort();
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_REACHABLE;
} else {
type = textsecure.protobuf.LokiAddressMessage.Type.HOST_UNREACHABLE;
}
const lokiAddressMessage = new textsecure.protobuf.LokiAddressMessage({

View file

@ -1130,14 +1130,6 @@ MessageReceiver.prototype.extend({
// This call already removes the envelope from the cache
await this.handleContacts(envelope, syncMessage.contacts);
removedFromCache = true;
if (window.initialisedAPI) {
await this.sendFriendRequestsToSyncContacts(syncMessage.contacts);
} else {
// We need to wait here because initAPIs hasn't been called yet
Whisper.events.once('apisReady', async () => {
await this.sendFriendRequestsToSyncContacts(syncMessage.contacts);
});
}
}
} else {
window.log.warn('Unimplemented pairing authorisation message type');

View file

@ -570,7 +570,8 @@ MessageSender.prototype = {
))
// Don't send to ourselves
.filter(pubKey => pubKey !== textsecure.storage.user.getNumber());
if (allOurDevices.length === 0) {
if (allOurDevices.includes(contactConversation.id) || !primaryDeviceKey || allOurDevices.length === 0) {
// If we havn't got a primaryDeviceKey then we are in the middle of pairing
return Promise.resolve();
}