Skip to content

Commit 3d0a35e

Browse files
committed
fix(moderators): Give the owner-demote preview a moderating conversation
ParticipantOperationsSheetOwnerPreview passed conversation = null and spreedCapabilities = null, so computeVisibility() always took the !canModerate early return and rendered the same header-only state as ParticipantOperationsSheetInformationalPreview - the two previews were indistinguishable despite different names. Add previewConversation()/previewCapabilities() and pass a group conversation the previewing user owns, with the promote-demote-owner capability, so the preview actually exercises the demote-owner-to-moderator and demote-owner-to-user rows it is meant to show. Assisted-by: Claude Code:claude-sonnet-5 Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
1 parent bbdb32c commit 3d0a35e

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

app/src/main/java/com/nextcloud/talk/conversationinfo/ui/ParticipantOperationsSheet.kt

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ import com.nextcloud.talk.R
4343
import com.nextcloud.talk.conversationinfo.model.ParticipantModel
4444
import com.nextcloud.talk.models.domain.ConversationModel
4545
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
46+
import com.nextcloud.talk.models.json.conversations.ConversationEnums
4647
import com.nextcloud.talk.models.json.participants.Participant
4748
import com.nextcloud.talk.utils.CapabilitiesUtil
4849
import com.nextcloud.talk.utils.ConversationUtils
4950
import com.nextcloud.talk.utils.ParticipantRole
5051
import com.nextcloud.talk.utils.ParticipantRoleUtils
52+
import com.nextcloud.talk.utils.SpreedFeatures
5153

5254
private data class RemoveOption(@DrawableRes val iconRes: Int, val label: String)
5355

@@ -307,6 +309,37 @@ private fun previewParticipant(
307309
isSelf = isSelf
308310
)
309311

312+
/** A group conversation moderated by the previewing user, satisfying canModerate(). */
313+
private fun previewConversation() =
314+
ConversationModel(
315+
internalId = "1@token",
316+
accountId = 1L,
317+
token = "token",
318+
name = "conversation",
319+
displayName = "Conversation",
320+
description = "",
321+
type = ConversationEnums.ConversationType.ROOM_GROUP_CALL,
322+
participantType = Participant.ParticipantType.OWNER,
323+
sessionId = "",
324+
actorId = "self",
325+
actorType = "users",
326+
objectType = ConversationEnums.ObjectType.DEFAULT,
327+
notificationLevel = ConversationEnums.NotificationLevel.DEFAULT,
328+
conversationReadOnlyState = ConversationEnums.ConversationReadOnlyState.CONVERSATION_READ_WRITE,
329+
lobbyState = ConversationEnums.LobbyState.LOBBY_STATE_ALL_PARTICIPANTS,
330+
lobbyTimer = 0L,
331+
canLeaveConversation = true,
332+
canDeleteConversation = true,
333+
unreadMentionDirect = false,
334+
notificationCalls = 0,
335+
avatarVersion = "",
336+
hasCustomAvatar = false,
337+
callStartTime = 0L
338+
)
339+
340+
private fun previewCapabilities(vararg features: SpreedFeatures) =
341+
SpreedCapability(features = features.map { it.value }, config = null, version = "")
342+
310343
@Composable
311344
private fun ParticipantOpsPreviewWrapper(content: @Composable () -> Unit) {
312345
val colors = if (isSystemInDarkTheme()) darkColorScheme() else lightColorScheme()
@@ -374,6 +407,7 @@ private fun ParticipantOperationsSheetInformationalPreview() {
374407
}
375408
}
376409

410+
/** With moderation rights and the capability, another owner can be demoted from the sheet. */
377411
@Preview(showBackground = true, name = "Light")
378412
@Preview(showBackground = true, name = "Dark", uiMode = Configuration.UI_MODE_NIGHT_YES)
379413
@Composable
@@ -385,8 +419,8 @@ private fun ParticipantOperationsSheetOwnerPreview() {
385419
Participant.ParticipantType.OWNER,
386420
ParticipantRole.OWNER
387421
),
388-
conversation = null,
389-
spreedCapabilities = null,
422+
conversation = previewConversation(),
423+
spreedCapabilities = previewCapabilities(SpreedFeatures.PROMOTE_DEMOTE_OWNER),
390424
onAction = {}
391425
)
392426
}

0 commit comments

Comments
 (0)