diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 5cfe51f9..7c733a8f 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -436,6 +436,8 @@
Ask the parent group to certify this subgroup
Create the subgroup
The key ceremony needs you
+ You already share %1$s with these people. This makes a separate group, with a key of its own.
+ The key ceremony for %1$s needs you
The subgroup's key ceremony needs you
%1$s key ceremonies need you
Join it by publishing your device's key
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ChillDkgRitualManager.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ChillDkgRitualManager.kt
index fc823c19..26646b15 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ChillDkgRitualManager.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ChillDkgRitualManager.kt
@@ -935,8 +935,8 @@ object ChillDkgRitualManager {
database = database,
session = session,
messageType = ChatMessage.TYPE_DKG_COMPLETE,
- content = "The group has a shared key. It takes ${session.threshold} of " +
- "${session.participantCount} members to sign with it.",
+ content = "${session.subject ?: "The group"} has a shared key. It takes " +
+ "${session.threshold} of ${session.participantCount} members to sign with it.",
actor = session.coordinatorPublicKey
)
@@ -1156,7 +1156,7 @@ object ChillDkgRitualManager {
// screen this line taps through to. "a participant is faulty
// (participant 2)" is worth having, but not in the middle of a
// sentence about who walked away.
- content = "abandoned the shared key ceremony. No key was created, " +
+ content = "abandoned ${ceremonyPhrase(current)}. No key was created, " +
"and it is safe to run it again.",
actor = culprit
)
@@ -1180,6 +1180,15 @@ object ChillDkgRitualManager {
"this group. It will take ${session.threshold} of " +
"${session.participantCount} of its admins to sign with the subgroup's key, " +
"and it finishes once all of them have taken part."
+ } else if (session.subject != null) {
+ // Named, because the same people may make more than one group in one
+ // room (docs/nip17-multiple-ceremonies.md), and a line read days later
+ // cannot ask which ceremony it was about. Every named one says so, not
+ // only a second: the room may have one at the time and two by the time
+ // somebody reads this.
+ "started a key ceremony for ${session.subject}. It will take ${session.threshold} of " +
+ "${session.participantCount} members to sign with its key, and it finishes " +
+ "once everyone has taken part."
} else {
"started a shared key ceremony. It will take ${session.threshold} of " +
"${session.participantCount} members to sign with the key, and it finishes " +
@@ -1330,7 +1339,7 @@ object ChillDkgRitualManager {
val (messageType, content) = when (step) {
DkgApprovalStep.HOST_KEY -> ChatMessage.TYPE_DKG_APPROVAL_NEEDED_HOST_KEY to
- "Your approval is needed to join the shared key ceremony. Nothing has been " +
+ "Your approval is needed to join ${ceremonyPhrase(session)}. Nothing has been " +
"published from this device yet."
// Never reached: rounds 1 and 2 are no longer asked for. Kept because the
@@ -1381,7 +1390,7 @@ object ChillDkgRitualManager {
) {
val (messageType, content) = when (kind) {
DkgRitualEvents.HOST_KEY -> ChatMessage.TYPE_DKG_HOST_KEY to
- "joined the shared key ceremony, publishing the key their device is " +
+ "joined ${ceremonyPhrase(session)}, publishing the key their device is " +
"identified by for the rest of it."
DkgRitualEvents.ROUND_1 -> ChatMessage.TYPE_DKG_ROUND_1 to
@@ -1413,6 +1422,16 @@ object ChillDkgRitualManager {
)
}
+ /**
+ * How a transcript line names its ceremony: by the group it makes when it has a
+ * name, which every ceremony Giza opens now does. The same people may run more
+ * than one in a room (docs/nip17-multiple-ceremonies.md), and "the shared key
+ * ceremony" said beside a second one names neither. A ceremony from before names
+ * were carried keeps the words it always had.
+ */
+ private fun ceremonyPhrase(session: DkgSession): String =
+ session.subject?.let { "the key ceremony for $it" } ?: "the shared key ceremony"
+
/** The stored session, for reading a column back before overwriting it. */
private suspend fun current(database: GizaDatabase, session: DkgSession): DkgSession =
database.dkgSessionDao().getSessionById(session.id) ?: session
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgJoinApprovalScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgJoinApprovalScreen.kt
index e53a9760..ea7840b2 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgJoinApprovalScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgJoinApprovalScreen.kt
@@ -4,6 +4,7 @@ import org.jetbrains.compose.resources.stringResource
import mobi.giza.compose.resources.this_subgroup_s_wallet_is_to_be_guarded
import mobi.giza.compose.database.model.isGuardedSubgroup
import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.you_already_share_with_these_people_this_makes_a_separate_group
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
@@ -72,7 +73,12 @@ fun DkgJoinApprovalScreen(
canApprove = { state -> !state.session.isGuardedSubgroup },
) { state ->
val session = state.session
- val group = state.localChatRoom.chatRoom.subject ?: stringResource(Res.string.this_group)
+ // The group the ceremony makes, not the room it is held in: the same people
+ // share one NIP-17 room however many groups they make, and the room keeps
+ // the first one's name (docs/nip17-multiple-ceremonies.md).
+ val group = session.subject
+ ?: state.localChatRoom.chatRoom.subject
+ ?: stringResource(Res.string.this_group)
Text(
text = stringResource(
@@ -84,6 +90,18 @@ fun DkgJoinApprovalScreen(
style = MaterialTheme.typography.bodyLarge
)
+ // Joining is the one decision a member makes, so they should know it is not
+ // the group they already have with these people.
+ if (state.otherGroups.isNotEmpty()) {
+ Text(
+ text = stringResource(
+ Res.string.you_already_share_with_these_people_this_makes_a_separate_group,
+ state.otherGroups.joinToString(", ")
+ ),
+ style = MaterialTheme.typography.bodyLarge
+ )
+ }
+
// A Bennu subgroup whose wallet is to be guarded: its certificate has to
// be guarded, which Giza does not sign, so it does not join (W5,
// docs/giza-wallet-removal.md). Said rather than hidden.
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
index 3bdbb693..e49a292e 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/widgets/chat/ChatTranscript.kt
@@ -83,6 +83,7 @@ import mobi.giza.compose.ui.view.state.ChatMessageListUIState
import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.composable.widgets.Decorative
import mobi.giza.compose.resources.Res
+import mobi.giza.compose.resources.the_key_ceremony_for_needs_you
import org.jetbrains.compose.resources.stringResource
import mobi.giza.compose.resources.currently_no_messages_have_been_shared
import mobi.giza.compose.resources.loading
@@ -639,14 +640,17 @@ fun ChatTranscript(
* room exists.
*/
@Composable
-private fun CeremoniesAwaitingYouNotice(
+internal fun CeremoniesAwaitingYouNotice(
ceremonies: List,
onClick: (ChatMessageListViewModel.AwaitingCeremony) -> Unit,
) {
val single = ceremonies.singleOrNull()
+ // Each named by the group it makes: the same people may run more than one
+ // ceremony in a room (docs/nip17-multiple-ceremonies.md).
val headline = when {
single == null -> stringResource(Res.string.ceremonies_need_you, ceremonies.size)
+ single.subject != null -> stringResource(Res.string.the_key_ceremony_for_needs_you, single.subject)
single.isSubgroup -> stringResource(Res.string.the_subgroups_key_ceremony_needs_you)
else -> stringResource(Res.string.the_key_ceremony_needs_you)
}
@@ -658,7 +662,10 @@ private fun CeremoniesAwaitingYouNotice(
//
// Joining is the only gate a ceremony has (docs/automatic-key-ceremony.md).
// The two rounds after it are never asked for, so they say nothing here.
- val detail = single?.let {
+ val detail = if (single == null) {
+ // Several: which ones, so a member knows what the count is of.
+ ceremonies.mapNotNull { it.subject }.takeIf { it.isNotEmpty() }?.joinToString(", ")
+ } else single.let {
when (val ask = it.ask) {
is ChatMessageListViewModel.Ask.SharedKeyStep -> when (ask.step) {
DkgApprovalStep.HOST_KEY -> stringResource(Res.string.join_the_ceremony_by_publishing_your_key)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatMessageListViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatMessageListViewModel.kt
index c6ff89a5..657573b2 100755
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatMessageListViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ChatMessageListViewModel.kt
@@ -117,6 +117,14 @@ class ChatMessageListViewModel(
/** Whether this ceremony is making a subgroup, for what the notice says. */
val isSubgroup: Boolean,
+
+ /**
+ * The group it makes, or null for a ceremony from before names were carried.
+ * The same people may run more than one in a room, and "the key ceremony
+ * needs you" beside a second one names neither
+ * (docs/nip17-multiple-ceremonies.md).
+ */
+ val subject: String? = null,
)
/** What a ceremony wants of this member. */
@@ -283,6 +291,7 @@ class ChatMessageListViewModel(
sessionId = session.id,
ask = ask,
isSubgroup = session.parentChatRoomId != null,
+ subject = session.subject,
)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModel.kt
index 0be40995..62e9380a 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModel.kt
@@ -189,6 +189,17 @@ class DkgRitualViewModel(
?: return@mapLatest DkgRitualUIState.Error("Couldn't find this key ceremony")
val ceremony = snapshot.ceremony
+ // The other groups held in this room, for a group's own ceremony:
+ // the same people may have made more than one here. A subgroup's
+ // runs in its parent's room, whose own groups are not its business.
+ val otherGroups = if (session.parentChatRoomId == null) {
+ dkgRepository.observeOwnSessionsForChatRoom(chatRoomId).first()
+ .filter { it.id != session.id }
+ .mapNotNull { it.subject ?: localChatRoom.chatRoom.subject }
+ } else {
+ emptyList()
+ }
+
DkgRitualUIState.Loaded(
localChatRoom = localChatRoom,
session = session,
@@ -208,6 +219,7 @@ class DkgRitualViewModel(
isRoomCreated = session.thresholdPublicKey
?.let { runCatching { SharedKeyDerivation.marmotGroupId(it) }.getOrNull() }
?.let { it in snapshot.roomIds } == true,
+ otherGroups = otherGroups,
)
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/DkgRitualUIState.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/DkgRitualUIState.kt
index a7f6e916..e555a20b 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/DkgRitualUIState.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/state/DkgRitualUIState.kt
@@ -94,6 +94,14 @@ sealed interface DkgRitualUIState {
* last rung is usually a way into the room rather than a button to make it.
*/
val isRoomCreated: Boolean = false,
+ /**
+ * The other groups the same people have made in this room, by name, when
+ * this ceremony is a group's own. The room's id is derived from its members,
+ * so a second group they make is held where the first was; joining one is
+ * not joining the other, and the join screen says so
+ * (docs/nip17-multiple-ceremonies.md).
+ */
+ val otherGroups: List = emptyList(),
/**
* The session asking the parent to certify, while it is running.
*
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustRoomKeyCeremonyTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustRoomKeyCeremonyTest.kt
index 501a2295..dda96d74 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustRoomKeyCeremonyTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/managers/RobustRoomKeyCeremonyTest.kt
@@ -290,6 +290,46 @@ class RobustRoomKeyCeremonyTest {
assertNotEquals(first.id, namesake.id)
}
+ /**
+ * A line is written once and read later, perhaps after the same people have
+ * started a second group in the room, so it names the group it is about.
+ * docs/nip17-multiple-ceremonies.md, Phase 4.
+ */
+ @Test
+ fun `a ceremony's lines name the group it makes`() = runBlocking {
+ val room = robustRoom()
+ val first = openCeremony(room)
+ db.dkgSessionDao().upsert(first.copy(stage = DkgRitualStage.COMPLETE))
+ val agora = openCeremony(room, subject = "Agora")
+
+ val started = chatMessages(room).filter { it.messageType == ChatMessage.TYPE_DKG_STARTED }
+ assertTrue(
+ started.single { it.dkgSessionId == first.id }.content.startsWith("started a key ceremony for Robust Group."),
+ "the room's first group is named for the room",
+ )
+ assertTrue(
+ started.single { it.dkgSessionId == agora.id }.content.startsWith("started a key ceremony for Agora."),
+ )
+
+ ChillDkgRitualManager.abandon(db, room, agora.id)
+ val abandoned = chatMessages(room).single { it.messageType == ChatMessage.TYPE_DKG_FAILED }
+ assertTrue(abandoned.content.startsWith("abandoned the key ceremony for Agora."), abandoned.content)
+ }
+
+ /** A room with no name opens a ceremony with none, and its lines read as they did. */
+ @Test
+ fun `an unnamed ceremony keeps the words it always had`() = runBlocking {
+ listOf(user, alice, bob).forEach { seedProfile(it) }
+ val room = assertNotNull(
+ db.nostrNip17Dao().createNip17ChatRoom(userPublicKey = user, participantPublicKeys = listOf(alice, bob))
+ )
+ val session = openCeremony(room)
+
+ assertNull(session.subject)
+ val started = chatMessages(room).single { it.messageType == ChatMessage.TYPE_DKG_STARTED }
+ assertTrue(started.content.startsWith("started a shared key ceremony."), started.content)
+ }
+
/**
* A collapsed ceremony leaves the group with no key and a room they can still
* talk in, which is exactly the group that should be able to try again. Failed
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/CeremoniesAwaitingYouNoticeJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/CeremoniesAwaitingYouNoticeJvmTest.kt
new file mode 100644
index 00000000..2a2968a4
--- /dev/null
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/CeremoniesAwaitingYouNoticeJvmTest.kt
@@ -0,0 +1,55 @@
+package mobi.giza.compose.ui.composable
+
+import androidx.compose.ui.test.ExperimentalTestApi
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.runDesktopComposeUiTest
+import mobi.giza.compose.database.model.types.DkgApprovalStep
+import mobi.giza.compose.ui.composable.widgets.chat.CeremoniesAwaitingYouNotice
+import mobi.giza.compose.ui.theme.GizaTheme
+import mobi.giza.compose.ui.view.model.ChatMessageListViewModel.AwaitingCeremony
+import mobi.giza.compose.ui.view.model.ChatMessageListViewModel.Ask
+import kotlin.test.Test
+
+/**
+ * The notice above a room's transcript that a ceremony wants this member. The same
+ * people may run more than one ceremony in a room, so it names the group each one
+ * makes. docs/nip17-multiple-ceremonies.md, Phase 4.
+ */
+@OptIn(ExperimentalTestApi::class)
+class CeremoniesAwaitingYouNoticeJvmTest {
+
+ private fun waiting(id: String, subject: String?, isSubgroup: Boolean = false) = AwaitingCeremony(
+ sessionId = id,
+ ask = Ask.SharedKeyStep(DkgApprovalStep.HOST_KEY),
+ isSubgroup = isSubgroup,
+ subject = subject,
+ )
+
+ private fun render(ceremonies: List, assertions: androidx.compose.ui.test.ComposeUiTest.() -> Unit) =
+ runDesktopComposeUiTest(width = 400, height = 400) {
+ setContent { GizaTheme { CeremoniesAwaitingYouNotice(ceremonies = ceremonies, onClick = {}) } }
+ assertions()
+ }
+
+ @Test
+ fun `one ceremony is named by the group it makes`() = render(listOf(waiting("a", "Agora"))) {
+ onNodeWithText("The key ceremony for Agora needs you").assertExists()
+ }
+
+ @Test
+ fun `several are counted, and named under the count`() =
+ render(listOf(waiting("a", "Agora"), waiting("b", "Ekklesia"))) {
+ onNodeWithText("2 key ceremonies need you").assertExists()
+ onNodeWithText("Agora, Ekklesia").assertExists()
+ }
+
+ @Test
+ fun `an unnamed ceremony reads as it always did`() {
+ render(listOf(waiting("a", null))) {
+ onNodeWithText("The key ceremony needs you").assertExists()
+ }
+ render(listOf(waiting("a", null, isSubgroup = true))) {
+ onNodeWithText("The subgroup's key ceremony needs you").assertExists()
+ }
+ }
+}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt
index 702f2c6d..b5f37860 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/view/model/DkgRitualViewModelJvmTest.kt
@@ -17,6 +17,7 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -123,6 +124,9 @@ class DkgRitualViewModelJvmTest {
private val messages = MutableStateFlow>(emptyList())
private val signingSessions = MutableStateFlow>(emptyList())
+ /** The room's own groups, as the repository reports them. */
+ private var roomGroups: List = emptyList()
+
/** How many times the screen started watching its ceremony. */
private var sessionSubscriptions = 0
@@ -136,6 +140,9 @@ class DkgRitualViewModelJvmTest {
override fun observeMessages(sessionId: String): Flow> = messages
+ override fun observeOwnSessionsForChatRoom(chatRoomId: String): Flow> =
+ flowOf(roomGroups)
+
override fun observeSigningSessions(chatRoomId: String): Flow> =
signingSessions
@@ -199,6 +206,38 @@ class DkgRitualViewModelJvmTest {
error("unreachable")
}
+ /**
+ * Joining is the one decision a member makes, so the join screen says when the
+ * same people already have another group in this room: this is not that one.
+ * docs/nip17-multiple-ceremonies.md, Phase 4.
+ */
+ @Test
+ fun `the other groups held in the room are named, and the ceremony itself is not`(): Unit = runBlocking {
+ roomGroups = listOf(
+ session().copy(subject = "Agora"),
+ session().copy(id = "e0".repeat(32), subject = "Ekklesia"),
+ session().copy(id = "e1".repeat(32), subject = null),
+ )
+ val viewModel = viewModel()
+ viewModel.initiate()
+
+ assertEquals(
+ listOf("Ekklesia", "Checkers"),
+ viewModel.awaitLoaded().otherGroups,
+ "an unnamed one is named by the room, and this ceremony is left out",
+ )
+ }
+
+ @Test
+ fun `a subgroup's ceremony is told nothing of its parent room's groups`(): Unit = runBlocking {
+ roomGroups = listOf(session().copy(id = "e0".repeat(32), subject = "Ekklesia"))
+ sessionRow.value = session().copy(parentChatRoomId = "9a7e".repeat(16))
+ val viewModel = viewModel()
+ viewModel.initiate()
+
+ assertEquals(emptyList(), viewModel.awaitLoaded().otherGroups)
+ }
+
@Test
fun `coming back to the screen keeps the ceremony it was showing`(): Unit = runBlocking {
val viewModel = viewModel()