From cdc2885f45d6af6b62603e5388cedb8d1801b0f7 Mon Sep 17 00:00:00 2001 From: Mojtaba Chenani Date: Wed, 21 Aug 2024 08:18:55 +0200 Subject: [PATCH] fix(migration): select proteus conversationId for mls migration in alphabetically order --- .../wire/kalium/persistence/Conversations.sq | 3 ++- .../persistence/dao/ConversationDAOTest.kt | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Conversations.sq b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Conversations.sq index 13f52b4ddab..32579fa8c21 100644 --- a/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Conversations.sq +++ b/persistence/src/commonMain/db_user/com/wire/kalium/persistence/Conversations.sq @@ -323,7 +323,8 @@ WHERE qualifiedId = (SELECT active_one_on_one_conversation_id FROM User WHERE qu selectOneOnOneConversationIdsByProtocol: SELECT Member.conversation FROM Member JOIN Conversation ON Conversation.qualified_id = Member.conversation -WHERE Conversation.type = 'ONE_ON_ONE' AND Conversation.protocol = :protocol AND Member.user = :user; +WHERE Conversation.type = 'ONE_ON_ONE' AND Conversation.protocol = :protocol AND Member.user = :user +ORDER BY Member.conversation ASC; getConversationIdByGroupId: SELECT qualified_id FROM Conversation WHERE mls_group_id = ?; diff --git a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt index c31791cc209..e4371dfab2e 100644 --- a/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt +++ b/persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/ConversationDAOTest.kt @@ -1259,6 +1259,26 @@ class ConversationDAOTest : BaseDatabaseTest() { ) } + @Test + fun givenMultipleOneOnOneProteusConversationExisting_whenGettingOneOnOneConversationId_thenShouldReturnAlphabeticallyOrderedConversation() = + runTest { + // given + val conversationA = conversationEntity1.copy(id = QualifiedIDEntity("a", "wire.com")) + val conversationB = conversationEntity1.copy(id = QualifiedIDEntity("b", "wire.com")) + + userDAO.upsertUser(user1) + conversationDAO.insertConversation(conversationB) + conversationDAO.insertConversation(conversationA) + memberDAO.insertMember(member1, conversationB.id) + memberDAO.insertMember(member1, conversationA.id) + + // then + assertEquals( + conversationA.id, + conversationDAO.getOneOnOneConversationIdsWithOtherUser(user1.id, protocol = ConversationEntity.Protocol.PROTEUS).first() + ) + } + @Test fun givenNoMLSConversationExistsForGivenClients_whenGettingE2EIClientInfoByClientId_thenReturnsNull() = runTest { // given