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 f8371aff33e..f2267d74cbb 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 @@ -229,7 +229,7 @@ WHERE OR (type IS 'ONE_ON_ONE' AND userDeleted = 1) -- show deleted 1:1 convos, to maintain prev, logic ) AND (protocol IS 'PROTEUS' OR (protocol IS 'MLS' AND mls_group_state IS 'ESTABLISHED')) -ORDER BY lastModifiedDate DESC, name COLLATE NOCASE ASC; +ORDER BY lastModifiedDate DESC, name IS NULL, name COLLATE NOCASE ASC; selectAllConversations: SELECT * FROM ConversationDetails WHERE type IS NOT 'CONNECTION_PENDING' ORDER BY last_modified_date DESC, name ASC; 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 87d7aecce6b..6e18c64414c 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 @@ -886,6 +886,37 @@ class ConversationDAOTest : BaseDatabaseTest() { assertNull(result.firstOrNull { it.id == conversation.id }) } + @Test + fun givenConversaions_whenObservingTheFullList_thenConvWithNullNameAreLast() = runTest { + // given + val conversation1 = conversationEntity1.copy( + id = ConversationIDEntity("convNullName", "domain"), + name = null, + type = ConversationEntity.Type.GROUP, + hasIncompleteMetadata = false, + lastModifiedDate = "2021-03-30T15:36:00.000Z".toInstant(), + ) + + val conversation2 = conversationEntity2.copy( + id = ConversationIDEntity("convWithName", "domain"), + name = "name", + type = ConversationEntity.Type.GROUP, + hasIncompleteMetadata = false, + lastModifiedDate = "2021-03-30T15:36:00.000Z".toInstant(), + ) + conversationDAO.insertConversation(conversation1) + conversationDAO.insertConversation(conversation2) + insertTeamUserAndMember(team, user1, conversation1.id) + insertTeamUserAndMember(team, user1, conversation2.id) + + // when + val result = conversationDAO.getAllConversationDetails().first() + + // then + assertEquals(conversation2.id, result[0].id) + assertEquals(conversation1.id, result[1].id) + } + private suspend fun insertTeamUserAndMember(team: TeamEntity, user: UserEntity, conversationId: QualifiedIDEntity) { teamDAO.insertTeam(team) userDAO.insertUser(user)