Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove unread event after mark delete message [WPB-4452] #2132

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading