Improve API: rename the method and return empty list instead of null

This commit is contained in:
Benoit Marty 2020-11-05 15:47:28 +01:00
parent c9e0aff839
commit 5c7a5fab94
5 changed files with 13 additions and 14 deletions

View file

@ -555,7 +555,7 @@ class SASTest : InstrumentedTest {
mTestHelper.waitWithLatch { mTestHelper.waitWithLatch {
mTestHelper.retryPeriodicallyWithLatch(it) { mTestHelper.retryPeriodicallyWithLatch(it) {
val prAlicePOV = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId)?.firstOrNull() val prAlicePOV = aliceVerificationService.getExistingVerificationRequests(bobSession.myUserId).firstOrNull()
requestID = prAlicePOV?.transactionId requestID = prAlicePOV?.transactionId
Log.v("TEST", "== alicePOV is $prAlicePOV") Log.v("TEST", "== alicePOV is $prAlicePOV")
prAlicePOV?.transactionId != null && prAlicePOV.localId == req.localId prAlicePOV?.transactionId != null && prAlicePOV.localId == req.localId
@ -566,7 +566,7 @@ class SASTest : InstrumentedTest {
mTestHelper.waitWithLatch { mTestHelper.waitWithLatch {
mTestHelper.retryPeriodicallyWithLatch(it) { mTestHelper.retryPeriodicallyWithLatch(it) {
val prBobPOV = bobVerificationService.getExistingVerificationRequest(aliceSession.myUserId)?.firstOrNull() val prBobPOV = bobVerificationService.getExistingVerificationRequests(aliceSession.myUserId).firstOrNull()
Log.v("TEST", "== prBobPOV is $prBobPOV") Log.v("TEST", "== prBobPOV is $prBobPOV")
prBobPOV?.transactionId == requestID prBobPOV?.transactionId == requestID
} }
@ -581,7 +581,7 @@ class SASTest : InstrumentedTest {
// wait for alice to get the ready // wait for alice to get the ready
mTestHelper.waitWithLatch { mTestHelper.waitWithLatch {
mTestHelper.retryPeriodicallyWithLatch(it) { mTestHelper.retryPeriodicallyWithLatch(it) {
val prAlicePOV = aliceVerificationService.getExistingVerificationRequest(bobSession.myUserId)?.firstOrNull() val prAlicePOV = aliceVerificationService.getExistingVerificationRequests(bobSession.myUserId).firstOrNull()
Log.v("TEST", "== prAlicePOV is $prAlicePOV") Log.v("TEST", "== prAlicePOV is $prAlicePOV")
prAlicePOV?.transactionId == requestID && prAlicePOV?.isReady != null prAlicePOV?.transactionId == requestID && prAlicePOV?.isReady != null
} }

View file

@ -41,7 +41,7 @@ interface VerificationService {
fun getExistingTransaction(otherUserId: String, tid: String): VerificationTransaction? fun getExistingTransaction(otherUserId: String, tid: String): VerificationTransaction?
fun getExistingVerificationRequest(otherUserId: String): List<PendingVerificationRequest>? fun getExistingVerificationRequests(otherUserId: String): List<PendingVerificationRequest>
fun getExistingVerificationRequest(otherUserId: String, tid: String?): PendingVerificationRequest? fun getExistingVerificationRequest(otherUserId: String, tid: String?): PendingVerificationRequest?

View file

@ -537,11 +537,10 @@ internal class DefaultVerificationService @Inject constructor(
// If there is a corresponding request, we can auto accept // If there is a corresponding request, we can auto accept
// as we are the one requesting in first place (or we accepted the request) // as we are the one requesting in first place (or we accepted the request)
// I need to check if the pending request was related to this device also // I need to check if the pending request was related to this device also
val autoAccept = getExistingVerificationRequest(otherUserId)?.any { val autoAccept = getExistingVerificationRequests(otherUserId).any {
it.transactionId == startReq.transactionId it.transactionId == startReq.transactionId
&& (it.requestInfo?.fromDevice == this.deviceId || it.readyInfo?.fromDevice == this.deviceId) && (it.requestInfo?.fromDevice == this.deviceId || it.readyInfo?.fromDevice == this.deviceId)
} }
?: false
val tx = DefaultIncomingSASDefaultVerificationTransaction( val tx = DefaultIncomingSASDefaultVerificationTransaction(
// this, // this,
setDeviceVerificationAction, setDeviceVerificationAction,
@ -837,8 +836,8 @@ internal class DefaultVerificationService @Inject constructor(
// SAS do not care for now? // SAS do not care for now?
} }
// Now transactions are udated, let's also update Requests // Now transactions are updated, let's also update Requests
val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == doneReq.transactionId } val existingRequest = getExistingVerificationRequests(senderId).find { it.transactionId == doneReq.transactionId }
if (existingRequest == null) { if (existingRequest == null) {
Timber.e("## SAS Received Done for unknown request txId:${doneReq.transactionId}") Timber.e("## SAS Received Done for unknown request txId:${doneReq.transactionId}")
return return
@ -892,7 +891,7 @@ internal class DefaultVerificationService @Inject constructor(
private fun handleReadyReceived(senderId: String, private fun handleReadyReceived(senderId: String,
readyReq: ValidVerificationInfoReady, readyReq: ValidVerificationInfoReady,
transportCreator: (DefaultVerificationTransaction) -> VerificationTransport) { transportCreator: (DefaultVerificationTransaction) -> VerificationTransport) {
val existingRequest = getExistingVerificationRequest(senderId)?.find { it.transactionId == readyReq.transactionId } val existingRequest = getExistingVerificationRequests(senderId).find { it.transactionId == readyReq.transactionId }
if (existingRequest == null) { if (existingRequest == null) {
Timber.e("## SAS Received Ready for unknown request txId:${readyReq.transactionId} fromDevice ${readyReq.fromDevice}") Timber.e("## SAS Received Ready for unknown request txId:${readyReq.transactionId} fromDevice ${readyReq.fromDevice}")
return return
@ -1041,9 +1040,9 @@ internal class DefaultVerificationService @Inject constructor(
} }
} }
override fun getExistingVerificationRequest(otherUserId: String): List<PendingVerificationRequest>? { override fun getExistingVerificationRequests(otherUserId: String): List<PendingVerificationRequest> {
synchronized(lock = pendingRequests) { synchronized(lock = pendingRequests) {
return pendingRequests[otherUserId] return pendingRequests[otherUserId].orEmpty()
} }
} }

View file

@ -143,7 +143,7 @@ class SharedSecureStorageViewModel @AssistedInject constructor(
// as we are going to reset, we'd better cancel all outgoing requests // as we are going to reset, we'd better cancel all outgoing requests
// if not they could be accepted in the middle of the reset process // if not they could be accepted in the middle of the reset process
// and cause strange use cases // and cause strange use cases
session.cryptoService().verificationService().getExistingVerificationRequest(session.myUserId)?.forEach { session.cryptoService().verificationService().getExistingVerificationRequests(session.myUserId).forEach {
session.cryptoService().verificationService().cancelVerificationRequest(it) session.cryptoService().verificationService().cancelVerificationRequest(it)
} }
_viewEvents.post(SharedSecureStorageViewEvent.ShowResetBottomSheet) _viewEvents.post(SharedSecureStorageViewEvent.ShowResetBottomSheet)

View file

@ -99,8 +99,8 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
val pr = if (selfVerificationMode) { val pr = if (selfVerificationMode) {
// See if active tx for this user and take it // See if active tx for this user and take it
session.cryptoService().verificationService().getExistingVerificationRequest(args.otherUserId) session.cryptoService().verificationService().getExistingVerificationRequests(args.otherUserId)
?.lastOrNull { !it.isFinished } .lastOrNull { !it.isFinished }
?.also { verificationRequest -> ?.also { verificationRequest ->
if (verificationRequest.isIncoming && !verificationRequest.isReady) { if (verificationRequest.isIncoming && !verificationRequest.isReady) {
// auto ready in this case, as we are waiting // auto ready in this case, as we are waiting