feat: a room with no key behind it takes no new members (remove-convenient-groups, Phase 2b)
A one-to-one chat, or a group its creator runs alone, grown by one more person would be a group run by one person. The invite screen refuses such a room and the detail screen no longer offers the invite there. The plan gains D7, since D1 had assumed no such invite path existed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb2c8aa090
commit
c2010abe44
7 files changed
+237
-18
No files matched your search
+1
-1
@@ -928,7 +928,7 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
if (chatRoomDetailUIState.canInvite) item {
|
||||
TextButton(
|
||||
onClick = {
|
||||
// Navigate to the invite user screen...
|
||||
|
||||
+34
@@ -32,6 +32,18 @@ import mobi.giza.compose.repository.ChatRepository
|
||||
import mobi.giza.compose.repository.NostrRepository
|
||||
import mobi.giza.compose.ui.view.state.AddMemberToChatRoomConfirmationUIState
|
||||
|
||||
/**
|
||||
* Inviting one person into a room that already exists -- the app's one way of
|
||||
* adding a member after a room's founding.
|
||||
*
|
||||
* Only a room with a threshold key behind it takes one. A room without is a
|
||||
* one-to-one chat or a group its creator runs alone, and a third person invited
|
||||
* into either is a group run by one person, which Giza no longer makes. The
|
||||
* people in it can make a group together instead, robust from the start. The
|
||||
* rule lives here, at the one entrance `MarmotRoomEntryPointsJvmTest` pins, and
|
||||
* not in the DAO, whose invite the tests drive on keyless rooms to exercise MLS
|
||||
* itself. See docs/remove-convenient-groups.md, D7.
|
||||
*/
|
||||
class AddMemberToChatRoomConfirmationViewModel(
|
||||
val chatRoomId: String,
|
||||
val activeUserPublicKey: HexKey,
|
||||
@@ -61,6 +73,13 @@ class AddMemberToChatRoomConfirmationViewModel(
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Said before anything is looked up for the invitee: there is nothing to
|
||||
// wait on the relays for if the room will not take them.
|
||||
if (!takesNewMembers(chatRoomId)) {
|
||||
addMemberToChatRoomConfirmationUIState = AddMemberToChatRoomConfirmationUIState.Error(KEYLESS_ROOM)
|
||||
return@launch
|
||||
}
|
||||
|
||||
val profile = nostrRepository.getProfileWithPublicKey(profilePublicKey)
|
||||
if (profile == null) {
|
||||
addMemberToChatRoomConfirmationUIState =
|
||||
@@ -135,6 +154,13 @@ class AddMemberToChatRoomConfirmationViewModel(
|
||||
onInviteSent: () -> Unit
|
||||
) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Again at the act, because a screen not drawing a button is not a guard.
|
||||
if (!takesNewMembers(localChatRoom.chatRoom.id)) {
|
||||
isActionPending.value = false
|
||||
addMemberToChatRoomConfirmationUIState = AddMemberToChatRoomConfirmationUIState.Error(KEYLESS_ROOM)
|
||||
return@launch
|
||||
}
|
||||
|
||||
// Invite member. `inviteMember` can throw (no MLS state for the room, credential
|
||||
// identity mismatch); reporting success regardless popped the user back to the chat
|
||||
// as though an invite had been sent when nothing was ever queued.
|
||||
@@ -167,9 +193,17 @@ class AddMemberToChatRoomConfirmationViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether [chatRoomId] has a threshold key behind it, which is what lets it grow. */
|
||||
private suspend fun takesNewMembers(chatRoomId: String): Boolean =
|
||||
chatRepository.groupKeyState(chatRoomId) != null
|
||||
|
||||
companion object {
|
||||
private const val TAG = "AddMemberToChatRoomConfirmationViewModel"
|
||||
|
||||
/** Says what to do instead, because the person asking can do it. */
|
||||
const val KEYLESS_ROOM =
|
||||
"Only a group can take new members. Make a group with everyone instead — it's run by all of you together."
|
||||
|
||||
/** How long to wait on the relays before telling the user we came up empty. */
|
||||
private val RELAY_LOOKUP_TIMEOUT = 20.seconds
|
||||
|
||||
|
||||
+6
@@ -120,6 +120,12 @@ class ChatRoomDetailViewModel(
|
||||
canAddSubgroup = canSign && !subgroupsNeedAWallet,
|
||||
subgroupsNeedAWallet = canSign && subgroupsNeedAWallet,
|
||||
canGovern = canGovern,
|
||||
// The same rule `AddMemberToChatRoomConfirmationViewModel` enforces;
|
||||
// this only keeps the button from offering what it would refuse.
|
||||
canInvite = groupKeyState != null &&
|
||||
localChatRoom.chatRoom.mlsGroupState != null &&
|
||||
!isDisbanded &&
|
||||
localChatRoom.chatRoom.leftGroupAt == null,
|
||||
isDisbanded = isDisbanded,
|
||||
shares = chatRepository.sharesSummary(localChatRoom),
|
||||
missingFoundingAdmins = missingFoundingAdmins,
|
||||
|
||||
+7
@@ -73,6 +73,13 @@ sealed interface ChatRoomDetailUIState {
|
||||
* neither either. See docs/marmot-v2.md, Phase 7.
|
||||
*/
|
||||
val canGovern: Boolean = false,
|
||||
/**
|
||||
* Whether the room takes new members: a Marmot room with a threshold key
|
||||
* behind it, still open. A one-to-one chat and a group its creator runs
|
||||
* alone take none -- inviting a third person is how one would become a
|
||||
* group run by one person. docs/remove-convenient-groups.md, D7.
|
||||
*/
|
||||
val canInvite: Boolean = false,
|
||||
/**
|
||||
* The group's lifecycle says it is over. Absorbing: nothing is sent into it
|
||||
* and nobody rejoins, so every write entrance is hidden and the room says so.
|
||||
|
||||
Reference in new issue
Block a user