Skip to content

Commit

Permalink
fix: remove unread event after mark delete message [WPB-4452] (#2132)
Browse files Browse the repository at this point in the history
* fix: remove unread event after mark delete message

* detekt fix
  • Loading branch information
Garzas authored Oct 13, 2023
1 parent 675404c commit 6ee492b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ CREATE TABLE UnreadEvent (
PRIMARY KEY (id, conversation_id)
);

deleteUnreadEvent:
DELETE FROM UnreadEvent WHERE id = ? AND conversation_id = ?;

deleteUnreadEvents:
DELETE FROM UnreadEvent WHERE creation_date <= ? AND conversation_id = ?;

insertEvent:
INSERT OR IGNORE INTO UnreadEvent(id, type, conversation_id, creation_date)
VALUES(?, ?, ?, ?);

updateEvent:
UPDATE OR IGNORE UnreadEvent
SET type = :type
WHERE id = :id AND conversation_id = :conversation_id;

getUnreadEvents:
SELECT conversation_id, type FROM UnreadEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.wire.kalium.persistence.dao.conversation.ConversationEntity
import com.wire.kalium.persistence.dao.unread.ConversationUnreadEventEntity
import com.wire.kalium.persistence.dao.unread.UnreadEventEntity
import com.wire.kalium.persistence.dao.unread.UnreadEventMapper
import com.wire.kalium.persistence.dao.unread.UnreadEventTypeEntity
import com.wire.kalium.persistence.util.mapToList
import com.wire.kalium.persistence.util.mapToOneOrNull
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -73,6 +74,7 @@ internal class MessageDAOImpl internal constructor(
override suspend fun markMessageAsDeleted(id: String, conversationsId: QualifiedIDEntity) =
withContext(coroutineContext) {
queries.markMessageAsDeleted(id, conversationsId)
unreadEventsQueries.deleteUnreadEvent(id, conversationsId)
}

override suspend fun deleteAllMessages() = withContext(coroutineContext) {
Expand Down Expand Up @@ -297,6 +299,13 @@ internal class MessageDAOImpl internal constructor(
user_id = it.userId
)
}
val selfMention = newTextContent.mentions.firstNotNullOfOrNull { it.userId == selfUserId }
if (selfMention != null) {
unreadEventsQueries.updateEvent(UnreadEventTypeEntity.MENTION, currentMessageId, conversationId)
} else {
unreadEventsQueries.updateEvent(UnreadEventTypeEntity.MESSAGE, currentMessageId, conversationId)
}

queries.updateMessageId(newMessageId, currentMessageId, conversationId)
queries.updateQuotedMessageId(newMessageId, currentMessageId, conversationId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wire.kalium.persistence.dao.message

import app.cash.turbine.test
import com.wire.kalium.persistence.BaseDatabaseTest
import com.wire.kalium.persistence.dao.QualifiedIDEntity
import com.wire.kalium.persistence.dao.UserDAO
Expand All @@ -43,6 +44,7 @@ import kotlin.test.Test
import kotlin.test.assertContains
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertIs
import kotlin.test.assertNotNull
import kotlin.test.assertTrue
Expand Down Expand Up @@ -264,6 +266,7 @@ class MessageDAOTest : BaseDatabaseTest() {
status = MessageEntity.Status.SENT
)
)

messageDAO.insertOrIgnoreMessages(allMessages)

messageDAO.markMessageAsDeleted(messageUuid, deleteMessageConversationId)
Expand All @@ -274,6 +277,8 @@ class MessageDAOTest : BaseDatabaseTest() {

val notDeletedMessage = messageDAO.getMessageById(messageUuid, visibleMessageConversationId)
assertTrue { notDeletedMessage?.visibility == MessageEntity.Visibility.VISIBLE }

assertFalse { messageDAO.observeUnreadEvents().first().containsKey(deleteMessageConversationId) }
}

@Test
Expand Down

0 comments on commit 6ee492b

Please sign in to comment.