Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conversation-mls): add getMLSSelfConversationGroupId to ConversationDAO #2150

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ SELECT changes();
selfConversationId:
SELECT qualified_id FROM Conversation WHERE type = 'SELF' AND protocol = ? LIMIT 1;

selfMLSGroupId:
SELECT mls_group_id FROM Conversation WHERE type = 'SELF' AND protocol = 'MLS' LIMIT 1;

updateConversationReceiptMode:
UPDATE Conversation
SET receipt_mode = ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ data class ProposalTimerEntity(

interface ConversationDAO {
suspend fun getSelfConversationId(protocol: ConversationEntity.Protocol): QualifiedIDEntity?
suspend fun getMLSSelfConversationGroupId(): String?
suspend fun insertConversation(conversationEntity: ConversationEntity)
suspend fun insertConversations(conversationEntities: List<ConversationEntity>)
suspend fun updateConversation(conversationEntity: ConversationEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ internal class ConversationDAOImpl internal constructor(
conversationQueries.selfConversationId(protocol).executeAsOneOrNull()
}

override suspend fun getMLSSelfConversationGroupId(): String? = withContext(coroutineContext) {
conversationQueries.selfMLSGroupId().executeAsOneOrNull()?.mls_group_id
}

override suspend fun insertConversation(conversationEntity: ConversationEntity) = withContext(coroutineContext) {
nonSuspendingInsertConversation(conversationEntity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,27 @@ class ConversationDAOTest : BaseDatabaseTest() {
assertEquals(listOf(conversationEntity2.id), conversationDAO.getOneOnOneConversationIdsWithOtherUser(user1.id, protocol = ConversationEntity.Protocol.MLS))
}

@Test
fun givenMLSSelfConversationExists_whenGettingMLSSelfGroupId_thenShouldReturnGroupId() = runTest{
// given
userDAO.upsertUser(user1)
conversationDAO.insertConversation(conversationEntity1.copy(type = ConversationEntity.Type.SELF))
conversationDAO.insertConversation(conversationEntity2.copy(type = ConversationEntity.Type.SELF))

// then
assertEquals((conversationEntity2.protocolInfo as ConversationEntity.ProtocolInfo.MLS).groupId, conversationDAO.getMLSSelfConversationGroupId())
}

@Test
fun givenMLSSelfConversationDoesNotExist_whenGettingMLSSelfGroupId_thenShouldReturnNull() = runTest{
// given
userDAO.upsertUser(user1)
conversationDAO.insertConversation(conversationEntity1.copy(type = ConversationEntity.Type.SELF))

// then
assertNull(conversationDAO.getMLSSelfConversationGroupId())
}

private suspend fun insertTeamUserAndMember(team: TeamEntity, user: UserEntity, conversationId: QualifiedIDEntity) {
teamDAO.insertTeam(team)
userDAO.upsertUser(user)
Expand Down
Loading