mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Update device mappings on the file server upon receiving a pairing confirmation.
This commit is contained in:
parent
8acc0bcff9
commit
203348b8fb
@ -1034,12 +1034,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePairingAuthorisation(@NonNull LokiPairingAuthorisation authorisation, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
private void handlePairingAuthorisation(@NonNull LokiPairingAuthorisation authorisation, @NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
||||||
|
String ourNumber = TextSecurePreferences.getLocalNumber(context);
|
||||||
if (authorisation.getType() == LokiPairingAuthorisation.Type.REQUEST) {
|
if (authorisation.getType() == LokiPairingAuthorisation.Type.REQUEST) {
|
||||||
handlePairingRequest(authorisation, envelope);
|
handlePairingRequest(authorisation, envelope);
|
||||||
} else if (authorisation.getSecondaryDevicePubKey().equals(TextSecurePreferences.getLocalNumber(context))) {
|
} else if (authorisation.getSecondaryDevicePubKey().equals(ourNumber)) {
|
||||||
|
// If we were listed as a secondary device, it means we got a confirmation back from the primary device
|
||||||
handlePairingAuthorisationForSelf(authorisation, envelope, content);
|
handlePairingAuthorisationForSelf(authorisation, envelope, content);
|
||||||
} else {
|
|
||||||
handlePairingAuthorisationForContact(authorisation);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1069,11 +1069,17 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
|
|
||||||
// Unimplemented
|
// Unimplemented
|
||||||
if (authorisation.getType() != LokiPairingAuthorisation.Type.GRANT) { return; }
|
if (authorisation.getType() != LokiPairingAuthorisation.Type.GRANT) { return; }
|
||||||
|
|
||||||
// Set the current device as secondary
|
|
||||||
Log.d("Loki", "Receiving pairing authorisation from: " + authorisation.getPrimaryDevicePubKey());
|
Log.d("Loki", "Receiving pairing authorisation from: " + authorisation.getPrimaryDevicePubKey());
|
||||||
|
|
||||||
|
// Set the current device as secondary and update our authorisations
|
||||||
|
String ourNumber = TextSecurePreferences.getLocalNumber(context);
|
||||||
|
DatabaseFactory.getLokiAPIDatabase(context).removePairingAuthorisations(ourNumber);
|
||||||
DatabaseFactory.getLokiAPIDatabase(context).insertOrUpdatePairingAuthorisation(authorisation);
|
DatabaseFactory.getLokiAPIDatabase(context).insertOrUpdatePairingAuthorisation(authorisation);
|
||||||
TextSecurePreferences.setIsSecondaryDevice(context, true);
|
TextSecurePreferences.setIsSecondaryDevice(context, true);
|
||||||
|
|
||||||
|
// Propagate the updates to the file server
|
||||||
|
LokiStorageAPI.shared.updateOurDeviceMappings();
|
||||||
|
|
||||||
// TODO: Trigger an event here?
|
// TODO: Trigger an event here?
|
||||||
|
|
||||||
// Update display names
|
// Update display names
|
||||||
@ -1082,24 +1088,6 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePairingAuthorisationForContact(@NonNull LokiPairingAuthorisation authorisation) {
|
|
||||||
if (!isAuthorisationValid(authorisation)) {
|
|
||||||
Log.w("Loki", "Received invalid pairing authorisation for self. Could not verify signature. Ignoring.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure primary device is a friend
|
|
||||||
String primaryDevice = authorisation.getPrimaryDevicePubKey();
|
|
||||||
LokiThreadDatabase lokiThreadDatabase = DatabaseFactory.getLokiThreadDatabase(context);
|
|
||||||
long threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(Recipient.from(context, Address.fromSerialized(primaryDevice), false));
|
|
||||||
LokiThreadFriendRequestStatus threadFriendRequestStatus = lokiThreadDatabase.getFriendRequestStatus(threadID);
|
|
||||||
if (threadFriendRequestStatus == LokiThreadFriendRequestStatus.FRIENDS) {
|
|
||||||
// If we're friends then save and send a background message if needed for friend request accept
|
|
||||||
DatabaseFactory.getLokiAPIDatabase(context).insertOrUpdatePairingAuthorisation(authorisation);
|
|
||||||
sendBackgroundMessage(authorisation.getSecondaryDevicePubKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setDisplayName(String pubKey, String profileName) {
|
private void setDisplayName(String pubKey, String profileName) {
|
||||||
String senderDisplayName = profileName + " (..." + pubKey.substring(pubKey.length() - 8) + ")";
|
String senderDisplayName = profileName + " (..." + pubKey.substring(pubKey.length() - 8) + ")";
|
||||||
DatabaseFactory.getLokiUserDatabase(context).setDisplayName(pubKey, senderDisplayName);
|
DatabaseFactory.getLokiUserDatabase(context).setDisplayName(pubKey, senderDisplayName);
|
||||||
@ -1119,7 +1107,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
// If we get a friend request then we need to check if the sender is a secondary device.
|
// If we get a friend request then we need to check if the sender is a secondary device.
|
||||||
// If it is then we need to check if we have its primary device as our friend
|
// If it is then we need to check if we have its primary device as our friend
|
||||||
// If so then we add them automatically as a friend
|
// If so then we add them automatically as a friend
|
||||||
LokiStorageAPI.Companion.getShared().getPrimaryDevice(content.getSender()).success(primaryDevicePubKey -> {
|
LokiStorageAPI.shared.getPrimaryDevice(content.getSender()).success(primaryDevicePubKey -> {
|
||||||
// Make sure we have a primary device
|
// Make sure we have a primary device
|
||||||
if (primaryDevicePubKey == null) { return Unit.INSTANCE; }
|
if (primaryDevicePubKey == null) { return Unit.INSTANCE; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user