-
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: receiving messages about new conversations and new messages fro…
…m Awala (#55) Receiving new messages about messages & conversations, storing & displaying them in the database
- Loading branch information
Showing
10 changed files
with
188 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/tech/relaycorp/letro/messages/dto/NewConversationIncomingMessage.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.messages.dto | ||
|
||
import tech.relaycorp.letro.awala.message.AwalaIncomingMessage | ||
import tech.relaycorp.letro.awala.message.MessageType | ||
import tech.relaycorp.letro.messages.storage.entity.Conversation | ||
import tech.relaycorp.letro.messages.storage.entity.Message | ||
|
||
data class NewConversationIncomingMessageContent( | ||
val conversation: Conversation, | ||
val message: Message, | ||
) | ||
|
||
data class NewConversationIncomingMessage( | ||
override val content: NewConversationIncomingMessageContent, | ||
) : AwalaIncomingMessage<NewConversationIncomingMessageContent> { | ||
override val type: MessageType | ||
get() = MessageType.NewConversation | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/tech/relaycorp/letro/messages/dto/NewMessageIncomingMessage.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,12 @@ | ||
package tech.relaycorp.letro.messages.dto | ||
|
||
import tech.relaycorp.letro.awala.message.AwalaIncomingMessage | ||
import tech.relaycorp.letro.awala.message.MessageType | ||
import tech.relaycorp.letro.messages.storage.entity.Message | ||
|
||
data class NewMessageIncomingMessage( | ||
override val content: Message, | ||
) : AwalaIncomingMessage<Message> { | ||
override val type: MessageType | ||
get() = MessageType.NewMessage | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/tech/relaycorp/letro/messages/parser/NewConversationMessageParser.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.messages.parser | ||
|
||
import tech.relaycorp.letro.awala.parser.AwalaMessageParser | ||
import tech.relaycorp.letro.messages.dto.NewConversationIncomingMessage | ||
import tech.relaycorp.letro.messages.dto.NewConversationIncomingMessageContent | ||
import tech.relaycorp.letro.messages.storage.entity.Conversation | ||
import java.util.UUID | ||
import javax.inject.Inject | ||
|
||
interface NewConversationMessageParser : AwalaMessageParser | ||
|
||
class NewConversationMessageParserImpl @Inject constructor() : NewConversationMessageParser { | ||
|
||
override fun parse(content: ByteArray): NewConversationIncomingMessage { | ||
val conversation = mockConversation() // TODO: parse conversation | ||
val message = mockMessage(conversation.conversationId) | ||
return NewConversationIncomingMessage( | ||
content = NewConversationIncomingMessageContent( | ||
conversation = conversation, | ||
message = message, | ||
), | ||
) | ||
} | ||
|
||
private fun mockConversation() = Conversation( | ||
ownerVeraId = "[email protected]", | ||
contactVeraId = "[email protected]", | ||
subject = "Test subject", | ||
conversationId = MOCK_CONVERSATION_ID, | ||
) | ||
} | ||
|
||
private val MOCK_CONVERSATION_ID = UUID.randomUUID() |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/tech/relaycorp/letro/messages/parser/NewMessageMessageParser.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,29 @@ | ||
package tech.relaycorp.letro.messages.parser | ||
|
||
import tech.relaycorp.letro.awala.parser.AwalaMessageParser | ||
import tech.relaycorp.letro.messages.dto.NewMessageIncomingMessage | ||
import tech.relaycorp.letro.messages.storage.entity.Message | ||
import java.time.LocalDateTime | ||
import java.util.UUID | ||
import javax.inject.Inject | ||
|
||
interface NewMessageMessageParser : AwalaMessageParser | ||
|
||
class NewMessageMessageParserImpl @Inject constructor() : NewMessageMessageParser { | ||
|
||
override fun parse(content: ByteArray): NewMessageIncomingMessage { | ||
val message = mockMessage(UUID.randomUUID()) // TODO: parse message here | ||
return NewMessageIncomingMessage( | ||
content = message, | ||
) | ||
} | ||
} | ||
|
||
internal fun mockMessage(conversationId: UUID) = Message( | ||
conversationId = conversationId, | ||
text = "Hello, how are you?", | ||
ownerVeraId = "[email protected]", | ||
recipientVeraId = "[email protected]", | ||
senderVeraId = "[email protected]", | ||
sentAt = LocalDateTime.now(), | ||
) |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/tech/relaycorp/letro/messages/processor/NewConversationProcessor.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,25 @@ | ||
package tech.relaycorp.letro.messages.processor | ||
|
||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.awala.AwalaManager | ||
import tech.relaycorp.letro.awala.processor.AwalaMessageProcessor | ||
import tech.relaycorp.letro.messages.dto.NewConversationIncomingMessage | ||
import tech.relaycorp.letro.messages.parser.NewConversationMessageParser | ||
import tech.relaycorp.letro.messages.storage.ConversationsDao | ||
import tech.relaycorp.letro.messages.storage.MessagesDao | ||
import javax.inject.Inject | ||
|
||
interface NewConversationProcessor : AwalaMessageProcessor | ||
|
||
class NewConversationProcessorImpl @Inject constructor( | ||
private val newConversationMessageParser: NewConversationMessageParser, | ||
private val conversationsDao: ConversationsDao, | ||
private val messagesDao: MessagesDao, | ||
) : NewConversationProcessor { | ||
|
||
override suspend fun process(message: IncomingMessage, awalaManager: AwalaManager) { | ||
val content = (newConversationMessageParser.parse(message.content) as NewConversationIncomingMessage).content | ||
conversationsDao.createNewConversation(content.conversation) | ||
messagesDao.insert(content.message) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/tech/relaycorp/letro/messages/processor/NewMessageProcessor.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.messages.processor | ||
|
||
import tech.relaycorp.awaladroid.messaging.IncomingMessage | ||
import tech.relaycorp.letro.awala.AwalaManager | ||
import tech.relaycorp.letro.awala.processor.AwalaMessageProcessor | ||
import tech.relaycorp.letro.messages.dto.NewMessageIncomingMessage | ||
import tech.relaycorp.letro.messages.parser.NewMessageMessageParser | ||
import tech.relaycorp.letro.messages.storage.MessagesDao | ||
import javax.inject.Inject | ||
|
||
interface NewMessageProcessor : AwalaMessageProcessor | ||
|
||
class NewMessageProcessorImpl @Inject constructor( | ||
private val parser: NewMessageMessageParser, | ||
private val messagesDao: MessagesDao, | ||
) : NewMessageProcessor { | ||
override suspend fun process(message: IncomingMessage, awalaManager: AwalaManager) { | ||
val parsedMessage = (parser.parse(message.content) as NewMessageIncomingMessage).content | ||
messagesDao.insert(parsedMessage) | ||
} | ||
} |
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