-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: notify user when sending first message in conversation on legal…
… hold [WPB-4566] (#2315) * feat: notify user when sending first message in conversation on legal hold [WPB-4566] * remove unused import * fix detekt * create separate table for legal hold change notified flag * upsert instead of update * update after merge * make use case implementation internal * make use case implementation internal * update after merge * fixes after merge
- Loading branch information
Showing
20 changed files
with
498 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...ire/kalium/logic/feature/conversation/ObserveConversationUnderLegalHoldNotifiedUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.conversation | ||
|
||
import com.wire.kalium.logic.data.conversation.Conversation | ||
import com.wire.kalium.logic.data.conversation.ConversationRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.functional.flatMapRightWithEither | ||
import com.wire.kalium.logic.functional.mapRight | ||
import com.wire.kalium.logic.functional.mapToRightOr | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
|
||
/** | ||
* UseCase for observing if User was notified about conversation being subject of legal hold | ||
*/ | ||
interface ObserveConversationUnderLegalHoldNotifiedUseCase { | ||
suspend operator fun invoke(conversationId: ConversationId): Flow<Boolean> | ||
} | ||
|
||
internal class ObserveConversationUnderLegalHoldNotifiedUseCaseImpl internal constructor( | ||
private val conversationRepository: ConversationRepository | ||
) : ObserveConversationUnderLegalHoldNotifiedUseCase { | ||
|
||
override suspend fun invoke(conversationId: ConversationId): Flow<Boolean> = | ||
conversationRepository.observeLegalHoldStatus(conversationId) | ||
.flatMapRightWithEither { legalHoldStatus -> | ||
conversationRepository.observeLegalHoldStatusChangeNotified(conversationId) | ||
.mapRight { isUserNotifiedAboutStatusChange -> | ||
when (legalHoldStatus) { | ||
Conversation.LegalHoldStatus.ENABLED -> isUserNotifiedAboutStatusChange | ||
else -> true // we only need to notify if legal hold was enabled | ||
} | ||
} | ||
} | ||
.mapToRightOr(true) | ||
.distinctUntilChanged() | ||
} |
37 changes: 37 additions & 0 deletions
37
...re/kalium/logic/feature/conversation/SetNotifiedAboutConversationUnderLegalHoldUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.conversation | ||
|
||
import com.wire.kalium.logic.data.conversation.ConversationRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
|
||
/** | ||
* UseCase for setting legal_hold_change_notified flag to true, | ||
* it means that User was notified about the recent change in legal hold status. | ||
*/ | ||
interface SetNotifiedAboutConversationUnderLegalHoldUseCase { | ||
suspend operator fun invoke(conversationId: ConversationId) | ||
} | ||
|
||
internal class SetNotifiedAboutConversationUnderLegalHoldUseCaseImpl internal constructor( | ||
private val conversationRepository: ConversationRepository | ||
) : SetNotifiedAboutConversationUnderLegalHoldUseCase { | ||
override suspend fun invoke(conversationId: ConversationId) { | ||
conversationRepository.setLegalHoldStatusChangeNotified(conversationId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...kalium/logic/feature/conversation/ObserveConversationUnderLegalHoldNotifiedUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.kalium.logic.feature.conversation | ||
|
||
import com.wire.kalium.logic.StorageFailure | ||
import com.wire.kalium.logic.data.conversation.Conversation | ||
import com.wire.kalium.logic.data.conversation.ConversationRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.functional.Either | ||
import com.wire.kalium.logic.functional.map | ||
import io.mockative.Mock | ||
import io.mockative.any | ||
import io.mockative.given | ||
import io.mockative.mock | ||
import kotlinx.coroutines.flow.first | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ObserveConversationUnderLegalHoldNotifiedUseCaseTest { | ||
|
||
private fun testObserving( | ||
given: Either<StorageFailure, Pair<Conversation.LegalHoldStatus, Boolean>>, | ||
expected: Boolean | ||
) = runTest { | ||
// given | ||
val conversationId = ConversationId("conversationId", "domain") | ||
val (_, useCase) = Arrangement() | ||
.withObserveLegalHoldStatusForConversation(given.map { it.first }) | ||
.withObserveLegalHoldStatusChangeNotifiedForConversation(given.map { it.second }) | ||
.arrange() | ||
// when | ||
val result = useCase.invoke(conversationId) | ||
// then | ||
assertEquals(expected, result.first()) | ||
} | ||
|
||
@Test | ||
fun givenFailure_whenObserving_thenReturnTrue() = | ||
testObserving(Either.Left(StorageFailure.DataNotFound), true) | ||
@Test | ||
fun givenLegalHoldEnabledAndNotNotified_whenObserving_thenReturnFalse() = | ||
testObserving(Either.Right(Conversation.LegalHoldStatus.ENABLED to false), false) | ||
@Test | ||
fun givenLegalHoldEnabledAndNotified_whenObserving_thenReturnTrue() = | ||
testObserving(Either.Right(Conversation.LegalHoldStatus.ENABLED to true), true) | ||
@Test | ||
fun givenLegalHoldDisabledAndNotNotified_whenObserving_thenReturnFalse() = | ||
testObserving(Either.Right(Conversation.LegalHoldStatus.DISABLED to false), true) | ||
@Test | ||
fun givenLegalHoldDisabledAndNotified_whenObserving_thenReturnTrue() = | ||
testObserving(Either.Right(Conversation.LegalHoldStatus.DISABLED to true), true) | ||
|
||
private class Arrangement() { | ||
@Mock | ||
val conversationRepository = mock(ConversationRepository::class) | ||
|
||
private val useCase: ObserveConversationUnderLegalHoldNotifiedUseCase by lazy { | ||
ObserveConversationUnderLegalHoldNotifiedUseCaseImpl(conversationRepository) | ||
} | ||
|
||
fun arrange() = this to useCase | ||
fun withObserveLegalHoldStatusForConversation( | ||
result: Either<StorageFailure, Conversation.LegalHoldStatus> | ||
) = apply { | ||
given(conversationRepository) | ||
.suspendFunction(conversationRepository::observeLegalHoldStatus) | ||
.whenInvokedWith(any()) | ||
.thenReturn(flowOf(result)) | ||
} | ||
fun withObserveLegalHoldStatusChangeNotifiedForConversation( | ||
result: Either<StorageFailure, Boolean> | ||
) = apply { | ||
given(conversationRepository) | ||
.suspendFunction(conversationRepository::observeLegalHoldStatusChangeNotified) | ||
.whenInvokedWith(any()) | ||
.thenReturn(flowOf(result)) | ||
} | ||
} | ||
} |
Oops, something went wrong.