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: missing notifications due to LegalHold not Notified (WPB-10351) #2905

Merged
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 @@ -16,12 +16,12 @@ SELECT
Conversation.type AS conversationType,
Conversation.degraded_conversation_notified AS degradedConversationNotified,
Conversation.legal_hold_status AS legalHoldStatus,
LegalHoldNotified.legal_hold_status_change_notified AS legalHoldStatusChangeNotified
IFNULL(LegalHoldNotified.legal_hold_status_change_notified, 1) == 1 AS legalHoldStatusChangeNotified
Copy link
Contributor Author

@yamilmedina yamilmedina Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I assumed the default value from the table (Boolean = 1), but please @borichellow that has more context, correct me if otherwise :D

FROM Message
LEFT JOIN SelfUser
JOIN User ON Message.sender_user_id = User.qualified_id AND Message.content_type IN ('TEXT', 'RESTRICTED_ASSET', 'ASSET', 'KNOCK', 'MISSED_CALL', 'LOCATION')
JOIN Conversation AS Conversation ON Message.conversation_id == Conversation.qualified_id AND (Message.creation_date > IFNULL(Conversation.last_notified_date, 0))
JOIN ConversationLegalHoldStatusChangeNotified AS LegalHoldNotified ON Message.conversation_id == LegalHoldNotified.conversation_id AND (Message.creation_date > IFNULL(Conversation.last_notified_date, 0))
LEFT JOIN ConversationLegalHoldStatusChangeNotified AS LegalHoldNotified ON Message.conversation_id == LegalHoldNotified.conversation_id AND (Message.creation_date > IFNULL(Conversation.last_notified_date, 0))
LEFT JOIN MessageAssetContent AS AssetContent ON Message.id = AssetContent.message_id AND Message.conversation_id = AssetContent.conversation_id
LEFT JOIN MessageTextContent AS TextContent ON Message.id = TextContent.message_id AND Message.conversation_id = TextContent.conversation_id
WHERE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import com.wire.kalium.persistence.dao.QualifiedIDEntity
import com.wire.kalium.persistence.dao.UserAvailabilityStatusEntity
import com.wire.kalium.persistence.dao.conversation.ConversationEntity
import com.wire.kalium.persistence.utils.stubs.newRegularMessageEntity
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Clock
import kotlin.test.Test
Expand All @@ -32,7 +31,6 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.hours

@OptIn(ExperimentalCoroutinesApi::class)
class MessageNotificationsTest : BaseMessageTest() {

@Test
Expand Down Expand Up @@ -116,6 +114,24 @@ class MessageNotificationsTest : BaseMessageTest() {
}
}

@Test
fun givenConversation_whenNoLegalHoldNotified_thenNotificationIsPresent() = runTest {
val message = OTHER_MESSAGE
val messageOtherConvo2 = OTHER_MESSAGE_CONVO2
// going to super to not insert legal hold values
super.insertInitialData()
// just inserting legal hold for one conversation
conversationDAO.updateLegalHoldStatusChangeNotified(TEST_CONVERSATION_1.id, false)
messageDAO.insertOrIgnoreMessages(listOf(message, messageOtherConvo2))

messageDAO.getNotificationMessage().test {
val notifications = awaitItem()
assertEquals(2, notifications.size)
assertEquals(false, notifications.first { it.conversationId == TEST_CONVERSATION_1.id }.legalHoldStatusChangeNotified)
assertEquals(true, notifications.first { it.conversationId == TEST_CONVERSATION_2.id }.legalHoldStatusChangeNotified)
}
}

@Test
fun givenNewMessageInserted_whenConvInAllMutedState_thenNeedsToBeNotifyIsFalse() = runTest {
val conversationMutedStatus = ConversationEntity.MutedStatus.ALL_MUTED
Expand Down Expand Up @@ -392,6 +408,13 @@ class MessageNotificationsTest : BaseMessageTest() {
content = MessageEntityContent.Text(OTHER_MESSAGE_CONTENT)
)

val OTHER_MESSAGE_CONVO2 = newRegularMessageEntity(
id = "OTHER_MESSAGE",
conversationId = TEST_CONVERSATION_2.id,
senderUserId = ORIGINAL_MESSAGE_SENDER.id,
content = MessageEntityContent.Text(OTHER_MESSAGE_CONTENT)
)

val OTHER_QUOTING_OTHERS = newRegularMessageEntity(
id = "OTHER_QUOTING_OTHERS",
conversationId = TEST_CONVERSATION_1.id,
Expand Down
Loading