feat: the room's details say who administers it, and whether the founders do (robust-group-admins, Phase 5)
The member list labels admins, from the flags AdminFlags keeps. Two cards on the error container, under the signing key and the parent: founding members the room's policy does not list as admins, with "Make them admins" for an admin of a current-profile room; and founding members the founding invite never reached, with "Invite them" on the device that holds the room at epoch 0. Founders are named through their profiles, since an uninvited one is not in the room to read a row off. A robust group's NIP-17 room has no admins of its own, so its details link to the admin room its ceremony made (ChatRepository.adminRoomOf), saying every member is an admin there. Strings in the catalogue, sentence case; colours from the error container roles; spacing from the scale; the actions guard a second tap. m3Audit: all budgets met. jvmTest 1249/1249, compileDebugKotlinAndroid. Not looked at in a running app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1dc94ad423
commit
baf63b8d7a
6 files changed
+281
-9
No files matched your search
@@ -479,4 +479,16 @@
|
||||
<string name="waiting_on_s_since_s">Waiting on %1$s since %2$s.</string>
|
||||
<string name="if_they_have_stopped_answering_any_member_can_abandon">If they have stopped answering, any member can abandon the ceremony. No key is made, and the group can start again.</string>
|
||||
<string name="open_the_room">Open the room</string>
|
||||
<string name="admin">Admin</string>
|
||||
<string name="founding_members_are_not_admins">Founding members aren't admins</string>
|
||||
<string name="s_took_part_in_the_key_ceremony_but_are_not_admins">%1$s took part in the key ceremony that made this group, but this room doesn't list them as admins.</string>
|
||||
<string name="make_them_admins">Make them admins</string>
|
||||
<string name="founding_members_made_admins_requested">Asked the group to make them admins</string>
|
||||
<string name="not_every_founding_member_was_invited">Not every founding member was invited</string>
|
||||
<string name="s_took_part_in_the_key_ceremony_but_were_not_invited">%1$s took part in the key ceremony that made this group, but the invitation to this room never went out.</string>
|
||||
<string name="invite_them">Invite them</string>
|
||||
<string name="founding_members_invited">Invited them to the room</string>
|
||||
<string name="founding_members_have_no_key_package">Some of them haven't published a key package yet</string>
|
||||
<string name="admin_room">Admin room</string>
|
||||
<string name="every_member_of_this_group_administers_it_there">Every member of this group is an admin there.</string>
|
||||
</resources>
|
||||
+14
@@ -8,6 +8,7 @@ import com.vitorpamplona.quartz.nip01Core.core.hexToByteArray
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.EventHasher
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
import mobi.giza.compose.managers.FoundingAdmins
|
||||
import mobi.giza.compose.managers.SharedKeyDerivation
|
||||
import mobi.giza.compose.managers.CeremonyFollowThrough
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
|
||||
@@ -114,6 +115,19 @@ class DatabaseChatRepository(
|
||||
emptySet()
|
||||
}
|
||||
|
||||
override suspend fun adminRoomOf(chatRoomId: String): String? = try {
|
||||
// The room's own ceremony, not a subgroup's it hosted: a subgroup's key
|
||||
// makes the subgroup's room, which is not this group's admin room.
|
||||
database.dkgSessionDao().getLatestSessionFor(chatRoomId, parentChatRoomId = null)
|
||||
?.takeIf { it.stage == DkgRitualStage.COMPLETE }
|
||||
?.thresholdPublicKey
|
||||
?.let { SharedKeyDerivation.marmotGroupId(it) }
|
||||
?.takeIf { it != chatRoomId && database.chatRoomDao().findChatRoomById(it) != null }
|
||||
} catch (e: Throwable) {
|
||||
logger.e("Error finding the admin room of $chatRoomId", e)
|
||||
null
|
||||
}
|
||||
|
||||
override suspend fun followThroughCeremonies(keyPair: KeyPair) =
|
||||
CeremonyFollowThrough.observe(database = database, chatRepository = this, keyPair = keyPair)
|
||||
|
||||
|
||||
@@ -237,6 +237,14 @@ interface ChatRepository {
|
||||
/** The founders [localChatRoom]'s founding invite never reached; empty when there are none to reach. */
|
||||
suspend fun uninvitedFounders(localChatRoom: LocalChatRoom): Set<HexKey>
|
||||
|
||||
/**
|
||||
* The admin room [chatRoomId]'s own key ceremony made, if this device holds
|
||||
* it: where the members of a robust group's NIP-17 room are admins. Null for
|
||||
* a room with no finished ceremony of its own, and for one whose admin room
|
||||
* this device does not hold.
|
||||
*/
|
||||
suspend fun adminRoomOf(chatRoomId: String): String?
|
||||
|
||||
/**
|
||||
* Takes every key ceremony [keyPair] coordinated from a key to a working room,
|
||||
* until cancelled: asks the group to sign its key state (a subgroup's parent to
|
||||
@@ -489,6 +497,8 @@ interface ChatRepository {
|
||||
|
||||
override suspend fun uninvitedFounders(localChatRoom: LocalChatRoom): Set<HexKey> = emptySet()
|
||||
|
||||
override suspend fun adminRoomOf(chatRoomId: String): String? = null
|
||||
|
||||
|
||||
override suspend fun sendChatMessage(
|
||||
text: String,
|
||||
|
||||
+179
-5
@@ -14,6 +14,9 @@ import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import mobi.giza.compose.managers.MarmotGroupCreation
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material.icons.filled.AdminPanelSettings
|
||||
import androidx.compose.material.icons.filled.Key
|
||||
import androidx.compose.material.icons.filled.AccountTree
|
||||
import androidx.compose.material.icons.filled.Autorenew
|
||||
@@ -81,6 +84,18 @@ import mobi.giza.compose.ui.view.model.ChatRoomDetailViewModel
|
||||
import mobi.giza.compose.ui.view.state.ChatRoomDetailUIState
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import mobi.giza.compose.ui.theme.spacing
|
||||
import mobi.giza.compose.resources.every_member_of_this_group_administers_it_there
|
||||
import mobi.giza.compose.resources.admin_room
|
||||
import mobi.giza.compose.resources.founding_members_have_no_key_package
|
||||
import mobi.giza.compose.resources.founding_members_invited
|
||||
import mobi.giza.compose.resources.invite_them
|
||||
import mobi.giza.compose.resources.s_took_part_in_the_key_ceremony_but_were_not_invited
|
||||
import mobi.giza.compose.resources.not_every_founding_member_was_invited
|
||||
import mobi.giza.compose.resources.founding_members_made_admins_requested
|
||||
import mobi.giza.compose.resources.make_them_admins
|
||||
import mobi.giza.compose.resources.s_took_part_in_the_key_ceremony_but_are_not_admins
|
||||
import mobi.giza.compose.resources.founding_members_are_not_admins
|
||||
import mobi.giza.compose.resources.admin
|
||||
import mobi.giza.compose.resources.run_by_members
|
||||
import mobi.giza.compose.resources.parent_group
|
||||
import mobi.giza.compose.resources.a_subgroup
|
||||
@@ -185,6 +200,9 @@ fun ChatRoomDetailScreen(
|
||||
val removalRequested = stringResource(Res.string.member_removal_requested)
|
||||
val rotationRequested = stringResource(Res.string.share_rotation_requested)
|
||||
val sharesActionSent = stringResource(Res.string.shares_action_sent)
|
||||
val madeAdminsRequested = stringResource(Res.string.founding_members_made_admins_requested)
|
||||
val foundersInvited = stringResource(Res.string.founding_members_invited)
|
||||
val foundersHaveNoKeyPackage = stringResource(Res.string.founding_members_have_no_key_package)
|
||||
|
||||
// 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
|
||||
@@ -347,6 +365,94 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// The founding members, where the room is not as the
|
||||
// ceremony that made its key left it: founders its
|
||||
// policy does not list as admins, or founders its
|
||||
// founding invite never reached. Under the key and the
|
||||
// parent, because it is about the same thing -- who the
|
||||
// group that made this room is. docs/robust-group-admins.md,
|
||||
// Phase 5.
|
||||
if (chatRoomDetailUIState.missingFoundingAdmins.isNotEmpty()) {
|
||||
item {
|
||||
FoundingMembersCard(
|
||||
title = stringResource(Res.string.founding_members_are_not_admins),
|
||||
body = stringResource(
|
||||
Res.string.s_took_part_in_the_key_ceremony_but_are_not_admins,
|
||||
chatRoomDetailUIState.founderNamesFor(chatRoomDetailUIState.missingFoundingAdmins),
|
||||
),
|
||||
// An admin of a room the app governs: the
|
||||
// repair is a commit only they can make.
|
||||
actionLabel = stringResource(Res.string.make_them_admins)
|
||||
.takeIf { chatRoomDetailUIState.canGovern },
|
||||
isActionPending = chatRoomDetailViewModel.isActionPending.value,
|
||||
onAction = {
|
||||
chatRoomDetailViewModel.addMissingFoundingAdmins(
|
||||
localChatRoom = chatRoomDetailUIState.localChatRoom,
|
||||
missing = chatRoomDetailUIState.missingFoundingAdmins,
|
||||
) { failure -> notify(failure ?: madeAdminsRequested) }
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (chatRoomDetailUIState.uninvitedFounders.isNotEmpty()) {
|
||||
item {
|
||||
FoundingMembersCard(
|
||||
title = stringResource(Res.string.not_every_founding_member_was_invited),
|
||||
body = stringResource(
|
||||
Res.string.s_took_part_in_the_key_ceremony_but_were_not_invited,
|
||||
chatRoomDetailUIState.founderNamesFor(chatRoomDetailUIState.uninvitedFounders),
|
||||
),
|
||||
actionLabel = stringResource(Res.string.invite_them),
|
||||
isActionPending = chatRoomDetailViewModel.isActionPending.value,
|
||||
onAction = {
|
||||
chatRoomDetailViewModel.inviteFounders(chatRoomId) { invite ->
|
||||
notify(
|
||||
when (invite) {
|
||||
is MarmotGroupCreation.FoundingInvite.BlockedOn -> foundersHaveNoKeyPackage
|
||||
is MarmotGroupCreation.FoundingInvite.Failed -> invite.reason
|
||||
else -> foundersInvited
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// A robust group's NIP-17 room has no admins of its own;
|
||||
// its members are admins of the room its key made.
|
||||
chatRoomDetailUIState.adminRoomId?.let { adminRoomId ->
|
||||
item {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
onNavigateToRoute.invoke(
|
||||
ChatRoomDetailRoute(
|
||||
activeUserPublicKey = activeUserPublicKey,
|
||||
chatRoomId = adminRoomId,
|
||||
relayHint = relayHint
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
ListItem(
|
||||
leadingContent = {
|
||||
Icon(Icons.Default.AdminPanelSettings, contentDescription = Decorative)
|
||||
},
|
||||
trailingContent = {
|
||||
Icon(Icons.Default.ChevronRight, contentDescription = Decorative)
|
||||
},
|
||||
headlineContent = {
|
||||
Text(text = stringResource(Res.string.admin_room))
|
||||
},
|
||||
supportingContent = {
|
||||
Text(text = stringResource(Res.string.every_member_of_this_group_administers_it_there))
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
item {
|
||||
chatRoomDetailUIState.localChatRoom.chatRoom.description?.let {
|
||||
Text(
|
||||
@@ -729,10 +835,21 @@ fun ChatRoomDetailScreen(
|
||||
)
|
||||
},
|
||||
supportingContent = {
|
||||
localParticipant.profile?.about?.let {
|
||||
Text(
|
||||
text = it
|
||||
)
|
||||
Column {
|
||||
// From the group's admin policy, through
|
||||
// `AdminFlags` -- docs/robust-group-admins.md.
|
||||
if (localParticipant.participant.adminAt != null) {
|
||||
Text(
|
||||
text = stringResource(Res.string.admin),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
}
|
||||
localParticipant.profile?.about?.let {
|
||||
Text(
|
||||
text = it
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1329,4 +1446,61 @@ private fun ChatRoomMessagingScreenPreview() {
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Something about this room's founding members that is not as the ceremony
|
||||
* left it -- founders it does not list as admins, or founders its invite never
|
||||
* reached -- and, where this device can, the one action that repairs it.
|
||||
*
|
||||
* On the error container: the room works, but not as the group that made it
|
||||
* agreed, and that is worth more than a supporting line. docs/robust-group-admins.md,
|
||||
* Phase 5.
|
||||
*/
|
||||
@Composable
|
||||
private fun FoundingMembersCard(
|
||||
title: String,
|
||||
body: String,
|
||||
actionLabel: String?,
|
||||
isActionPending: Boolean,
|
||||
onAction: () -> Unit,
|
||||
) {
|
||||
Card(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.errorContainer,
|
||||
contentColor = MaterialTheme.colorScheme.onErrorContainer,
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.padding(MaterialTheme.spacing.containerPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.relatedGap),
|
||||
) {
|
||||
Icon(Icons.Default.AdminPanelSettings, contentDescription = Decorative)
|
||||
Text(text = title, style = MaterialTheme.typography.titleSmall)
|
||||
}
|
||||
|
||||
Text(text = body, style = MaterialTheme.typography.bodyMedium)
|
||||
|
||||
actionLabel?.let { label ->
|
||||
TextButton(
|
||||
onClick = onAction,
|
||||
enabled = !isActionPending,
|
||||
colors = ButtonDefaults.textButtonColors(
|
||||
contentColor = MaterialTheme.colorScheme.onErrorContainer
|
||||
),
|
||||
) {
|
||||
Text(label)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The founders [publicKeys] names, as the screen calls them, in a stable order. */
|
||||
private fun ChatRoomDetailUIState.Loaded.founderNamesFor(publicKeys: Set<HexKey>): String =
|
||||
publicKeys.map { founderNames[it] ?: it }.sorted().joinToString(", ")
|
||||
+46
-4
@@ -19,6 +19,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.launch
|
||||
import mobi.giza.compose.managers.FoundingAdmins
|
||||
import mobi.giza.compose.managers.MarmotGroupCreation
|
||||
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
|
||||
import mobi.giza.compose.database.model.types.MarmotReindexReport
|
||||
import mobi.giza.compose.managers.WalletRefusal
|
||||
@@ -98,6 +99,14 @@ class ChatRoomDetailViewModel(
|
||||
?.let { Event.fromJsonOrNull(it) }
|
||||
?.let(WalletRefusal::isGuarded) == true
|
||||
|
||||
// The founding members, against what the ceremony that made the
|
||||
// room's key said: who the policy leaves out, and who the founding
|
||||
// invite never reached. docs/robust-group-admins.md, Phases 3 and 4.
|
||||
val missingFoundingAdmins = (chatRepository.foundingAdmins(chatRoomId) as? FoundingAdmins.Check.Missing)
|
||||
?.publicKeys
|
||||
.orEmpty()
|
||||
val uninvitedFounders = chatRepository.uninvitedFounders(localChatRoom)
|
||||
|
||||
ChatRoomDetailUIState.Loaded(
|
||||
localChatRoom = localChatRoom,
|
||||
groupKeyState = groupKeyState,
|
||||
@@ -109,9 +118,13 @@ class ChatRoomDetailViewModel(
|
||||
canGovern = canGovern,
|
||||
isDisbanded = isDisbanded,
|
||||
shares = chatRepository.sharesSummary(localChatRoom),
|
||||
missingFoundingAdmins = (chatRepository.foundingAdmins(chatRoomId) as? FoundingAdmins.Check.Missing)
|
||||
?.publicKeys
|
||||
.orEmpty(),
|
||||
missingFoundingAdmins = missingFoundingAdmins,
|
||||
uninvitedFounders = uninvitedFounders,
|
||||
founderNames = (missingFoundingAdmins + uninvitedFounders).associateWith { publicKey ->
|
||||
nostrRepository.getProfileWithPublicKey(publicKey)?.humanReadableNameOrPubkey()
|
||||
?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH)
|
||||
},
|
||||
adminRoomId = if (localChatRoom.chatRoom.mlsGroupState == null) chatRepository.adminRoomOf(chatRoomId) else null,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -146,10 +159,36 @@ class ChatRoomDetailViewModel(
|
||||
* warning stays until then. docs/robust-group-admins.md, Phase 3.
|
||||
*/
|
||||
fun addMissingFoundingAdmins(localChatRoom: LocalChatRoom, missing: Set<HexKey>, onDone: (String?) -> Unit = {}) {
|
||||
if (isActionPending.value) return
|
||||
isActionPending.value = true
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val failure = runCatching { chatRepository.addAdmins(localChatRoom, missing) }.exceptionOrNull()
|
||||
initiateChatRoomDetail()
|
||||
viewModelScope.launch(Dispatchers.Main) { onDone(failure?.message) }
|
||||
viewModelScope.launch(Dispatchers.Main) {
|
||||
isActionPending.value = false
|
||||
onDone(failure?.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes the room's founding invite, and reloads the screen. Reports null
|
||||
* when it went out, or why not -- naming the founders still without a key
|
||||
* package, since only they can publish one. docs/robust-group-admins.md,
|
||||
* Phase 4.
|
||||
*/
|
||||
fun inviteFounders(chatRoomId: String, onDone: (MarmotGroupCreation.FoundingInvite) -> Unit = {}) {
|
||||
// Waits on relays for key packages, so a second tap would ask twice.
|
||||
if (isActionPending.value) return
|
||||
isActionPending.value = true
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val invite = runCatching { chatRepository.finishFoundingInvite(chatRoomId) }
|
||||
.getOrElse { MarmotGroupCreation.FoundingInvite.Failed(it.message ?: "Couldn't invite them. Please try again.") }
|
||||
initiateChatRoomDetail()
|
||||
viewModelScope.launch(Dispatchers.Main) {
|
||||
isActionPending.value = false
|
||||
onDone(invite)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,6 +327,9 @@ class ChatRoomDetailViewModel(
|
||||
companion object {
|
||||
private const val TAG = "ChatRoomDetailViewModel"
|
||||
|
||||
/** Enough of a key to tell two founders apart when no profile is stored. */
|
||||
private const val SHORTENED_PUBLIC_KEY_LENGTH = 12
|
||||
|
||||
fun factory(
|
||||
activeUserPublicKey: HexKey,
|
||||
chatRoomId: String,
|
||||
|
||||
+20
@@ -91,6 +91,26 @@ sealed interface ChatRoomDetailUIState {
|
||||
* `FoundingAdmins.check`; docs/robust-group-admins.md, Phase 3.
|
||||
*/
|
||||
val missingFoundingAdmins: Set<HexKey> = emptySet(),
|
||||
/**
|
||||
* Founding members this room's founding invite never reached -- only ever
|
||||
* non-empty on the device that made the room, while it is still at epoch 0.
|
||||
* See `MarmotGroupCreation.uninvitedFounders`; docs/robust-group-admins.md,
|
||||
* Phase 4.
|
||||
*/
|
||||
val uninvitedFounders: Set<HexKey> = emptySet(),
|
||||
/**
|
||||
* What to call the founders the two sets above name. They need not be in
|
||||
* this room -- an uninvited one is not, by definition -- so the room's own
|
||||
* rows cannot be asked.
|
||||
*/
|
||||
val founderNames: Map<HexKey, String> = emptyMap(),
|
||||
/**
|
||||
* The admin room this group's ceremony made, when this is the group's
|
||||
* NIP-17 room and this device holds it. A NIP-17 room has no admins of its
|
||||
* own; this is where its members are admins. docs/robust-group-admins.md,
|
||||
* Phase 5.
|
||||
*/
|
||||
val adminRoomId: String? = null,
|
||||
): ChatRoomDetailUIState
|
||||
|
||||
data class Error(
|
||||
|
||||
Reference in new issue
Block a user