Skip to content

Commit

Permalink
feat: Deleted users adjustments [WPB-1655] (#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski authored Dec 13, 2024
1 parent 9e75446 commit a346709
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
),
userId = conversationDetails.otherUser.id,
blockingState = conversationDetails.otherUser.BlockState,
isUserDeleted = conversationDetails.otherUser.deleted,
teamId = conversationDetails.otherUser.teamId,
isArchived = conversationDetails.conversation.archived,
mlsVerificationStatus = conversationDetails.conversation.mlsVerificationStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ sealed class ConversationTypeDetail {
data class Private(
val avatarAsset: UserAvatarAsset?,
val userId: UserId,
val blockingState: BlockingState
val blockingState: BlockingState,
val isUserDeleted: Boolean
) : ConversationTypeDetail()

data class Connection(val avatarAsset: UserAvatarAsset?) : ConversationTypeDetail()
Expand Down Expand Up @@ -131,7 +132,8 @@ data class ConversationSheetContent(

fun canEditNotifications(): Boolean = isSelfUserMember
&& ((conversationTypeDetail is ConversationTypeDetail.Private
&& (conversationTypeDetail.blockingState != BlockingState.BLOCKED))
&& (conversationTypeDetail.blockingState != BlockingState.BLOCKED)
&& !conversationTypeDetail.isUserDeleted)
|| conversationTypeDetail is ConversationTypeDetail.Group)

fun canDeleteGroup(): Boolean {
Expand All @@ -142,8 +144,11 @@ data class ConversationSheetContent(

fun canLeaveTheGroup(): Boolean = conversationTypeDetail is ConversationTypeDetail.Group && isSelfUserMember

fun canBlockUser(): Boolean =
conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState == BlockingState.NOT_BLOCKED
fun canBlockUser(): Boolean {
return conversationTypeDetail is ConversationTypeDetail.Private
&& conversationTypeDetail.blockingState == BlockingState.NOT_BLOCKED
&& !conversationTypeDetail.isUserDeleted
}

fun canUnblockUser(): Boolean =
conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState == BlockingState.BLOCKED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ fun rememberConversationSheetState(
} else conversationInfo.name,
mutingConversationState = mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Private(
userAvatarData.asset,
userId,
blockingState
avatarAsset = userAvatarData.asset,
userId = userId,
blockingState = blockingState,
isUserDeleted = isUserDeleted
),
isTeamConversation = isTeamConversation,
selfRole = Conversation.Member.Role.Member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ fun PreviewPrivateConversationItemWithBlockedBadge() = WireTheme {
isArchived = false,
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
isFavorite = false
isFavorite = false,
isUserDeleted = false
),
modifier = Modifier,
isSelectableItem = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ fun previewConversationList(count: Int, startIndex: Int = 0, unread: Boolean = f
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
searchQuery = searchQuery,
isFavorite = false
isFavorite = false,
isUserDeleted = false
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ sealed class ConversationItem : ConversationFolderItem {
val conversationInfo: ConversationInfo,
val userId: UserId,
val blockingState: BlockingState,
val isUserDeleted: Boolean,
override val conversationId: ConversationId,
override val mutedStatus: MutedConversationStatus,
override val showLegalHoldIndicator: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ fun ContentFooter(
exit = fadeOut(),
) {
// TODO show open conversation button for service bots after AR-2135
if (!state.isMetadataEmpty() && state.membership != Membership.Service && !state.isTemporaryUser()) {
val isNotTemporaryAndNotDeleted = !state.isTemporaryUser() && !state.isDeletedUser
if (!state.isMetadataEmpty() && state.membership != Membership.Service && isNotTemporaryAndNotDeleted) {
Surface(
shadowElevation = dimensions().bottomNavigationShadowElevation,
color = MaterialTheme.wireColorScheme.background
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,17 @@ class OtherUserProfileScreenViewModel @Inject constructor(
isUnderLegalHold = otherUser.isUnderLegalHold,
expiresAt = otherUser.expiresAt,
accentId = otherUser.accentId,
isDeletedUser = otherUser.deleted,
conversationSheetContent = conversation?.let {
ConversationSheetContent(
title = otherUser.name.orEmpty(),
conversationId = conversation.id,
mutingConversationState = conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Private(
userAvatarAsset,
userId,
otherUser.BlockState
avatarAsset = userAvatarAsset,
userId = userId,
blockingState = otherUser.BlockState,
isUserDeleted = otherUser.deleted
),
isTeamConversation = conversation.isTeamGroup(),
selfRole = Conversation.Member.Role.Member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ data class OtherUserProfileState(
val isConversationStarted: Boolean = false,
val expiresAt: Instant? = null,
val accentId: Int = -1,
val errorLoadingUser: ErrorLoadingUser? = null
val errorLoadingUser: ErrorLoadingUser? = null,
val isDeletedUser: Boolean = false
) {
fun updateMuteStatus(status: MutedConversationStatus): OtherUserProfileState {
return conversationSheetContent?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ object TestConversationItem {
isArchived = false,
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
isFavorite = false
isFavorite = false,
isUserDeleted = false
)

val GROUP = ConversationItem.GroupConversation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,160 @@
*/
package com.wire.android.ui.common.bottomsheet.conversation

import com.wire.android.framework.TestUser
import com.wire.android.ui.home.conversations.details.GroupConversationDetailsViewModelTest.Companion.testGroup
import com.wire.android.ui.home.conversationslist.model.BlockingState
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.TeamId
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class ConversationSheetContentTest {

@Test
fun givenTitleIsEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsTrue() = runTest {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))

val givenConversationSheetContent = ConversationSheetContent(
title = "",
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, false),
selfRole = Conversation.Member.Role.Member,
isTeamConversation = details.conversation.isTeamGroup(),
isArchived = false,
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
isUnderLegalHold = false,
isFavorite = false
)
val givenConversationSheetContent = createGroupSheetContent("")
val givenParticipantsCount = 1

assertEquals(true, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsEmptyAndTheGroupSizeIsGtOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))
val givenConversationSheetContent = createGroupSheetContent("")
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsNotEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
val givenConversationSheetContent = createGroupSheetContent("notEmpty")
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenPrivateConversationWithoutBlockedAndNotDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = false)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertTrue(canBlockUser)
}

@Test
fun givenGroupConversation_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent = createGroupSheetContent("")

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithBlockedAndNotDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

val givenConversationSheetContent = ConversationSheetContent(
title = "",
// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithoutBlockedAndDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = true)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithoutBlockedAndNotDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertTrue(canEditNotifications)
}

@Test
fun givenGroupConversation_whenCanEditNotificationsIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent = createGroupSheetContent("")

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertTrue(canEditNotifications)
}

@Test
fun givenPrivateConversationWithBlockedAndNotDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertFalse(canEditNotifications)
}

@Test
fun givenPrivateConversationWithoutBlockedAndDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertFalse(canEditNotifications)
}

private fun createPrivateSheetContent(
blockingState: BlockingState,
isUserDeleted: Boolean
): ConversationSheetContent {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))
return ConversationSheetContent(
title = "notEmpty",
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, false),
conversationTypeDetail = ConversationTypeDetail.Private(
avatarAsset = null,
userId = TestUser.USER_ID,
blockingState = blockingState,
isUserDeleted = isUserDeleted
),
selfRole = Conversation.Member.Role.Member,
isTeamConversation = details.conversation.isTeamGroup(),
isArchived = false,
Expand All @@ -67,17 +180,15 @@ class ConversationSheetContentTest {
isUnderLegalHold = false,
isFavorite = false
)
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsNotEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
private fun createGroupSheetContent(
title: String
): ConversationSheetContent {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))

val givenConversationSheetContent = ConversationSheetContent(
title = "notEmpty",
return ConversationSheetContent(
title = title,
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, false),
Expand All @@ -90,8 +201,5 @@ class ConversationSheetContentTest {
isUnderLegalHold = false,
isFavorite = false
)
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}
}

0 comments on commit a346709

Please sign in to comment.