-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pairing authorization handling
- Loading branch information
Showing
8 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/tech/relaycorp/letro/pairing/dto/ContactPairingAuthorizationResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tech.relaycorp.letro.pairing.dto | ||
|
||
import tech.relaycorp.letro.awala.message.AwalaIncomingMessage | ||
import tech.relaycorp.letro.awala.message.MessageType | ||
|
||
data class ContactPairingAuthorizationResponse( | ||
val authData: ByteArray, | ||
) | ||
|
||
data class ContactPairingAuthorizationIncomingMessage( | ||
override val content: ContactPairingAuthorizationResponse, | ||
) : AwalaIncomingMessage<ContactPairingAuthorizationResponse> { | ||
override val type: MessageType | ||
get() = MessageType.ContactPairingAuthorization | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/tech/relaycorp/letro/pairing/parser/ContactPairingAuthorizationParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package tech.relaycorp.letro.pairing.parser | ||
|
||
import tech.relaycorp.letro.awala.parser.AwalaMessageParser | ||
import tech.relaycorp.letro.pairing.dto.ContactPairingAuthorizationIncomingMessage | ||
import tech.relaycorp.letro.pairing.dto.ContactPairingAuthorizationResponse | ||
import javax.inject.Inject | ||
|
||
interface ContactPairingAuthorizationParser : AwalaMessageParser | ||
|
||
class ContactPairingAuthorizationParserImpl @Inject constructor() : ContactPairingAuthorizationParser { | ||
|
||
override fun parse(content: ByteArray): ContactPairingAuthorizationIncomingMessage { | ||
return ContactPairingAuthorizationIncomingMessage( | ||
content = ContactPairingAuthorizationResponse( | ||
authData = content, | ||
), | ||
) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../main/java/tech/relaycorp/letro/pairing/processor/ContactPairingAuthorizationProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package tech.relaycorp.letro.pairing.processor | ||
|
||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.awala.AwalaManager | ||
import tech.relaycorp.letro.awala.processor.AwalaMessageProcessor | ||
import tech.relaycorp.letro.contacts.model.ContactPairingStatus | ||
import tech.relaycorp.letro.contacts.storage.ContactsDao | ||
import tech.relaycorp.letro.pairing.dto.ContactPairingAuthorizationIncomingMessage | ||
import tech.relaycorp.letro.pairing.parser.ContactPairingAuthorizationParser | ||
import javax.inject.Inject | ||
|
||
interface ContactPairingAuthorizationProcessor : AwalaMessageProcessor | ||
|
||
class ContactPairingAuthorizationProcessorImpl @Inject constructor( | ||
private val parser: ContactPairingAuthorizationParser, | ||
private val contactsDao: ContactsDao, | ||
) : ContactPairingAuthorizationProcessor { | ||
|
||
override suspend fun process(message: IncomingMessage, awalaManager: AwalaManager) { | ||
val response = (parser.parse(message.content) as ContactPairingAuthorizationIncomingMessage).content | ||
val nodeId = awalaManager.importPrivateThirdPartyAuth(response.authData) | ||
|
||
contactsDao.getContactsByContactEndpointId( | ||
contactEndpointId = nodeId, | ||
).forEach { contactToUpdate -> | ||
contactsDao.update( | ||
contactToUpdate.copy( | ||
status = ContactPairingStatus.COMPLETED, | ||
), | ||
) | ||
} | ||
} | ||
} |