Storing primary device pubkey on the conversation model for easier access, ensuring that we accept all the friend requests from the primary conversation rather than the secondary

This commit is contained in:
Beaudan Brown 2019-11-13 17:01:21 +11:00
parent 24a687c106
commit 807f4cbd2a
3 changed files with 25 additions and 6 deletions

View file

@ -1247,7 +1247,7 @@
ourDevices.some(devicePubKey => devicePubKey === id);
if (isOurSecondaryDevice) {
await conversation.setSecondaryStatus(true);
await conversation.setSecondaryStatus(true, ourPrimaryKey);
}
if (conversation.isFriendRequestStatusNone()) {

View file

@ -766,9 +766,15 @@
isSecondaryDevice() {
return !!this.get('secondaryStatus');
},
async setSecondaryStatus(newStatus) {
getPrimaryDevicePubKey() {
return this.get('getPrimaryDevicePubKey') || this.id;
},
async setSecondaryStatus(newStatus, primaryDevicePubKey) {
if (this.get('secondaryStatus') !== newStatus) {
this.set({ secondaryStatus: newStatus });
this.set({
secondaryStatus: newStatus,
primaryDevicePubKey,
});
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
@ -804,7 +810,17 @@
if (!response) {
return;
}
const pending = await this.getFriendRequests(direction, status);
const primaryConversation = ConversationController.get(
this.getPrimaryDevicePubKey()
);
// Should never happen
if (!primaryConversation) {
return;
}
const pending = await primaryConversation.getFriendRequests(
direction,
status
);
await Promise.all(
pending.map(async request => {
if (request.hasErrors()) {
@ -815,7 +831,7 @@
await window.Signal.Data.saveMessage(request.attributes, {
Message: Whisper.Message,
});
this.trigger('updateMessage', request);
primaryConversation.trigger('updateMessage', request);
})
);
},

View file

@ -172,7 +172,10 @@
authorisation.secondaryDevicePubKey,
'private'
);
await conversation.setSecondaryStatus(true);
await conversation.setSecondaryStatus(
true,
authorisation.primaryDevicePubKey
);
await window.Signal.Data.createOrUpdatePairingAuthorisation(authorisation);
}