Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Nov 30, 2023
1 parent 4f5a295 commit fe6e61e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ interface ConversationRepository {
conversationId: QualifiedID,
value: Boolean
): Either<CoreFailure, Unit>

suspend fun updateLegalHoldStatus(
conversationId: ConversationId,
legalHoldStatus: Conversation.LegalHoldStatus
): Either<CoreFailure, Unit>

suspend fun observeLegalHoldForConversation(conversationId: ConversationId): Flow<Either<StorageFailure, Conversation.LegalHoldStatus>>
}

@Suppress("LongParameterList", "TooManyFunctions", "LargeClass")
Expand Down Expand Up @@ -1074,6 +1081,24 @@ internal class ConversationDataSource internal constructor(
.wrapStorageRequest()
.mapToRightOr(true)

override suspend fun updateLegalHoldStatus(
conversationId: ConversationId,
legalHoldStatus: Conversation.LegalHoldStatus
): Either<CoreFailure, Unit> {
val legalHoldStatusEntity = conversationMapper.legalHoldStatusToEntity(legalHoldStatus)
return wrapStorageRequest {
conversationDAO.updateLegalHoldStatus(
conversationId = conversationId.toDao(),
legalHoldStatus = legalHoldStatusEntity
)
}
}

override suspend fun observeLegalHoldForConversation(conversationId: ConversationId) =
conversationDAO.observeLegalHoldForConversation(conversationId.toDao())
.map { conversationMapper.legalHoldStatusFromEntity(it) }
.wrapStorageRequest()

companion object {
const val DEFAULT_MEMBER_ROLE = "wire_member"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,33 @@ class ConversationRepositoryTest {
}
}

@Test
fun givenLegalHoldStatus_whenUpdateIsCalled_thenInvokeUpdateLegalHoldStatusFromOnce() = runTest {
val (arrange, conversationRepository) = Arrangement()
.arrange()

conversationRepository.updateLegalHoldStatus(CONVERSATION_ID, Conversation.LegalHoldStatus.ENABLED)

verify(arrange.conversationDAO)
.suspendFunction(arrange.conversationDAO::updateLegalHoldStatus)
.with(eq(CONVERSATION_ID.toDao()), any())
.wasInvoked(exactly = once)
}

@Test
fun givenConversationId_whenObservingLegalHoldStatus_thenInvokeObserveLegalHoldStatusFromOnce() = runTest {
val (arrange, conversationRepository) = Arrangement()
.withObserveLegalHoldStatus()
.arrange()

conversationRepository.observeLegalHoldForConversation(CONVERSATION_ID)

verify(arrange.conversationDAO)
.suspendFunction(arrange.conversationDAO::observeLegalHoldForConversation)
.with(eq(CONVERSATION_ID.toDao()))
.wasInvoked(exactly = once)
}

private class Arrangement :
MemberDAOArrangement by MemberDAOArrangementImpl() {

Expand Down Expand Up @@ -1683,6 +1710,13 @@ class ConversationRepositoryTest {
.thenReturn(response)
}

fun withObserveLegalHoldStatus() = apply {
given(conversationDAO)
.suspendFunction(conversationDAO::observeLegalHoldForConversation)
.whenInvokedWith(any())
.thenReturn(flowOf(ConversationEntity.LegalHoldStatus.ENABLED))
}

fun arrange() = this to conversationRepository
}

Expand Down
2 changes: 1 addition & 1 deletion persistence/src/commonMain/db_user/migrations/21.sqm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import com.wire.kalium.persistence.dao.conversation.ConversationEntity;

DROP VIEW ConversationDetails;
ALTER TABLE Conversation ADD COLUMN receipt_mode TEXT AS ConversationEntity.ReceiptMode DEFAULT "DISABLED";
ALTER TABLE Conversation ADD COLUMN receipt_mode TEXT AS ConversationEntity.ReceiptMode DEFAULT "DISABLED" NOT NULL;

CREATE VIEW IF NOT EXISTS ConversationDetails AS
SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ interface ConversationDAO {
suspend fun observeUnreadArchivedConversationsCount(): Flow<Long>
suspend fun observeDegradedConversationNotified(conversationId: QualifiedIDEntity): Flow<Boolean>
suspend fun updateDegradedConversationNotifiedFlag(conversationId: QualifiedIDEntity, updateFlag: Boolean)
suspend fun updateLegalHoldStatus(conversationId: QualifiedIDEntity, legalHoldStatus: ConversationEntity.LegalHoldStatus)
suspend fun observeLegalHoldForConversation(conversationId: QualifiedIDEntity): Flow<ConversationEntity.LegalHoldStatus>
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,17 @@ internal class ConversationDAOImpl internal constructor(
override suspend fun observeUnreadArchivedConversationsCount(): Flow<Long> =
unreadEventsQueries.getUnreadArchivedConversationsCount().asFlow().mapToOne()

override suspend fun updateLegalHoldStatus(
conversationId: QualifiedIDEntity,
legalHoldStatus: ConversationEntity.LegalHoldStatus
) = withContext(coroutineContext) {
conversationQueries.updateLegalHoldStatus(legalHoldStatus, conversationId)
}

override suspend fun observeLegalHoldForConversation(conversationId: QualifiedIDEntity) =
conversationQueries.selectLegalHoldStatus(conversationId)
.asFlow()
.mapToOneOrDefault(ConversationEntity.LegalHoldStatus.DISABLED)
.flowOn(coroutineContext)

}

0 comments on commit fe6e61e

Please sign in to comment.