Skip to content

Commit

Permalink
fix: conversations with null name are placed on the top of the conv l…
Browse files Browse the repository at this point in the history
…ist (#2017)

* fix: conversations with NULL name are placed at the top of the conversations list

* unit test

---------

Co-authored-by: Mojtaba Chenani <[email protected]>
  • Loading branch information
MohamadJaara and mchenani committed Sep 4, 2023
1 parent 1ccc6c6 commit dbaa68a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dbaa68a

Please sign in to comment.