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(
|
||||
|
||||
Reference in new issue
Block a user