Skip to content

Commit

Permalink
fix: Remove Self Deleting Messages from Messages Search inside a Conv…
Browse files Browse the repository at this point in the history
…ersation (WPB-4915) (#2216)

* fix: add where clause to only get not self deleting messages from db

* test: add tests for getting only non self deleting messages
  • Loading branch information
alexandreferris authored Nov 13, 2023
1 parent ea4ec38 commit ab4e95d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,13 @@ SELECT * FROM MessageDetailsView
WHERE text LIKE ('%' || :searchQuery || '%')
AND conversationId = :conversationId
AND contentType = 'TEXT'
AND expireAfterMillis IS NULL
ORDER BY date DESC;

selectSearchedConversationMessagePosition:
SELECT COUNT(*) FROM Message
WHERE
conversation_id = :conversationId
AND creation_date >= (SELECT creation_date FROM Message WHERE id = :messageId LIMIT 1)
AND expire_after_millis IS NULL
ORDER BY creation_date DESC;
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,66 @@ class MessageDAOTest : BaseDatabaseTest() {
assertEquals(expectedPosition, result)
}

@Test
fun givenMessagesAreInserted_whenGettingConversationMessagesFromSearch_thenNoSelfDeletingMessagesAreReturned() = runTest {
insertInitialData()

val otherUser = userEntity2

val expectedMessages = listOf(
newRegularMessageEntity(
"1",
conversationId = conversationEntity1.id,
status = MessageEntity.Status.SENT,
senderUserId = otherUser.id,
senderName = otherUser.name!!,
content = MessageEntityContent.Text("message10"),
date = Instant.parse("2022-03-30T15:36:00.000Z")
),
newRegularMessageEntity(
"2",
conversationId = conversationEntity1.id,
status = MessageEntity.Status.SENT,
senderUserId = otherUser.id,
senderName = otherUser.name!!,
content = MessageEntityContent.Text("message11"),
date = Instant.parse("2022-03-30T15:36:01.000Z")
)
)

val allMessages = expectedMessages + listOf(
newRegularMessageEntity(
"3",
conversationId = conversationEntity1.id,
status = MessageEntity.Status.SENT,
senderUserId = otherUser.id,
senderName = otherUser.name!!,
content = MessageEntityContent.Text("message12"),
date = Instant.parse("2022-03-30T15:36:02.000Z"),
expireAfterMs = 3600000L
),
newRegularMessageEntity(
"4",
conversationId = conversationEntity1.id,
senderUserId = otherUser.id,
senderName = otherUser.name!!,
status = MessageEntity.Status.SENT,
content = MessageEntityContent.Text("message20"),
date = Instant.parse("2022-03-30T15:36:03.000Z")
)
)

messageDAO.insertOrIgnoreMessages(allMessages)

val result = messageDAO.getConversationMessagesFromSearch(
searchQuery = "message1",
conversationId = conversationEntity1.id
)

assertEquals(expectedMessages.size, result.size)
assertContentEquals(expectedMessages.sortedByDescending { it.date }, result)
}

private suspend fun insertInitialData() {
userDAO.upsertUsers(listOf(userEntity1, userEntity2))
conversationDAO.insertConversation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ fun newRegularMessageEntity(
visibility: MessageEntity.Visibility = MessageEntity.Visibility.VISIBLE,
senderName: String = "senderName",
expectsReadConfirmation: Boolean = false,
expireAfterMs: Long? = null,
selfDeletionStartDate: Instant? = null,
) = MessageEntity.Regular(
id = id,
content = content,
Expand All @@ -49,7 +51,9 @@ fun newRegularMessageEntity(
visibility = visibility,
senderName = senderName,
expectsReadConfirmation = expectsReadConfirmation,
readCount = 0
readCount = 0,
expireAfterMs = expireAfterMs,
selfDeletionStartDate = selfDeletionStartDate,
)

@Suppress("LongParameterList")
Expand Down

0 comments on commit ab4e95d

Please sign in to comment.