-
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.
feat: process incoming messages in-band (#41)
# What kind of change does this PR introduce? Process awala messages in-band # What is the current behavior? Now there is only message parsing is performed in-band. Other work with message content (for example, saving data to a database) is performed after acknowledging of a message. # What is the new behavior (if this is a feature change)? All work with message content is performed before message.ack() call.
- Loading branch information
Showing
11 changed files
with
83 additions
and
55 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
11 changes: 1 addition & 10 deletions
11
app/src/main/java/tech/relaycorp/letro/awala/parser/AwalaMessageParser.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 |
---|---|---|
@@ -1,16 +1,7 @@ | ||
package tech.relaycorp.letro.awala.parser | ||
|
||
import tech.relaycorp.letro.awala.message.AwalaIncomingMessage | ||
import tech.relaycorp.letro.awala.message.MessageType | ||
|
||
interface AwalaMessageParser { | ||
fun parse(type: MessageType, content: ByteArray): AwalaIncomingMessage<*> | ||
} | ||
|
||
class AwalaMessageParserImpl constructor( | ||
private val parsers: Map<MessageType, AwalaMessageParser>, | ||
) : AwalaMessageParser { | ||
override fun parse(type: MessageType, content: ByteArray): AwalaIncomingMessage<*> { | ||
return parsers[type]?.parse(type, content) ?: throw IllegalStateException("No parser for messageType: $type") | ||
} | ||
fun parse(content: ByteArray): AwalaIncomingMessage<*> | ||
} |
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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/tech/relaycorp/letro/awala/processor/AwalaMessageProcessor.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,18 @@ | ||
package tech.relaycorp.letro.awala.processor | ||
|
||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.awala.message.MessageType | ||
|
||
interface AwalaMessageProcessor { | ||
suspend fun process(message: IncomingMessage) | ||
} | ||
|
||
class AwalaMessageProcessorImpl constructor( | ||
private val processors: Map<MessageType, AwalaMessageProcessor>, | ||
) : AwalaMessageProcessor { | ||
|
||
override suspend fun process(message: IncomingMessage) { | ||
val type = MessageType.from(message.type) | ||
processors[type]!!.process(message) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/tech/relaycorp/letro/awala/processor/UnknownMessageProcessor.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,13 @@ | ||
package tech.relaycorp.letro.awala.processor | ||
|
||
import android.util.Log | ||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.awala.AwalaManagerImpl | ||
import javax.inject.Inject | ||
|
||
class UnknownMessageProcessor @Inject constructor() : AwalaMessageProcessor { | ||
|
||
override suspend fun process(message: IncomingMessage) { | ||
Log.w(AwalaManagerImpl.TAG, "Unknown message processor for type: ${message.type}") | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
...va/tech/relaycorp/letro/onboarding/registration/processor/RegistrationMessageProcessor.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,21 @@ | ||
package tech.relaycorp.letro.onboarding.registration.processor | ||
|
||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.account.storage.AccountRepository | ||
import tech.relaycorp.letro.awala.processor.AwalaMessageProcessor | ||
import tech.relaycorp.letro.onboarding.registration.dto.RegistrationResponseIncomingMessage | ||
import tech.relaycorp.letro.onboarding.registration.parser.RegistrationMessageParser | ||
import javax.inject.Inject | ||
|
||
interface RegistrationMessageProcessor : AwalaMessageProcessor | ||
|
||
class RegistrationMessageProcessorImpl @Inject constructor( | ||
private val parser: RegistrationMessageParser, | ||
private val accountRepository: AccountRepository, | ||
) : RegistrationMessageProcessor { | ||
|
||
override suspend fun process(message: IncomingMessage) { | ||
val response = parser.parse(message.content) as RegistrationResponseIncomingMessage | ||
accountRepository.updateAccountId(response.content.requestedVeraId, response.content.assignedVeraId) | ||
} | ||
} |