feat: a group run by one person says so, and is still joined (remove-convenient-groups, Phase 5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
03704db3fb
commit
41409434a7
5 files changed
+109
No files matched your search
@@ -521,4 +521,5 @@
|
||||
<string name="pick_more">Pick %1$s more</string>
|
||||
<string name="not_enough_people_for_a_group_yet">Not enough people for a group yet.</string>
|
||||
<string name="a_group_needs_at_least_two_other_people">A group needs at least two other people, and everyone in it is added when it's made. To talk with one person, start a chat with them instead.</string>
|
||||
<string name="run_by_alone">Run by %1$s alone. Changes to this group don't need anyone else's approval.</string>
|
||||
</resources>
|
||||
+14
@@ -86,6 +86,7 @@ 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.run_by_alone
|
||||
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
|
||||
@@ -928,6 +929,19 @@ fun ChatRoomDetailScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// A group run by one person, which Giza no longer makes: said
|
||||
// above its members, because nothing else here explains why it
|
||||
// behaves unlike every other group the member is in.
|
||||
chatRoomDetailUIState.soleAdminName?.let { soleAdminName ->
|
||||
item {
|
||||
Text(
|
||||
text = stringResource(Res.string.run_by_alone, soleAdminName),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (chatRoomDetailUIState.canInvite) item {
|
||||
TextButton(
|
||||
onClick = {
|
||||
|
||||
+25
@@ -10,6 +10,7 @@ import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.marmot.groups.currentAdminIdentities
|
||||
import com.vitorpamplona.marmot.groups.currentGroupState
|
||||
import com.vitorpamplona.marmot.groups.isLocalAdmin
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
@@ -135,12 +136,36 @@ class ChatRoomDetailViewModel(
|
||||
?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH)
|
||||
},
|
||||
adminRoomId = if (localChatRoom.chatRoom.mlsGroupState == null) chatRepository.adminRoomOf(chatRoomId) else null,
|
||||
soleAdminName = soleAdminOf(localChatRoom, hasKey = groupKeyState != null)?.let { publicKey ->
|
||||
nostrRepository.getProfileWithPublicKey(publicKey)?.humanReadableNameOrPubkey()
|
||||
?: publicKey.take(SHORTENED_PUBLIC_KEY_LENGTH)
|
||||
},
|
||||
)
|
||||
}
|
||||
localChatRoom?.let { observeShares(it.chatRoom.id) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The one admin of a group run by one person, or null. Every group Giza makes
|
||||
* is robust now, so this only finds groups made before that or by a Bennu peer;
|
||||
* nothing else on the screen says why such a group behaves unlike the others.
|
||||
* docs/remove-convenient-groups.md, Phase 5.
|
||||
*/
|
||||
private fun soleAdminOf(localChatRoom: LocalChatRoom, hasKey: Boolean): HexKey? {
|
||||
if (hasKey) return null
|
||||
|
||||
val members = localChatRoom.localParticipants.count { it.participant.deletedAt == null }
|
||||
if (members <= 2) return null
|
||||
|
||||
val admins = runCatching { localChatRoom.chatRoom.toMlsGroup()?.currentAdminIdentities() }
|
||||
.onFailure { logger.w("Couldn't read the admins of ${localChatRoom.chatRoom.id}", it) }
|
||||
.getOrNull()
|
||||
?: return null
|
||||
|
||||
return admins.singleOrNull()
|
||||
}
|
||||
|
||||
private var sharesObserver: Job? = null
|
||||
|
||||
/**
|
||||
|
||||
+8
@@ -118,6 +118,14 @@ sealed interface ChatRoomDetailUIState {
|
||||
* Phase 5.
|
||||
*/
|
||||
val adminRoomId: String? = null,
|
||||
/**
|
||||
* Who runs this group alone, when it is one: a Marmot room with no key
|
||||
* behind it, more than two members and one admin -- a group made before
|
||||
* every group was robust, or one a Bennu peer made. Null for every other
|
||||
* room, a one-to-one chat included, since one person running a chat for
|
||||
* two is not news. docs/remove-convenient-groups.md, Phase 5.
|
||||
*/
|
||||
val soleAdminName: String? = null,
|
||||
): ChatRoomDetailUIState
|
||||
|
||||
data class Error(
|
||||
|
||||
@@ -394,4 +394,65 @@ class RobustGroupAdminsJvmTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- A group run by one person ------------------------------------------------
|
||||
|
||||
/**
|
||||
* Giza stops making groups its creator runs alone, and does not stop joining
|
||||
* them. docs/remove-convenient-groups.md, D4: a Bennu member still makes them,
|
||||
* and a Giza member invited to one takes part like anybody else.
|
||||
*
|
||||
* Made with one admin and a random id -- no key behind it -- which is all a
|
||||
* "convenient" group ever was on the wire.
|
||||
*/
|
||||
@Test
|
||||
fun `a group its creator runs alone, made elsewhere, is still joined`(): Unit = runBlocking {
|
||||
listOf(MarmotProfile.LEGACY, MarmotProfile.CURRENT).forEach { profile ->
|
||||
val phones = List(3) { Phone(profile) }
|
||||
try {
|
||||
phones.forEach { it.ready() }
|
||||
phones.forEach { phone -> phones.forEach { MarmotStandIn.seedProfile(phone.db, it.publicKey) } }
|
||||
val creator = phones.first()
|
||||
phones.drop(1).forEach { creator.db.marmotKeyPackageDao().upsert(it.keyPackage) }
|
||||
|
||||
val soloRoomId = KeyPair().pubKey.toHexKey()
|
||||
val outcome = MarmotGroupCreation.create(
|
||||
database = creator.db,
|
||||
chatRepository = creator.chatRepository,
|
||||
groupId = soloRoomId,
|
||||
name = "Checkers",
|
||||
purpose = "Run by its creator.",
|
||||
adminPublicKeys = setOf(creator.publicKey),
|
||||
userPublicKey = creator.publicKey,
|
||||
keyPair = creator.keyPair,
|
||||
keyPackageLookupTimeout = 2_000L,
|
||||
profile = profile,
|
||||
)
|
||||
assertIs<MarmotGroupCreation.Outcome.Created>(outcome, "($profile)")
|
||||
|
||||
// `create` invites the admins it is given, and here that is nobody but
|
||||
// the creator. The members come the way a creator-run group's always
|
||||
// did: one founding commit for all of them.
|
||||
val room = assertNotNull(creator.db.chatRoomDao().findChatRoomById(soloRoomId), "($profile)")
|
||||
val notAdded = creator.chatRepository.addMembers(room, phones.drop(1).map { it.publicKey to it.keyPackage })
|
||||
assertTrue(notAdded.isEmpty(), "the creator could not invite $notAdded ($profile)")
|
||||
|
||||
phones.drop(1).forEach { joiner ->
|
||||
welcome(from = creator, to = joiner, roomId = soloRoomId)
|
||||
|
||||
val room = assertNotNull(joiner.db.chatRoomDao().findChatRoomById(soloRoomId), "$joiner has no room ($profile)")
|
||||
val group = assertNotNull(room.chatRoom.toMlsGroup(), "$joiner holds no group ($profile)")
|
||||
assertEquals(setOf(creator.publicKey), group.currentAdminIdentities(), "$joiner's admin policy ($profile)")
|
||||
assertFalse(group.isLocalAdmin(), "$joiner is not an admin of a room its creator runs ($profile)")
|
||||
assertEquals(
|
||||
FoundingAdmins.Check.NotKeyBacked,
|
||||
FoundingAdmins.check(joiner.db, soloRoomId),
|
||||
"no key behind it, so no founders to check ($profile)",
|
||||
)
|
||||
}
|
||||
} finally {
|
||||
phones.forEach { it.close() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user