diff --git a/composeApp/src/androidMain/kotlin/mobi/giza/compose/ExperimentalFeatures.android.kt b/composeApp/src/androidMain/kotlin/mobi/giza/compose/ExperimentalFeatures.android.kt new file mode 100644 index 00000000..43db5092 --- /dev/null +++ b/composeApp/src/androidMain/kotlin/mobi/giza/compose/ExperimentalFeatures.android.kt @@ -0,0 +1,5 @@ +package mobi.giza.compose + +import mobi.giza.android.BuildConfig + +actual fun isDevelopmentBuild(): Boolean = BuildConfig.DEBUG diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 6cafefea..79166d68 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -114,6 +114,19 @@ Rotate shares without them? They are out of the room, but their share of the group key still helps sign until the shares are rotated without them. Rotating asks every remaining member to take part. Shares held before the rotation stop working once every device has deleted them. Rotate shares + Shares + Generation %1$d + Holds a share + Waiting to be brought back + Removed for good + %1$s (you) + Rotating gives every member a new share of the same key, so the group keeps its room and everything it has signed. Shares held before stop working once every device has deleted them. A rotation does not undo a compromised account. + Ask to be brought back + Approve + Take part in rotating the shares + Store your new share + Help bring a member back + Sent to the group Share rotation proposed; every remaining member is asked to take part Library Lightning invoice diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt new file mode 100644 index 00000000..2d1b6d65 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ExperimentalFeatures.kt @@ -0,0 +1,22 @@ +package mobi.giza.compose + +/** + * Features built but not shipped: on in a debug or development build, off in a + * release one, and overridable in tests. + * + * Share rotation (docs/frost-share-refresh.md, D4) stays here until upstream + * drops "experimental" from the secp256k1-zkp enrollment module and the + * frost_refresh module has had independent review. Off, the app offers no + * rotation or repair, and declines a rotation it is asked to take part in, + * out loud. + */ +object ExperimentalFeatures { + /** Set by a test that has to see the build a release would be. */ + var shareRefreshOverride: Boolean? = null + + val shareRefresh: Boolean + get() = shareRefreshOverride ?: isDevelopmentBuild() +} + +/** Whether this is a debug or development build of the app, rather than a release. */ +expect fun isDevelopmentBuild(): Boolean diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt index c7c28652..2dcc72df 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt @@ -41,6 +41,16 @@ import mobi.giza.compose.database.model.types.MarmotReindexReport import mobi.giza.compose.identity.Identity import mobi.giza.compose.identity.toKeyPair import mobi.giza.compose.managers.ShareRefreshManager +import mobi.giza.compose.ui.view.state.SharesSummary +import mobi.giza.compose.database.model.types.ShareStanding +import mobi.giza.compose.database.model.types.ShareRepairStage +import mobi.giza.compose.database.model.types.ShareRefreshStage +import mobi.giza.compose.database.model.types.ShareRefreshApprovalStep +import mobi.giza.compose.database.model.types.DkgRitualStage +import mobi.giza.compose.database.model.DkgSession +import mobi.giza.compose.managers.ShareGenerations +import mobi.giza.compose.managers.ShareRepairManager +import mobi.giza.compose.ExperimentalFeatures import mobi.giza.compose.managers.ChronicleManager import mobi.giza.compose.managers.FrostSigningManager import mobi.giza.compose.managers.GroupKeyStateManager @@ -633,7 +643,82 @@ class DatabaseChatRepository( } override suspend fun holdsShare(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): Boolean = - runCatching { ShareRefreshManager.liveIdOf(database, localChatRoom, memberPublicKey) != null }.getOrDefault(false) + ExperimentalFeatures.shareRefresh && + runCatching { ShareRefreshManager.liveIdOf(database, localChatRoom, memberPublicKey) != null }.getOrDefault(false) + + /** The key the room's Shares section is about: the one its key state names, else the one this device signs it with. */ + private suspend fun shareKeyOf(localChatRoom: LocalChatRoom): DkgSession? { + val roomId = localChatRoom.chatRoom.id + return GroupKeyStateManager.keyStateFor(database, roomId)?.dkgSessionId?.let { database.dkgSessionDao().getSessionById(it) } + ?.takeIf { it.stage == DkgRitualStage.COMPLETE } + ?: FrostSigningManager.completedKey(database, roomId) + } + + override suspend fun sharesSummary(localChatRoom: LocalChatRoom): SharesSummary? = runCatching { + if (localChatRoom.chatRoom.mlsGroupState == null) return null + val key = shareKeyOf(localChatRoom) ?: return null + val me = localChatRoom.chatRoom.userPublicKey + val shares = ShareGenerations.active(database, key) + if (shares.roster.isEmpty()) return null + val names = localChatRoom.localParticipants.associate { it.participant.participantPublicKey to it.profile?.humanReadableNameOrPubkey() } + val refreshes = database.shareRefreshDao().getSessionsForKey(key.id) + val repairs = database.shareRepairDao().getSessionsForKey(key.id) + val pending = refreshes.mapNotNull { session -> + when (ShareRefreshManager.pendingApproval(database, session)) { + ShareRefreshApprovalStep.DEAL -> SharesSummary.PendingApproval(session.id, SharesSummary.PendingApproval.Kind.REFRESH_DEAL) + ShareRefreshApprovalStep.CONFIRM -> SharesSummary.PendingApproval(session.id, SharesSummary.PendingApproval.Kind.REFRESH_CONFIRM) + null -> null + } + } + repairs.filter { ShareRepairManager.isAwaitingApproval(database, it) } + .map { SharesSummary.PendingApproval(it.id, SharesSummary.PendingApproval.Kind.REPAIR_HELP) } + val running = refreshes.any { it.stage != ShareRefreshStage.COMPLETE && it.stage != ShareRefreshStage.FAILED } + val mine = shares.roster.firstOrNull { it.memberPublicKey == me } + val repairing = repairs.any { it.targetPublicKey == me && it.stage != ShareRepairStage.FAILED && it.stage != ShareRepairStage.COMPLETE } + SharesSummary( + generation = shares.generation, + members = shares.roster.map { entry -> + SharesSummary.Member(entry.memberPublicKey, names[entry.memberPublicKey] ?: entry.memberPublicKey.take(8), entry.standing, entry.memberPublicKey == me) + }, + pending = if (ExperimentalFeatures.shareRefresh) pending else emptyList(), + canRotate = ExperimentalFeatures.shareRefresh && shares.secretShare != null && !running, + canAskToBeRepaired = ExperimentalFeatures.shareRefresh && mine?.standing == ShareStanding.STALE && !repairing, + ) + }.getOrNull() + + private fun failureOf(t: Throwable?): String? = t?.let { it.message ?: it::class.simpleName ?: "Unknown error" } + + private fun privateKeyOrNull(): Pair? { + val identity = activeIdentity.value ?: return null + val privateKey = identity.toKeyPair().privKey ?: return null + return identity.nostrPublicKey to privateKey + } + + override suspend fun rotateShares(localChatRoom: LocalChatRoom): String? { + val (me, privateKey) = privateKeyOrNull() ?: return "This identity cannot sign" + val key = shareKeyOf(localChatRoom) ?: return "This group has no shared key" + return failureOf(runCatching { ShareRefreshManager.proposeRefresh(database, localChatRoom, me, privateKey, key) }.exceptionOrNull()) + } + + override suspend fun approveShares(localChatRoom: LocalChatRoom, approval: SharesSummary.PendingApproval): String? { + val (_, privateKey) = privateKeyOrNull() ?: return "This identity cannot sign" + return failureOf(runCatching { + when (approval.kind) { + SharesSummary.PendingApproval.Kind.REFRESH_DEAL, SharesSummary.PendingApproval.Kind.REFRESH_CONFIRM -> + ShareRefreshManager.approve(database, localChatRoom, approval.sessionId, privateKey) + SharesSummary.PendingApproval.Kind.REPAIR_HELP -> + ShareRepairManager.approve(database, localChatRoom, approval.sessionId, privateKey) + } + }.exceptionOrNull()) + } + + override suspend fun abandonRotation(localChatRoom: LocalChatRoom, sessionId: String): String? = + failureOf(runCatching { ShareRefreshManager.abandon(database, localChatRoom, sessionId) }.exceptionOrNull()) + + override suspend fun askToBeRepaired(localChatRoom: LocalChatRoom): String? { + val (me, privateKey) = privateKeyOrNull() ?: return "This identity cannot sign" + val key = shareKeyOf(localChatRoom) ?: return "This group has no shared key" + return failureOf(runCatching { ShareRepairManager.requestRepair(database, localChatRoom, me, privateKey, key) }.exceptionOrNull()) + } override suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? { val identity = activeIdentity.value ?: return "No identity is signed in" diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt index 160ff004..2cc97bd7 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRefreshManager.kt @@ -34,6 +34,7 @@ import mobi.giza.compose.database.model.types.ShareGenerationState import mobi.giza.compose.database.model.types.ShareRefreshApprovalStep import mobi.giza.compose.database.model.types.ShareRefreshStage import mobi.giza.compose.database.model.types.ShareStanding +import mobi.giza.compose.ExperimentalFeatures import mobi.giza.compose.extensions.toHex import mobi.giza.compose.nostr.frost.ShareRefreshEvents @@ -122,6 +123,7 @@ object ShareRefreshManager { key: DkgSession, withheld: Map = emptyMap(), ): ShareRefreshSession { + check(ExperimentalFeatures.shareRefresh) { "This build does not rotate shares" } require(key.stage == DkgRitualStage.COMPLETE) { "Ceremony ${key.id} has not produced a key" } require(isKeysRoom(database, localChatRoom, key)) { "${localChatRoom.chatRoom.id} is not the room key ${key.id} signs as" } @@ -285,6 +287,9 @@ object ShareRefreshManager { ) val reason = when { + // Built but not shipped (D4): a release build declines, out loud, rather + // than leaving a refresh that needs it waiting forever. + !ExperimentalFeatures.shareRefresh -> "this build cannot rotate shares" base != active.generation -> "it refreshes generation $base, and this device is at generation ${active.generation}" proposer == null || proposer !in recipients -> "its proposer is not one of its recipients" running(database, key) != null -> "another refresh of this key is still running here" diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRepairManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRepairManager.kt index 55542a2d..41dcaa31 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRepairManager.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ShareRepairManager.kt @@ -30,6 +30,7 @@ import mobi.giza.compose.database.model.intermdiate.LocalChatRoom import mobi.giza.compose.database.model.types.DkgRitualStage import mobi.giza.compose.database.model.types.ShareRepairStage import mobi.giza.compose.database.model.types.ShareStanding +import mobi.giza.compose.ExperimentalFeatures import mobi.giza.compose.extensions.toHex import mobi.giza.compose.nostr.frost.ShareRepairEvents @@ -71,6 +72,7 @@ object ShareRepairManager { key: DkgSession, targetId: Int? = null, ): ShareRepairSession { + check(ExperimentalFeatures.shareRefresh) { "This build does not repair shares" } require(key.stage == DkgRitualStage.COMPLETE) { "Ceremony ${key.id} has not produced a key" } val shares = ShareGenerations.active(database, key) val id = targetId ?: shares.roster.firstOrNull { it.memberPublicKey == userPublicKey }?.participantId @@ -135,6 +137,7 @@ object ShareRepairManager { private suspend fun acceptRequest(database: GizaDatabase, localChatRoom: LocalChatRoom, event: Event, sessionId: String, userPublicKey: HexKey): ShareRepairSession? { database.shareRepairDao().getSessionById(sessionId)?.let { return it } + if (!ExperimentalFeatures.shareRefresh) return null val tag = { name: String -> ShareRepairEvents.value(event.tags, name) } val key = tag(ShareRepairEvents.KEY_TAG)?.let { database.dkgSessionDao().getSessionById(it) }?.takeIf { it.stage == DkgRitualStage.COMPLETE } ?: return null val generation = tag(ShareRepairEvents.GENERATION_TAG)?.toIntOrNull() ?: return null diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt index 0cc98225..cd4e6cad 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/repository/ChatRepository.kt @@ -21,6 +21,7 @@ import mobi.giza.compose.managers.MarmotGroupCreation import mobi.giza.compose.managers.SharedKeyDerivation import mobi.giza.compose.managers.SubgroupManager import mobi.giza.compose.nostr.MarmotProfile +import mobi.giza.compose.ui.view.state.SharesSummary interface ChatRepository { suspend fun observeChatRoomListByPublicKey(publicKey: String): Flow> @@ -272,6 +273,21 @@ interface ChatRepository { */ suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? + /** The room's key as the Shares section shows it, or null when the room has none. */ + suspend fun sharesSummary(localChatRoom: LocalChatRoom): SharesSummary? + + /** Proposes rotating every share of the room's key. Null on success, or why not. */ + suspend fun rotateShares(localChatRoom: LocalChatRoom): String? + + /** Answers what [approval] asks. Null on success, or why not. */ + suspend fun approveShares(localChatRoom: LocalChatRoom, approval: SharesSummary.PendingApproval): String? + + /** Ends the rotation [sessionId] for everyone. Null on success, or why not. */ + suspend fun abandonRotation(localChatRoom: LocalChatRoom, sessionId: String): String? + + /** Asks the group to bring this device's stale id back. Null on success, or why not. */ + suspend fun askToBeRepaired(localChatRoom: LocalChatRoom): String? + /** * Disbands a current-profile room this device administers. Absorbing: once the * disband commit is applied nobody rejoins, and a replacement conversation is a @@ -464,6 +480,16 @@ interface ChatRepository { override suspend fun rotateSharesWithout(localChatRoom: LocalChatRoom, memberPublicKey: HexKey): String? = null + override suspend fun sharesSummary(localChatRoom: LocalChatRoom): SharesSummary? = null + + override suspend fun rotateShares(localChatRoom: LocalChatRoom): String? = null + + override suspend fun approveShares(localChatRoom: LocalChatRoom, approval: SharesSummary.PendingApproval): String? = null + + override suspend fun abandonRotation(localChatRoom: LocalChatRoom, sessionId: String): String? = null + + override suspend fun askToBeRepaired(localChatRoom: LocalChatRoom): String? = null + override suspend fun disbandChatRoom(localChatRoom: LocalChatRoom) = Unit override suspend fun softDeleteChatRoom( diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt index 204e780e..2b3ac801 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt @@ -102,6 +102,23 @@ import mobi.giza.compose.resources.direct_message_functionality_will_be_here import mobi.giza.compose.resources.invite_new_member import mobi.giza.compose.resources.leave_group import mobi.giza.compose.resources.remove_from_group +import mobi.giza.compose.resources.shares_action_sent +import mobi.giza.compose.resources.pending_repair_help +import mobi.giza.compose.resources.pending_rotation_confirm +import mobi.giza.compose.resources.pending_rotation_deal +import mobi.giza.compose.resources.abandon +import mobi.giza.compose.resources.approve +import mobi.giza.compose.resources.ask_to_be_brought_back +import mobi.giza.compose.resources.shares_rotation_caveat +import mobi.giza.compose.resources.share_standing_you +import mobi.giza.compose.resources.share_standing_retired +import mobi.giza.compose.resources.share_standing_stale +import mobi.giza.compose.resources.share_standing_live +import mobi.giza.compose.resources.share_generation +import mobi.giza.compose.resources.shares +import mobi.giza.compose.ui.view.state.SharesSummary +import mobi.giza.compose.database.model.types.ShareStanding +import androidx.compose.foundation.layout.Row import mobi.giza.compose.resources.share_rotation_requested import mobi.giza.compose.resources.not_now import mobi.giza.compose.resources.rotate_shares @@ -167,6 +184,7 @@ fun ChatRoomDetailScreen( val notify = rememberNotifier(rememberCoroutineScope()) val removalRequested = stringResource(Res.string.member_removal_requested) val rotationRequested = stringResource(Res.string.share_rotation_requested) + val sharesActionSent = stringResource(Res.string.shares_action_sent) // Offered after removing a member who still holds a share of the room's key: // the removal took them out of the room, not out of the key @@ -343,6 +361,118 @@ fun ChatRoomDetailScreen( HorizontalDivider() } + // The room's key, share by share (docs/frost-share-refresh.md, + // Phase 11): which generation the group signs with, who + // holds what, what this device is being asked, and the two + // things it may start. Absent where the room has no key. + chatRoomDetailUIState.shares?.let { shares -> + item { + Text( + text = stringResource(Res.string.shares), + style = MaterialTheme.typography.labelMedium + ) + } + item { + Text( + text = stringResource(Res.string.share_generation, shares.generation), + style = MaterialTheme.typography.bodyMedium + ) + } + items(items = shares.members, key = { member -> "share-${member.publicKey}" }) { member -> + ListItem( + headlineContent = { + Text(if (member.isSelf) stringResource(Res.string.share_standing_you, member.name) else member.name) + }, + supportingContent = { + Text( + stringResource( + when (member.standing) { + ShareStanding.LIVE -> Res.string.share_standing_live + ShareStanding.STALE -> Res.string.share_standing_stale + ShareStanding.RETIRED -> Res.string.share_standing_retired + } + ) + ) + } + ) + } + items(items = shares.pending, key = { approval -> "pending-${approval.sessionId}-${approval.kind}" }) { approval -> + ListItem( + headlineContent = { + Text( + stringResource( + when (approval.kind) { + SharesSummary.PendingApproval.Kind.REFRESH_DEAL -> Res.string.pending_rotation_deal + SharesSummary.PendingApproval.Kind.REFRESH_CONFIRM -> Res.string.pending_rotation_confirm + SharesSummary.PendingApproval.Kind.REPAIR_HELP -> Res.string.pending_repair_help + } + ) + ) + }, + trailingContent = { + Row(horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) { + if (approval.kind != SharesSummary.PendingApproval.Kind.REPAIR_HELP) { + TextButton( + onClick = { + chatRoomDetailViewModel.abandonRotation(chatRoomDetailUIState.localChatRoom, approval.sessionId) { failure -> + notify(failure ?: sharesActionSent) + } + } + ) { + Text(stringResource(Res.string.abandon)) + } + } + FilledTonalButton( + onClick = { + chatRoomDetailViewModel.approveShares(chatRoomDetailUIState.localChatRoom, approval) { failure -> + notify(failure ?: sharesActionSent) + } + } + ) { + Text(stringResource(Res.string.approve)) + } + } + } + ) + } + if (shares.canRotate || shares.canAskToBeRepaired) { + item { + Column(verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap)) { + Text( + text = stringResource(Res.string.shares_rotation_caveat), + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onSurfaceVariant + ) + if (shares.canRotate) { + FilledTonalButton( + onClick = { + chatRoomDetailViewModel.rotateShares(chatRoomDetailUIState.localChatRoom) { failure -> + notify(failure ?: rotationRequested) + } + } + ) { + Text(stringResource(Res.string.rotate_shares)) + } + } + if (shares.canAskToBeRepaired) { + TextButton( + onClick = { + chatRoomDetailViewModel.askToBeRepaired(chatRoomDetailUIState.localChatRoom) { failure -> + notify(failure ?: sharesActionSent) + } + } + ) { + Text(stringResource(Res.string.ask_to_be_brought_back)) + } + } + } + } + } + item { + HorizontalDivider() + } + } + item { Text( text = stringResource(Res.string.subgroups), diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt index f67a7b78..3cb13a0e 100644 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatRoomDetailViewModel.kt @@ -27,6 +27,7 @@ import mobi.giza.compose.repository.NostrRepository import mobi.giza.compose.ui.composable.navigation.routes.HomeRoute import mobi.giza.compose.ui.composable.navigation.routes.Route import mobi.giza.compose.ui.view.state.ChatRoomDetailUIState +import mobi.giza.compose.ui.view.state.SharesSummary class ChatRoomDetailViewModel( val chatRoomId: String, @@ -106,6 +107,7 @@ class ChatRoomDetailViewModel( subgroupsNeedAWallet = canSign && subgroupsNeedAWallet, canGovern = canGovern, isDisbanded = isDisbanded, + shares = chatRepository.sharesSummary(localChatRoom), ) } } @@ -134,6 +136,31 @@ class ChatRoomDetailViewModel( } } + /** + * Runs one Shares section action, reloads the screen, and reports: null for + * done, or why not. Every one of them is a proposal or an answer the group + * goes on with in the background, so done means sent, not finished. + */ + private fun sharesAction(onDone: (String?) -> Unit, action: suspend () -> String?) { + viewModelScope.launch(Dispatchers.IO) { + val failure = action() + initiateChatRoomDetail() + viewModelScope.launch(Dispatchers.Main) { onDone(failure) } + } + } + + fun rotateShares(localChatRoom: LocalChatRoom, onDone: (String?) -> Unit) = + sharesAction(onDone) { chatRepository.rotateShares(localChatRoom) } + + fun approveShares(localChatRoom: LocalChatRoom, approval: SharesSummary.PendingApproval, onDone: (String?) -> Unit) = + sharesAction(onDone) { chatRepository.approveShares(localChatRoom, approval) } + + fun abandonRotation(localChatRoom: LocalChatRoom, sessionId: String, onDone: (String?) -> Unit) = + sharesAction(onDone) { chatRepository.abandonRotation(localChatRoom, sessionId) } + + fun askToBeRepaired(localChatRoom: LocalChatRoom, onDone: (String?) -> Unit) = + sharesAction(onDone) { chatRepository.askToBeRepaired(localChatRoom) } + /** A removed member who still holds a share of the room's key, for the offer to rotate without them. */ data class RotationOffer(val localChatRoom: LocalChatRoom, val memberPublicKey: HexKey) diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt index acb5c4e6..5b7b8511 100755 --- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/ChatRoomDetailUIState.kt @@ -78,6 +78,12 @@ sealed interface ChatRoomDetailUIState { * and nobody rejoins, so every write entrance is hidden and the room says so. */ val isDisbanded: Boolean = false, + /** + * The room's key as the Shares section shows it: the generation, who + * holds what, and what this device is asked or may start. Null when the + * room has no key (docs/frost-share-refresh.md, Phase 11). + */ + val shares: SharesSummary? = null, ): ChatRoomDetailUIState data class Error( diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/SharesSummary.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/SharesSummary.kt new file mode 100644 index 00000000..720377f0 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/SharesSummary.kt @@ -0,0 +1,26 @@ +package mobi.giza.compose.ui.view.state + +import com.vitorpamplona.quartz.nip01Core.core.HexKey +import mobi.giza.compose.database.model.types.ShareStanding + +/** + * A room's key, as the Shares section shows it (docs/frost-share-refresh.md, + * Phase 11): the generation the group signs with, who holds what, what this + * device is being asked, and what it may start. + */ +data class SharesSummary( + val generation: Int, + val members: List, + val pending: List, + /** This device holds a live share and no rotation is running: it may propose one. */ + val canRotate: Boolean, + /** This device's own id is stale and nothing is bringing it back yet. */ + val canAskToBeRepaired: Boolean, +) { + data class Member(val publicKey: HexKey, val name: String, val standing: ShareStanding, val isSelf: Boolean) + + /** Something this device's owner is being asked, and the session it is for. */ + data class PendingApproval(val sessionId: String, val kind: Kind) { + enum class Kind { REFRESH_DEAL, REFRESH_CONFIRM, REPAIR_HELP } + } +} diff --git a/composeApp/src/iosMain/kotlin/mobi/giza/compose/ExperimentalFeatures.ios.kt b/composeApp/src/iosMain/kotlin/mobi/giza/compose/ExperimentalFeatures.ios.kt new file mode 100644 index 00000000..f8e99f15 --- /dev/null +++ b/composeApp/src/iosMain/kotlin/mobi/giza/compose/ExperimentalFeatures.ios.kt @@ -0,0 +1,6 @@ +package mobi.giza.compose + +import kotlin.experimental.ExperimentalNativeApi + +@OptIn(ExperimentalNativeApi::class) +actual fun isDevelopmentBuild(): Boolean = Platform.isDebugBinary diff --git a/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ExperimentalFeatures.jvm.kt b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ExperimentalFeatures.jvm.kt new file mode 100644 index 00000000..e683dab4 --- /dev/null +++ b/composeApp/src/jvmMain/kotlin/mobi/giza/compose/ExperimentalFeatures.jvm.kt @@ -0,0 +1,10 @@ +package mobi.giza.compose + +/** + * A packaged distribution carries a jar manifest with its version (see + * [AppVersion]); running from class directories -- gradle, a test -- does not. + * A packaged build can still opt in with `-Dgiza.experimental=true`. + */ +actual fun isDevelopmentBuild(): Boolean = + AppVersion::class.java.`package`?.implementationVersion == null || + System.getProperty("giza.experimental") == "true"