mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Implement AFR sending
This commit is contained in:
parent
7a351592a4
commit
f29f775cf9
@ -1,7 +1,9 @@
|
||||
package org.thoughtcrime.securesms.loki.protocol
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.crypto.UnidentifiedAccessUtil
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.loki.utilities.recipient
|
||||
@ -10,6 +12,8 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.sms.OutgoingTextMessage
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceContent
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.loki.protocol.meta.SessionMetaProtocol
|
||||
import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol
|
||||
import org.whispersystems.signalservice.loki.protocol.todo.LokiMessageFriendRequestStatus
|
||||
@ -48,7 +52,7 @@ object FriendRequestProtocol {
|
||||
// Do nothing
|
||||
} else if (!allUserDevices.contains(device)
|
||||
&& (deviceFRStatus == LokiThreadFriendRequestStatus.NONE || deviceFRStatus == LokiThreadFriendRequestStatus.REQUEST_EXPIRED)) {
|
||||
// TODO: Send AFR to contact (NOT their linked devices)
|
||||
sendAutoGeneratedFriendRequest(context, device)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -293,4 +297,22 @@ object FriendRequestProtocol {
|
||||
threadDB.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
fun sendAutoGeneratedFriendRequest(context: Context, publicKey: String) {
|
||||
val messageSender = ApplicationContext.getInstance(context).communicationModule.provideSignalMessageSender()
|
||||
val address = SignalServiceAddress(publicKey)
|
||||
val recipient = recipient(context, publicKey)
|
||||
val preKeyBundle = DatabaseFactory.getLokiPreKeyBundleDatabase(context).generatePreKeyBundle(address.number)
|
||||
val message = SignalServiceDataMessage.newBuilder()
|
||||
.asFriendRequest(true)
|
||||
.withPreKeyBundle(preKeyBundle)
|
||||
.withBody("")
|
||||
val threadDB = DatabaseFactory.getThreadDatabase(context)
|
||||
val uncheckedThreadID = threadDB.getThreadIdIfExistsFor(recipient)
|
||||
val threadID = if (uncheckedThreadID == -1L) threadDB.getThreadIdFor(recipient) else uncheckedThreadID
|
||||
setFriendRequestStatusToSendingIfNeeded(context, 0, threadID)
|
||||
Log.d("Loki", "Sending auto generated friend request message to: $publicKey.")
|
||||
val udAccess = UnidentifiedAccessUtil.getAccessFor(context, recipient(context, publicKey))
|
||||
messageSender.sendMessage(0, address, udAccess, message.build())
|
||||
}
|
||||
}
|
@ -104,7 +104,10 @@ object SyncMessagesProtocol {
|
||||
val threadFRStatus = lokiThreadDB.getFriendRequestStatus(threadID)
|
||||
when (threadFRStatus) {
|
||||
LokiThreadFriendRequestStatus.NONE, LokiThreadFriendRequestStatus.REQUEST_EXPIRED -> {
|
||||
// TODO: Send AFR to contact AND THEIR LINKED DEVICES
|
||||
val contactLinkedDevices = MultiDeviceProtocol.shared.getAllLinkedDevices(contactPublicKey)
|
||||
for (device in contactLinkedDevices) {
|
||||
FriendRequestProtocol.sendAutoGeneratedFriendRequest(context, device)
|
||||
}
|
||||
}
|
||||
LokiThreadFriendRequestStatus.REQUEST_RECEIVED -> {
|
||||
FriendRequestProtocol.acceptFriendRequest(context, recipient(context, contactPublicKey)) // Takes into account multi device internally
|
||||
|
Loading…
Reference in New Issue
Block a user