diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 4eecb11f..10338751 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -96,6 +96,8 @@
Invite
Invite a friend
Invite new member
+ Invite new member to %1$s
+ Invite new member to chat
It is cryptographical secure, and decentralized, putting you in total control of your digital profile
Keep the feed alive.
Keep this phrase safe.\nDo not share it.
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoom.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoom.kt
index ab89f4e2..5a473af7 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoom.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoom.kt
@@ -59,6 +59,9 @@ data class ChatRoom(
* Any member can change the topic by simply submitting a new subject to an existing pubkey + p tags room.
*
* There is no need to send subject in every message. The newest subject in the chat room is the subject of the conversation.
+ *
+ * For a Marmot room, the group's bare name. Draw a room's name through [title], which
+ * puts a group's in braces; never off this (docs/group-name-braces.md).
*/
val subject: String?,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoomTitle.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoomTitle.kt
new file mode 100644
index 00000000..7e4c5b88
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/ChatRoomTitle.kt
@@ -0,0 +1,17 @@
+package mobi.giza.compose.database.model
+
+import mobi.giza.compose.managers.MarmotGroupName
+
+/**
+ * The room's name as it is drawn: a Marmot room's [ChatRoom.subject] in braces, a NIP-17
+ * room's as it is, and null when it has none.
+ *
+ * Every screen that shows a room's name reads it here rather than off `subject`, which
+ * holds the bare name (docs/group-name-braces.md, D3). The braces are a mark of what kind
+ * of room this is; they are drawn, never stored.
+ */
+val ChatRoom.title: String?
+ get() {
+ val subject = subject ?: return null
+ return if (mlsGroupState != null) MarmotGroupName.display(subject) else subject
+ }
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/intermdiate/LocalChatRoom.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/intermdiate/LocalChatRoom.kt
index f819dfcc..363a79e9 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/intermdiate/LocalChatRoom.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/model/intermdiate/LocalChatRoom.kt
@@ -16,6 +16,7 @@ import mobi.giza.compose.database.model.Participant
import mobi.giza.compose.extensions.memberName
import mobi.giza.compose.ui.composable.widgets.profile.ProfileColor
import com.vitorpamplona.quartz.nip01Core.core.HexKey
+import mobi.giza.compose.database.model.title
data class LocalChatRoom(
@Embedded val chatRoom: ChatRoom,
@@ -64,9 +65,10 @@ data class LocalChatRoom(
@Composable
fun RenderChatRoomTitleText() {
- if (chatRoom.subject != null) {
+ val title = chatRoom.title
+ if (title != null) {
Text(
- text = chatRoom.subject,
+ text = title,
color = ProfileColor.fromPublicKey(chatRoom.id),
maxLines = 1,
overflow = TextOverflow.Ellipsis
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationName.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationName.kt
new file mode 100644
index 00000000..69eb1fd1
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/ConfederationName.kt
@@ -0,0 +1,42 @@
+package mobi.giza.compose.managers
+
+/**
+ * How a confederation's name is drawn: `Hellenic league`, drawn `{{Hellenic league}}`.
+ *
+ * A confederation is a group of groups (docs/confederation.md), and its name is drawn
+ * with one more pair of braces than a group's ([MarmotGroupName]), so the two never look
+ * alike in a transcript line or a list. docs/group-name-braces.md, D10.
+ *
+ * The braces are drawn, never stored -- and a confederation's name must never be
+ * normalised once it exists. It is signed into the proposal and the charter, and
+ * `ConfederationSigningManager` and `ConfederationChangeRefusal` compare those copies
+ * byte for byte: rewriting one would make a valid charter look tampered with. So [bare]
+ * is applied in one place only, where a name is typed and before it is signed.
+ *
+ * Unlike a group's, a confederation's name never carried a mark, so a leading `#` or `&`
+ * in one is part of the name and is kept. Only braces come off.
+ */
+object ConfederationName {
+ /** Drawn before the name, and shown in the name field before what is typed. */
+ const val PREFIX = "{{"
+
+ /** Drawn after the name, and shown at the trailing edge of the name field. */
+ const val SUFFIX = "}}"
+
+ private val NO_MARKS = CharArray(0)
+
+ /**
+ * [name] without the braces somebody typed around it, or surrounding space. For a name
+ * being *proposed* only: never apply it to a name that has been received or signed.
+ */
+ fun bare(name: String): String = NameMarks.strip(name, NO_MARKS).ifEmpty { name.trim() }
+
+ /**
+ * [name] as it is drawn: `{{` + the name + `}}`. Braces already around the name are
+ * taken off first, so drawing twice changes nothing. A blank name is not given braces.
+ */
+ fun display(name: String): String {
+ val bare = NameMarks.strip(name, NO_MARKS)
+ return if (bare.isEmpty()) name.trim() else PREFIX + bare + SUFFIX
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupName.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupName.kt
index e5706062..dd876d18 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupName.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/MarmotGroupName.kt
@@ -1,64 +1,84 @@
package mobi.giza.compose.managers
/**
- * What a Marmot room is called: an `&`, then the name.
+ * What a Marmot room is called, and how it is drawn: `Ekklesia`, drawn `{Ekklesia}`.
*
* A device's room list holds two unrelated kinds of room. A NIP-17 room is a
* conversation between the people in it; a Marmot room is a *group* -- it has an
* id its key derives, a membership baked into an MLS tree, admins who can act for
* it, and a signature anyone can check. Nothing on a row says which one is which,
- * and the two behave differently enough that guessing is a mistake. The `&` says
- * it, in the one place a user always reads.
+ * and the two behave differently enough that guessing is a mistake. The braces say
+ * it, at the front of the row, where a truncated row still shows the `{`.
*
- * The mark has been spelled three ways. First `"Ekklesia (#admins)"`, which said
- * it in more words and only for the *admin* room -- a subgroup got no marker at
- * all, and "Ekklesia (#admins)" sorted nowhere near "Ekklesia". Then
- * `#Ekklesia`, which marked both kinds at the front, where a truncated row still
- * shows it. Now `&Ekklesia`, because `#` already means something in nostr and in
- * this app: `#word` in a note is a hashtag, and a leading `#` in search is a
- * hashtag search, so a group's name written in a note or typed into search was
- * read as a topic. Nothing gives `&` a meaning. docs/group-name-prefix.md.
+ * The mark is drawn, not stored. It says what kind of room a row is, which is not
+ * part of what the group is called, and storing it meant every reader had to strip
+ * it before comparing, every change of character needed a migration, and the mark
+ * ended up signed into certificates that can never change. So the database, the
+ * wire and every certificate carry the bare name, [bare] is what makes a name so,
+ * and [display] is the only place the braces go on. docs/group-name-braces.md.
*
- * Applied where a Marmot room is minted rather than where it is drawn, because
- * the name is baked into the epoch-0 `MarmotGroupData` every member is welcomed
- * with: a name that only existed at the point of display would be a name this
- * device alone could see. Applied again where a Welcome is joined, so a room
- * minted under `#` -- by an older Giza, or by a Bennu peer -- or by a client
- * that marks nothing, is called the same way as every other.
+ * The mark has been spelled four ways. First `"Ekklesia (#admins)"`, only for the
+ * admin room. Then `#Ekklesia`, stored. Then `&Ekklesia`, stored, because `#word`
+ * is a hashtag (docs/group-name-prefix.md). Now `{Ekklesia}`, drawn. The two stored
+ * marks are still in rooms minted before, in Bennu's rooms, and in old birth
+ * certificates, which is why [bare] takes them off.
+ *
+ * A confederation is drawn `{{name}}`, by [ConfederationName], which is a different
+ * rule: do not draw one through this.
*/
object MarmotGroupName {
- /** Shown in a name field so the user reads the name they are about to get. */
- const val PREFIX = "&"
+ /** Drawn before the name, and shown in a name field before what is typed. */
+ const val PREFIX = "{"
+
+ /** Drawn after the name, and shown at the trailing edge of a name field. */
+ const val SUFFIX = "}"
/**
- * Every mark a Marmot room's name has been given: the current one, and the
- * `#` that rooms minted before docs/group-name-prefix.md still carry in
- * their MLS state and their birth certificates.
+ * The mark stored in front of a Marmot room's name before docs/group-name-braces.md.
+ * Still written by [of] until the writers store the bare name.
*/
- private val MARKS = charArrayOf('&', '#')
+ private const val LEGACY_PREFIX = "&"
/**
- * [name] under the convention, and [name] again if it is already there.
+ * Every mark a Marmot room's name has been stored with: the `&` of
+ * docs/group-name-prefix.md and the `#` before it. Rooms minted under them still
+ * carry them in their MLS state, and certificates signed under them in their tags.
+ */
+ private val LEGACY_MARKS = charArrayOf('&', '#')
+
+ /**
+ * [name] as it is stored: no mark, no braces, no surrounding space.
*
- * Idempotent on purpose. A subgroup's name is normalised twice from the same
- * bare subject and by two unrelated callers -- once into the birth
- * certificate the parent's quorum signs, once onto the room itself -- and
- * those two have to be the same string, or the room is not called what its
- * parent certified.
+ * Idempotent, and `bare` of any old spelling -- `#X`, `&X`, `{X}` -- is `X`, which is
+ * what lets one function name the rooms a Welcome brings in, the rooms already on a
+ * device, and the names old certificates carry.
*
- * Any leading run of marks and space is taken off before the `&` goes on,
- * so an old `#name` and a new `&name` say the same thing. That is what lets
- * this one function rename the rooms already on a device, the rooms a
- * Welcome brings in, and the names old certificates carry.
+ * Only a *leading* mark is a mark: `Arts & crafts` keeps its `&`. A blank name, or one
+ * that is only marks, is handed back trimmed rather than made up.
+ */
+ fun bare(name: String): String = NameMarks.strip(name, LEGACY_MARKS).ifEmpty { name.trim() }
+
+ /**
+ * [name] as it is drawn: `{` + [bare] + `}`. Takes a stored name in any spelling, so it
+ * draws a room minted under `&` the same as one minted since, and drawing a drawn name
+ * again changes nothing. A blank name is not given braces.
+ */
+ fun display(name: String): String {
+ val bare = NameMarks.strip(name, LEGACY_MARKS)
+ return if (bare.isEmpty()) name.trim() else PREFIX + bare + SUFFIX
+ }
+
+ /**
+ * [name] under the stored `&` of docs/group-name-prefix.md: what the writers still
+ * store until docs/group-name-braces.md's Phase 2 has them store [bare].
*
- * A blank name is handed back untouched rather than turned into a bare `&`,
- * and so is a name that is only marks. No caller passes one -- each has a
- * fallback for the room whose subject is missing -- and inventing a name
- * here would hide that if one ever did.
+ * Idempotent on purpose. A subgroup's name is normalised twice from the same bare
+ * subject and by two unrelated callers -- once into the birth certificate the
+ * parent's quorum signs, once onto the room itself -- and those two have to be the
+ * same string, or the room is not called what its parent certified.
*/
fun of(name: String): String {
- val bare = name.trimStart { it.isWhitespace() || it in MARKS }.trimEnd()
-
- return if (bare.isEmpty()) name.trim() else PREFIX + bare
+ val bare = NameMarks.strip(name, LEGACY_MARKS)
+ return if (bare.isEmpty()) name.trim() else LEGACY_PREFIX + bare
}
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/NameMarks.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/NameMarks.kt
new file mode 100644
index 00000000..e76e8795
--- /dev/null
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/managers/NameMarks.kt
@@ -0,0 +1,40 @@
+package mobi.giza.compose.managers
+
+/**
+ * The braces drawn around a name, and the marks older names were stored with, taken off.
+ *
+ * Shared by [MarmotGroupName] and [ConfederationName], which differ only in which other
+ * leading marks count as one. docs/group-name-braces.md, D1 and D10.
+ */
+internal object NameMarks {
+ /**
+ * [name] trimmed, without its leading run of whitespace, `{` and [marks], and without as
+ * many trailing `}` as there were `{` in that run. Empty when nothing else is left.
+ *
+ * A closing brace comes off only when an opening one did, so a name whose real last
+ * character is `}` -- `Set {a}` -- keeps it.
+ */
+ fun strip(name: String, marks: CharArray): String {
+ val text = name.trim()
+ var start = 0
+ var opened = 0
+ while (start < text.length && (text[start].isWhitespace() || text[start] == '{' || text[start] in marks)) {
+ if (text[start] == '{') opened++
+ start++
+ }
+
+ var end = text.length
+ var closed = 0
+ while (true) {
+ while (end > start && text[end - 1].isWhitespace()) end--
+ if (closed < opened && end > start && text[end - 1] == '}') {
+ end--
+ closed++
+ } else {
+ break
+ }
+ }
+
+ return text.substring(start, end)
+ }
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationContent.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationContent.kt
index 008ed058..6a0fc65c 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationContent.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/notifications/NotificationContent.kt
@@ -3,6 +3,7 @@ package mobi.giza.compose.notifications
import kotlin.time.Instant
import mobi.giza.compose.database.model.ChatMessage
import mobi.giza.compose.database.model.intermdiate.LocalChatRoom
+import mobi.giza.compose.database.model.title
/**
* The words a notification is built from that are not anybody's message: read from the string
@@ -61,7 +62,7 @@ object NotificationContent {
* one member's own as a note to self.
*/
fun roomTitle(room: LocalChatRoom, strings: NotificationStrings): String {
- room.chatRoom.subject?.takeIf { it.isNotBlank() }?.let { return it }
+ room.chatRoom.title?.takeIf { it.isNotBlank() }?.let { return it }
val others = room.localParticipants.filter { it.participant.participantPublicKey != room.chatRoom.userPublicKey }
if (others.isEmpty()) return strings.noteToSelf
return others.joinToString(", ") { participant ->
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
index ef5ce8e6..603fabc0 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddGroupPostScreen.kt
@@ -68,6 +68,7 @@ import mobi.giza.compose.resources.the_group_signs_a_post_so_it_takes_a_quorum
import mobi.giza.compose.resources.this_group_has_no_shared_key_to_sign_a_post
import mobi.giza.compose.resources.what_should_the_group_say
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.database.model.title
/**
* The draft of something the group would say, in its own name.
@@ -207,7 +208,7 @@ fun AddGroupPostScreen(
Text(
text = addGroupPostUIState.groupNostrProfile?.name()
?: addGroupPostUIState.postingAs
- ?: addGroupPostUIState.localChatRoom.chatRoom.subject
+ ?: addGroupPostUIState.localChatRoom.chatRoom.title
?: chatRoomId.take(16),
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddMemberToChatRoomConfirmationScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddMemberToChatRoomConfirmationScreen.kt
index a78d75f1..0ad813ab 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddMemberToChatRoomConfirmationScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/AddMemberToChatRoomConfirmationScreen.kt
@@ -53,6 +53,7 @@ import mobi.giza.compose.ui.theme.readableContent
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
import mobi.giza.compose.ui.composable.widgets.buttons.ExtendedFab
import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.database.model.title
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
@Composable
@@ -150,7 +151,7 @@ fun AddMemberToChatRoomConfirmationScreen(
)
Text(
- text = stringResource(Res.string.to_join_the_chat_room, addMemberToChatRoomConfirmationUIState.localChatRoom.chatRoom.subject ?: "")
+ text = stringResource(Res.string.to_join_the_chat_room, addMemberToChatRoomConfirmationUIState.localChatRoom.chatRoom.title ?: "")
)
Text(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
index 2c3e6eb2..d4064a57 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ChatRoomDetailScreen.kt
@@ -279,6 +279,7 @@ import mobi.giza.compose.ui.theme.readableContent
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
import mobi.giza.compose.ui.theme.ConformancePreviews
import kotlin.time.Instant
+import mobi.giza.compose.managers.MarmotGroupName
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
@Composable
@@ -1871,8 +1872,8 @@ private fun SubgroupCard(
},
headlineContent = {
Text(
- text = subgroup.room?.chatRoom?.subject
- ?: subgroup.name
+ text = (subgroup.room?.chatRoom?.subject ?: subgroup.name)
+ ?.let(MarmotGroupName::display)
?: stringResource(Res.string.a_subgroup)
)
},
@@ -2464,7 +2465,7 @@ internal fun GroupsMadeHere(
Icon(Icons.Default.ChevronRight, contentDescription = Decorative)
},
headlineContent = {
- Text(text = group.name?.takeIf { it.isNotBlank() } ?: unnamed)
+ Text(text = group.name?.takeIf { it.isNotBlank() }?.let(MarmotGroupName::display) ?: unnamed)
},
supportingContent = {
Text(
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationChangeScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationChangeScreen.kt
index 6d6b0d4e..65b1a6a4 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationChangeScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationChangeScreen.kt
@@ -93,6 +93,7 @@ import mobi.giza.compose.ui.view.model.ConfederationChangeViewModel
import mobi.giza.compose.ui.view.state.ConfederationChangeUIState
import mobi.giza.compose.ui.view.state.ConfederationChangeUIState.FieldName
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* One proposal for a confederation to sign something, seen from one of its groups
@@ -166,7 +167,7 @@ fun ConfederationChangeScreen(
val change = current.status.change
val nameOf = { key: HexKey -> current.names[key] ?: key.take(12) }
- Text(text = current.confederationName, style = MaterialTheme.typography.headlineSmall)
+ Text(text = ConfederationName.display(current.confederationName), style = MaterialTheme.typography.headlineSmall)
Text(
text = stringResource(Res.string.proposal_overline, proposalKindLabel(change.kind), changeStateLabel(current.status)),
style = MaterialTheme.typography.labelLarge,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationProposalScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationProposalScreen.kt
index cd656c1d..2047373a 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationProposalScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationProposalScreen.kt
@@ -80,6 +80,7 @@ import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.view.model.ConfederationProposalViewModel
import mobi.giza.compose.ui.view.state.ConfederationProposalUIState
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* One confederation proposal, seen from one of the groups it names (docs/confederation.md,
@@ -154,7 +155,7 @@ fun ConfederationProposalScreen(
val proposal = current.status.proposal
val nameOf = { key: HexKey -> current.names[key] ?: key.take(12) }
- Text(text = proposal.name, style = MaterialTheme.typography.headlineSmall)
+ Text(text = ConfederationName.display(proposal.name), style = MaterialTheme.typography.headlineSmall)
Text(text = stateLabel(current.status.state), style = MaterialTheme.typography.labelLarge)
Text(text = stringResource(Res.string.confederation_proposed_by, nameOf(proposal.proposingGroup)))
Text(text = stringResource(Res.string.confederation_groups_to_act, proposal.threshold, proposal.groups.size))
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt
index ce0c178f..ec036e0e 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationRitualScreen.kt
@@ -67,6 +67,7 @@ import mobi.giza.compose.ui.view.model.ConfederationRitualViewModel
import mobi.giza.compose.ui.view.state.ConfederationRitualUIState
import mobi.giza.compose.ui.view.state.ConfederationRitualUIState.StepKind
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* A confederation's key ceremony (docs/confederation.md, Phase 11): the groups and who holds a role
@@ -125,7 +126,7 @@ fun ConfederationRitualScreen(
.padding(MaterialTheme.spacing.screenMargin),
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
) {
- Text(text = current.name, style = MaterialTheme.typography.headlineSmall)
+ Text(text = ConfederationName.display(current.name), style = MaterialTheme.typography.headlineSmall)
Text(text = stringResource(Res.string.confederation_groups_to_act, current.threshold, current.groups.size))
Text(text = stringResource(Res.string.the_others_have_started_without_you))
if (identityCanSign) {
@@ -153,7 +154,7 @@ fun ConfederationRitualScreen(
verticalArrangement = Arrangement.spacedBy(MaterialTheme.spacing.itemGap),
) {
val ceremony = current.ceremony
- Text(text = current.name, style = MaterialTheme.typography.headlineSmall)
+ Text(text = ConfederationName.display(current.name), style = MaterialTheme.typography.headlineSmall)
Text(text = stringResource(Res.string.confederation_groups_to_act, current.threshold, current.groups.size))
when (ceremony.stage) {
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt
index fb87b444..159163f5 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationScreen.kt
@@ -115,6 +115,7 @@ import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.ui.graphics.vector.ImageVector
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* A formed confederation, seen from one of its member groups (docs/confederation-profile.md, D1;
@@ -166,7 +167,7 @@ fun ConfederationScreen(
snackbarHost = { SnackbarHost(LocalSnackbarHostState.current) },
topBar = {
TopAppBar(
- title = { Text(text = (state as? ConfederationUIState.Loaded)?.name ?: "", maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ title = { Text(text = (state as? ConfederationUIState.Loaded)?.name?.let(ConfederationName::display) ?: "", maxLines = 1, overflow = TextOverflow.Ellipsis) },
navigationIcon = { NavigateBackButton(onNavigateBack) },
)
},
@@ -338,7 +339,7 @@ private fun ConfederationProfileCard(state: ConfederationUIState.Loaded) {
leadingContent = { ProfileAvatar(publicKey = state.confederationId, picture = profile?.picture(), name = profile?.name() ?: state.name) },
headlineContent = {
Text(
- text = profile?.let { it.name() ?: stringResource(Res.string.no_name_on_this_profile) } ?: state.name,
+ text = profile?.let { it.name() ?: stringResource(Res.string.no_name_on_this_profile) } ?: ConfederationName.display(state.name),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationsScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationsScreen.kt
index 0849d14d..89947302 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationsScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ConfederationsScreen.kt
@@ -62,6 +62,7 @@ import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.view.model.ConfederationsViewModel
import mobi.giza.compose.ui.view.state.ConfederationsUIState
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* Every confederation proposal naming a group, its own and the ones inviting it, newest first
@@ -187,7 +188,7 @@ private fun ConfederationProposalCard(item: ConfederationsUIState.Item, onClick:
overlineContent = {
Text(text = if (item.formed) stringResource(Res.string.confederation_formed) else stateLabel(status.state))
},
- headlineContent = { Text(text = proposal.name, maxLines = 1, overflow = TextOverflow.Ellipsis) },
+ headlineContent = { Text(text = ConfederationName.display(proposal.name), maxLines = 1, overflow = TextOverflow.Ellipsis) },
supportingContent = {
Column {
Text(text = stringResource(Res.string.confederation_proposed_by, item.proposerName))
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/CreateSharedKeyScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/CreateSharedKeyScreen.kt
index 7425a6b2..2e1d7b13 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/CreateSharedKeyScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/CreateSharedKeyScreen.kt
@@ -75,6 +75,7 @@ import mobi.giza.compose.ui.theme.readableContent
import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.view.model.CreateSharedKeyViewModel
import mobi.giza.compose.ui.view.state.CreateSharedKeyUIState
+import mobi.giza.compose.managers.MarmotGroupName
/**
* Starts a group's key ceremony in a NIP-17 room: its name, the quorum, and one
@@ -135,7 +136,7 @@ fun CreateSharedKeyScreen(
// room that already has a group is making another, and its name
// is the first group's, not this one's.
val loaded = state as? CreateSharedKeyUIState.Loaded
- val subject = loaded?.takeIf { !it.needsName }?.localChatRoom?.chatRoom?.subject
+ val subject = loaded?.takeIf { !it.needsName }?.localChatRoom?.chatRoom?.subject?.let(MarmotGroupName::display)
Text(
text = when {
loaded?.needsName == true -> stringResource(Res.string.new_group_with_these_members)
@@ -199,7 +200,7 @@ fun CreateSharedKeyScreen(
val unnamed = stringResource(Res.string.an_unnamed_group)
val roomSubject = uiState.localChatRoom.chatRoom.subject
val names = uiState.groups.joinToString(", ") {
- it.subject ?: roomSubject ?: unnamed
+ (it.subject ?: roomSubject)?.let(MarmotGroupName::display) ?: unnamed
}
Text(
text = if (uiState.groups.size == 1) {
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 ea7840b2..f47235f1 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
@@ -30,6 +30,7 @@ import mobi.giza.compose.resources.you
import mobi.giza.compose.resources.your_device_publishes_the_key_it_will_be
import mobi.giza.compose.resources.your_share_of_the_key_never_leaves_this
import mobi.giza.compose.ui.theme.spacing
+import mobi.giza.compose.managers.MarmotGroupName
/**
* Asks whether to join a shared key ceremony somebody else opened.
@@ -76,8 +77,8 @@ fun DkgJoinApprovalScreen(
// 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
+ val group = (session.subject ?: state.localChatRoom.chatRoom.subject)
+ ?.let(MarmotGroupName::display)
?: stringResource(Res.string.this_group)
Text(
@@ -96,7 +97,7 @@ fun DkgJoinApprovalScreen(
Text(
text = stringResource(
Res.string.you_already_share_with_these_people_this_makes_a_separate_group,
- state.otherGroups.joinToString(", ")
+ state.otherGroups.joinToString(", ", transform = MarmotGroupName::display)
),
style = MaterialTheme.typography.bodyLarge
)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgRitualScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgRitualScreen.kt
index eca8ae8f..76641311 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgRitualScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/DkgRitualScreen.kt
@@ -133,6 +133,7 @@ import mobi.giza.compose.ui.theme.readableContent
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
import mobi.giza.compose.ui.composable.widgets.buttons.ExtendedFab
import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.managers.MarmotGroupName
/**
* One shared-key ceremony: a ChillDKG ritual, shown as a ladder of rounds so
@@ -199,12 +200,12 @@ fun DkgRitualScreen(
Text(
// The ceremony's name, not the room's: a subgroup's
// runs in its parent's room, and "Shared key for
- // #Checkers" over Tapscript's ceremony names the
+ // {Checkers}" over Tapscript's ceremony names the
// one group it is not for.
text = stringResource(
Res.string.shared_key_for,
- session.subject
- ?: dkgRitualUIState.localChatRoom.chatRoom.subject
+ (session.subject ?: dkgRitualUIState.localChatRoom.chatRoom.subject)
+ ?.let(MarmotGroupName::display)
?: "this group"
),
maxLines = 1,
@@ -604,7 +605,7 @@ internal fun RitualProgress(
// more than one group in this room (docs/nip17-multiple-ceremonies.md).
Text(
text = session.subject
- ?.let { stringResource(Res.string.s_has_a_shared_key, it) }
+ ?.let { stringResource(Res.string.s_has_a_shared_key, MarmotGroupName.display(it)) }
?: stringResource(Res.string.the_group_has_a_shared_key),
style = MaterialTheme.typography.titleSmall
)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
index 99cbfabc..e5cec448 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreen.kt
@@ -93,6 +93,7 @@ import mobi.giza.compose.ui.view.state.MemberActionBlocker
import mobi.giza.compose.ui.view.state.MemberActionUnavailableUIState
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.MarmotGroupName
/**
* Why a member row's action cannot be taken now, and what would change that.
@@ -197,7 +198,7 @@ fun MemberActionUnavailableScreen(
if (state.adminRooms.size == 1 || adminRoom.name == null) {
stringResource(Res.string.open_the_admin_room)
} else {
- stringResource(Res.string.open_room_named, adminRoom.name)
+ stringResource(Res.string.open_room_named, MarmotGroupName.display(adminRoom.name))
}
)
}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeConfederationScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeConfederationScreen.kt
index 5127b48f..5035b778 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeConfederationScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeConfederationScreen.kt
@@ -94,6 +94,7 @@ import mobi.giza.compose.ui.view.state.ProposeConfederationUIState
import mobi.giza.compose.ui.view.state.ProposeConfederationUIState.GroupLookup
import mobi.giza.compose.ui.view.state.ProposeConfederationUIState.Lookup
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.ConfederationName
/**
* Proposing that this group and others form a confederation (docs/confederation.md, Phase 6).
@@ -215,6 +216,10 @@ fun ProposeConfederationScreen(
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
state = nameField,
+ // Drawn around the field, never stored: the name proposed is what
+ // is typed (docs/group-name-braces.md, D10).
+ prefix = { Text(ConfederationName.PREFIX) },
+ suffix = { Text(ConfederationName.SUFFIX) },
label = { Text(stringResource(Res.string.confederation_name)) },
supportingText = { Text(stringResource(Res.string.confederation_name_supporting)) },
lineLimits = androidx.compose.foundation.text.input.TextFieldLineLimits.SingleLine,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeGroupEventScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeGroupEventScreen.kt
index fdd40117..111b966b 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeGroupEventScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/ProposeGroupEventScreen.kt
@@ -84,6 +84,7 @@ import mobi.giza.compose.resources.this_group_has_no_shared_key_to_sign_an_event
import mobi.giza.compose.resources.unsigned_event
import mobi.giza.compose.resources.what_the_group_would_sign
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.database.model.title
/**
* An unsigned event, pasted, for the group to sign.
@@ -225,7 +226,7 @@ fun ProposeGroupEventScreen(
Text(
text = proposeGroupEventUIState.groupNostrProfile?.name()
- ?: proposeGroupEventUIState.localChatRoom.chatRoom.subject
+ ?: proposeGroupEventUIState.localChatRoom.chatRoom.title
?: chatRoomId.take(16),
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SearchMemberToAddToChatRoomScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SearchMemberToAddToChatRoomScreen.kt
index c35fb66c..8b7aca27 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SearchMemberToAddToChatRoomScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SearchMemberToAddToChatRoomScreen.kt
@@ -51,6 +51,9 @@ import mobi.giza.compose.ui.composable.widgets.NavigateBackButton
import mobi.giza.compose.ui.theme.readableContent
import mobi.giza.compose.ui.composable.widgets.ScreenStateTransition
import mobi.giza.compose.ui.theme.ConformancePreviews
+import mobi.giza.compose.database.model.title
+import mobi.giza.compose.resources.invite_new_member_to
+import mobi.giza.compose.resources.invite_new_member_to_chat
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalMaterial3Api::class)
@Composable
@@ -96,11 +99,9 @@ fun SearchMemberToAddToChatRoomScreen(
topBar = {
TopAppBar(
title = {
- val title = if (searchMemberToAddToChatRoomUIState.localChatRoom.chatRoom.subject != null) {
- "Invite new member to ${searchMemberToAddToChatRoomUIState.localChatRoom.chatRoom.subject}"
- } else {
- "Invite new member to chat"
- }
+ val title = searchMemberToAddToChatRoomUIState.localChatRoom.chatRoom.title
+ ?.let { stringResource(Res.string.invite_new_member_to, it) }
+ ?: stringResource(Res.string.invite_new_member_to_chat)
Text(
text = title,
)
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectQuorumScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectQuorumScreen.kt
index f0bcf9b1..bb32bc3c 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectQuorumScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectQuorumScreen.kt
@@ -79,6 +79,7 @@ import mobi.giza.compose.ui.theme.spacing
import mobi.giza.compose.ui.view.model.SelectQuorumViewModel
import mobi.giza.compose.ui.view.state.SelectQuorumUIState
import org.jetbrains.compose.resources.stringResource
+import mobi.giza.compose.managers.MarmotGroupName
/**
* Last step of group creation: how many of the group have to agree to a change,
@@ -309,7 +310,7 @@ private fun ExistingGroupsCard(
sharesName: Boolean,
) {
val unnamed = stringResource(Res.string.an_unnamed_group)
- val names = existingGroups.joinToString(", ") { it.name?.takeIf(String::isNotBlank) ?: unnamed }
+ val names = existingGroups.joinToString(", ") { it.name?.takeIf(String::isNotBlank)?.let(MarmotGroupName::display) ?: unnamed }
Card(
modifier = Modifier.fillMaxWidth(),
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectSubgroupAdminsScreen.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectSubgroupAdminsScreen.kt
index 8ae3913e..4a35dfe2 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectSubgroupAdminsScreen.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/composable/SelectSubgroupAdminsScreen.kt
@@ -163,12 +163,13 @@ fun SelectSubgroupAdminsScreen(
onValueChange = viewModel::setName,
modifier = Modifier.fillMaxWidth(),
singleLine = true,
- // Every Marmot room is an `&name`, and a subgroup is
- // one. Shown in the field rather than added on
- // confirm alone, so the name the coordinator reads
- // here is the name the parent's admins will be asked
- // to approve.
+ // Every Marmot room is drawn `{name}`, and a subgroup
+ // is one. The braces frame the field and are never
+ // stored: what is typed between them is the name the
+ // parent's admins will be asked to approve
+ // (docs/group-name-braces.md, D7).
prefix = { Text(MarmotGroupName.PREFIX) },
+ suffix = { Text(MarmotGroupName.SUFFIX) },
label = { Text(stringResource(Res.string.what_is_the_subgroup_called)) }
)
}
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 cd861a51..31eb30b1 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
@@ -99,6 +99,7 @@ import mobi.giza.compose.resources.proposals_are_waiting_for_your_signature
import mobi.giza.compose.resources.reply_privately_to
import mobi.giza.compose.resources.sent_a_private_message_to
import mobi.giza.compose.ui.composable.widgets.ErrorState
+import mobi.giza.compose.managers.MarmotGroupName
/**
* A chat room's transcript: its messages, the notices between them, and the standing ask
@@ -700,7 +701,7 @@ internal fun CeremoniesAwaitingYouNotice(
// 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.subject != null -> stringResource(Res.string.the_key_ceremony_for_needs_you, MarmotGroupName.display(single.subject))
single.isSubgroup -> stringResource(Res.string.the_subgroups_key_ceremony_needs_you)
else -> stringResource(Res.string.the_key_ceremony_needs_you)
}
@@ -714,7 +715,7 @@ internal fun CeremoniesAwaitingYouNotice(
// The two rounds after it are never asked for, so they say nothing here.
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(", ")
+ ceremonies.mapNotNull { it.subject?.let(MarmotGroupName::display) }.takeIf { it.isNotEmpty() }?.joinToString(", ")
} else single.let {
when (val ask = it.ask) {
is ChatMessageListViewModel.Ask.SharedKeyStep -> when (ask.step) {
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ProposeConfederationViewModel.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ProposeConfederationViewModel.kt
index 2c46e9a3..d5e783c0 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ProposeConfederationViewModel.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/ui/view/model/ProposeConfederationViewModel.kt
@@ -31,6 +31,7 @@ import mobi.giza.compose.repository.NostrRepository
import mobi.giza.compose.ui.view.state.ProposeConfederationUIState
import mobi.giza.compose.ui.view.state.ProposeConfederationUIState.GroupLookup
import mobi.giza.compose.ui.view.state.ProposeConfederationUIState.Lookup
+import mobi.giza.compose.managers.ConfederationName
/**
* The form a group's admin fills in to propose a confederation (docs/confederation.md,
@@ -151,7 +152,9 @@ class ProposeConfederationViewModel(
userPublicKey = activeUserPublicKey,
invitees = form.invitees.map { it.publicKey },
threshold = form.threshold,
- name = name.trim(),
+ // The one place a confederation's name is normalised: typed, not yet
+ // signed. Once signed it is compared byte for byte (ConfederationName).
+ name = ConfederationName.bare(name),
expiresAt = Clock.System.now().epochSeconds + form.expiryDays * SECONDS_PER_DAY,
)
}.onFailure { logger.e("Could not propose a confederation for $chatRoomId", it) }.getOrNull()
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/ChatRoomTitleTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/ChatRoomTitleTest.kt
new file mode 100644
index 00000000..0e46c4b1
--- /dev/null
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/database/model/ChatRoomTitleTest.kt
@@ -0,0 +1,30 @@
+package mobi.giza.compose.database.model
+
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNull
+
+/** A room's name as drawn: a group's in braces, a conversation's as it is (docs/group-name-braces.md, D3). */
+class ChatRoomTitleTest {
+ private fun room(subject: String?, marmot: Boolean) =
+ ChatRoom(id = "a".repeat(64), userPublicKey = "b".repeat(64), subject = subject, description = null, mlsGroupState = if (marmot) "00" else null)
+
+ @Test
+ fun `a group is drawn in braces however it was stored`() {
+ listOf("Ekklesia", "&Ekklesia", "#Ekklesia").forEach {
+ assertEquals("{Ekklesia}", room(it, marmot = true).title, "title of $it")
+ }
+ }
+
+ @Test
+ fun `a conversation is drawn as it is called`() {
+ assertEquals("&topic", room("&topic", marmot = false).title)
+ assertEquals("Book club", room("Book club", marmot = false).title)
+ }
+
+ @Test
+ fun `a room with no name has no title`() {
+ assertNull(room(null, marmot = true).title)
+ assertNull(room(null, marmot = false).title)
+ }
+}
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ConfederationNameTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ConfederationNameTest.kt
new file mode 100644
index 00000000..9da0b06b
--- /dev/null
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/ConfederationNameTest.kt
@@ -0,0 +1,44 @@
+package mobi.giza.compose.managers
+
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+/** A confederation's name, drawn in doubled braces (docs/group-name-braces.md, D10). */
+class ConfederationNameTest {
+ @Test
+ fun `a name is drawn in doubled braces`() {
+ assertEquals("{{Hellenic league}}", ConfederationName.display("Hellenic league"))
+ }
+
+ @Test
+ fun `braces already around the name are not doubled again`() {
+ listOf("League", "{League}", "{{League}}", " {{ League }} ").forEach {
+ assertEquals("{{League}}", ConfederationName.display(it), "display($it)")
+ assertEquals("League", ConfederationName.bare(it), "bare($it)")
+ }
+ }
+
+ @Test
+ fun `drawing a drawn name changes nothing`() {
+ val once = ConfederationName.display("League")
+
+ assertEquals(once, ConfederationName.display(once))
+ }
+
+ @Test
+ fun `a leading hash or ampersand is part of a confederation's name`() {
+ assertEquals("{{#1 league}}", ConfederationName.display("#1 league"))
+ assertEquals("&Co", ConfederationName.bare("&Co"))
+ }
+
+ @Test
+ fun `a real closing brace is kept`() {
+ assertEquals("{{Set {a}}}", ConfederationName.display("Set {a}"))
+ }
+
+ @Test
+ fun `a blank name is not given braces`() {
+ assertEquals("", ConfederationName.display(" "))
+ assertEquals("", ConfederationName.display(""))
+ }
+}
diff --git a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MarmotGroupNameTest.kt b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MarmotGroupNameTest.kt
index 97bc7039..21c66914 100644
--- a/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MarmotGroupNameTest.kt
+++ b/composeApp/src/commonTest/kotlin/mobi/giza/compose/managers/MarmotGroupNameTest.kt
@@ -4,70 +4,79 @@ import kotlin.test.Test
import kotlin.test.assertEquals
/**
- * The convention, checked at the one function that applies it.
+ * The convention, checked at the functions that apply it: [MarmotGroupName.bare] for what
+ * is stored, [MarmotGroupName.display] for what is drawn (docs/group-name-braces.md, D1).
*
- * Idempotence is the property worth a test. The name a subgroup ends up with
- * passes through here four times -- typed, carried on the ceremony room, signed
- * into the birth certificate, normalised again at creation -- and a rule that
- * added an `&` each time would leave the room called something its parent never
- * certified.
- *
- * The `#` inputs are the mark rooms carried before docs/group-name-prefix.md, on
- * purpose: they are what an older Giza or a Bennu peer still mints.
+ * The `&` and `#` inputs are the marks rooms were stored with before, on purpose: they are
+ * what an older Giza or a Bennu peer still mints, and what old certificates carry.
*/
class MarmotGroupNameTest {
+ /** Stored or received, then bare, then drawn: D1's table, row by row. */
+ private val table = listOf(
+ Triple("Ekklesia", "Ekklesia", "{Ekklesia}"),
+ Triple("&Ekklesia", "Ekklesia", "{Ekklesia}"),
+ Triple("#Ekklesia", "Ekklesia", "{Ekklesia}"),
+ Triple("{Ekklesia}", "Ekklesia", "{Ekklesia}"),
+ Triple("# & #Ekklesia", "Ekklesia", "{Ekklesia}"),
+ Triple("{{Ekklesia}}", "Ekklesia", "{Ekklesia}"),
+ Triple("{ Ekklesia }", "Ekklesia", "{Ekklesia}"),
+ Triple("{Ekklesia", "Ekklesia", "{Ekklesia}"),
+ Triple(" Ekklesia ", "Ekklesia", "{Ekklesia}"),
+ Triple("Book club", "Book club", "{Book club}"),
+ Triple("Arts & crafts", "Arts & crafts", "{Arts & crafts}"),
+ Triple("#Room #2", "Room #2", "{Room #2}"),
+ Triple("Set {a}", "Set {a}", "{Set {a}}"),
+ Triple("Ekklesia}", "Ekklesia}", "{Ekklesia}}"),
+ )
+
@Test
- fun `a plain name gets the prefix`() {
+ fun `every spelling is stored bare`() {
+ table.forEach { (input, bare, _) -> assertEquals(bare, MarmotGroupName.bare(input), "bare($input)") }
+ }
+
+ @Test
+ fun `every spelling is drawn in braces`() {
+ table.forEach { (input, _, drawn) -> assertEquals(drawn, MarmotGroupName.display(input), "display($input)") }
+ }
+
+ @Test
+ fun `bare is idempotent`() {
+ table.forEach { (input, _, _) ->
+ val once = MarmotGroupName.bare(input)
+ assertEquals(once, MarmotGroupName.bare(once), "bare(bare($input))")
+ }
+ }
+
+ @Test
+ fun `drawing a drawn name changes nothing`() {
+ table.forEach { (input, _, _) ->
+ val once = MarmotGroupName.display(input)
+ assertEquals(once, MarmotGroupName.display(once), "display(display($input))")
+ }
+ }
+
+ @Test
+ fun `an old name and a new name are the same name`() {
+ val names = listOf("Translators", "&Translators", "#Translators", "{Translators}")
+
+ assertEquals(setOf("Translators"), names.map(MarmotGroupName::bare).toSet())
+ assertEquals(setOf("{Translators}"), names.map(MarmotGroupName::display).toSet())
+ }
+
+ @Test
+ fun `a blank name is left alone rather than turned into bare marks`() {
+ listOf(" " to "", "&" to "&", "#" to "#", "{}" to "{}", "{" to "{").forEach { (input, expected) ->
+ assertEquals(expected, MarmotGroupName.bare(input), "bare($input)")
+ assertEquals(expected, MarmotGroupName.display(input), "display($input)")
+ }
+ }
+
+ @Test
+ fun `the stored mark is still the old one until the writers store bare`() {
assertEquals("&Ekklesia", MarmotGroupName.of("Ekklesia"))
- }
-
- @Test
- fun `a name that already has the prefix keeps exactly one`() {
- assertEquals("&Ekklesia", MarmotGroupName.of("&Ekklesia"))
- assertEquals("&Ekklesia", MarmotGroupName.of("&&&Ekklesia"))
- }
-
- @Test
- fun `the old mark is replaced rather than kept`() {
assertEquals("&Ekklesia", MarmotGroupName.of("#Ekklesia"))
- assertEquals("&Ekklesia", MarmotGroupName.of("###Ekklesia"))
- assertEquals("&Ekklesia", MarmotGroupName.of("# & #Ekklesia"))
- }
-
- @Test
- fun `an old name and a new name normalise to the same thing`() {
- assertEquals(MarmotGroupName.of("&Translators"), MarmotGroupName.of("#Translators"))
- }
-
- @Test
- fun `applying it twice says the same thing as applying it once`() {
- val once = MarmotGroupName.of("Translators")
-
- assertEquals(once, MarmotGroupName.of(once))
- }
-
- @Test
- fun `surrounding space is not part of the name`() {
- assertEquals("&Ekklesia", MarmotGroupName.of(" Ekklesia "))
- assertEquals("&Ekklesia", MarmotGroupName.of("& Ekklesia"))
- assertEquals("&Ekklesia", MarmotGroupName.of("# Ekklesia"))
- }
-
- @Test
- fun `space inside the name is`() {
- assertEquals("&Book club", MarmotGroupName.of("Book club"))
- }
-
- @Test
- fun `only a leading mark is a mark`() {
- assertEquals("&Arts & crafts", MarmotGroupName.of("Arts & crafts"))
- assertEquals("&Room #2", MarmotGroupName.of("#Room #2"))
- }
-
- @Test
- fun `a blank name is left alone rather than turned into a bare mark`() {
- assertEquals("", MarmotGroupName.of(" "))
+ assertEquals("&Ekklesia", MarmotGroupName.of("&Ekklesia"))
+ assertEquals(MarmotGroupName.of("Translators"), MarmotGroupName.of(MarmotGroupName.of("Translators")))
assertEquals("&", MarmotGroupName.of("&"))
- assertEquals("#", MarmotGroupName.of("#"))
}
}
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
index 2a2968a4..f14389d8 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/CeremoniesAwaitingYouNoticeJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/CeremoniesAwaitingYouNoticeJvmTest.kt
@@ -33,14 +33,14 @@ class CeremoniesAwaitingYouNoticeJvmTest {
@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()
+ 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()
+ onNodeWithText("{Agora}, {Ekklesia}").assertExists()
}
@Test
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt
index b5f82488..fecf7923 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/ConfederationScreensJvmTest.kt
@@ -152,7 +152,7 @@ class ConfederationScreensJvmTest {
),
)
) {
- onNodeWithText("Atlas").assertIsDisplayed()
+ onNodeWithText("{{Atlas}}").assertIsDisplayed()
onNodeWithText("Open").assertIsDisplayed()
onNodeWithText("Proposed by Polis").assertIsDisplayed()
onNodeWithText("Waiting on 1 of 2 groups").assertIsDisplayed()
@@ -217,7 +217,7 @@ class ConfederationScreensJvmTest {
fun `an invited group is offered both answers, and told what accepting discloses`() = renderProposal(
ConfederationProposalUIState.Loaded(localChatRoom = localChatRoom, status = status(), names = mapOf(polis to "Polis", roomId to "This group"), canSign = true)
) {
- onNodeWithText("Atlas").assertIsDisplayed()
+ onNodeWithText("{{Atlas}}").assertIsDisplayed()
onAllNodesWithText("Coordinated by", substring = true).assertCountEquals(0)
onNodeWithText("Accepting shows this group's admins and threshold to the admins of every group", substring = true).assertIsDisplayed()
onNodeWithText("Propose accepting").assertIsDisplayed()
@@ -236,7 +236,7 @@ class ConfederationScreensJvmTest {
fun `a member without a share reads it and is offered nothing`() = renderProposal(
ConfederationProposalUIState.Loaded(localChatRoom = localChatRoom, status = status(), canSign = false)
) {
- onNodeWithText("Atlas").assertIsDisplayed()
+ onNodeWithText("{{Atlas}}").assertIsDisplayed()
onAllNodesWithText("Propose accepting").assertCountEquals(0)
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/GroupsMadeHereJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/GroupsMadeHereJvmTest.kt
index efe75a90..c9e829b0 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/GroupsMadeHereJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/GroupsMadeHereJvmTest.kt
@@ -33,11 +33,11 @@ class GroupsMadeHereJvmTest {
@Test
fun `every group is listed, with where it stands`() = render(listOf(agora, forum, ekklesia)) {
- onNodeWithText("Agora").assertExists()
+ onNodeWithText("{Agora}").assertExists()
onNodeWithText("Key ceremony in progress").assertExists()
- onNodeWithText("Forum").assertExists()
+ onNodeWithText("{Forum}").assertExists()
onNodeWithText("Has its key, and is waiting for its room").assertExists()
- onNodeWithText("Ekklesia").assertExists()
+ onNodeWithText("{Ekklesia}").assertExists()
onNodeWithText("Every member of this group is an admin there.").assertExists()
}
@@ -45,7 +45,7 @@ class GroupsMadeHereJvmTest {
fun `a group is opened by the one tapped`() {
var opened: GroupMadeHere? = null
render(listOf(agora, ekklesia), onOpen = { opened = it }) {
- onNodeWithText("Ekklesia").performClick()
+ onNodeWithText("{Ekklesia}").performClick()
}
assertEquals(ekklesia, opened)
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
index 1bf2d412..574f8bef 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/MemberActionUnavailableScreenJvmTest.kt
@@ -130,8 +130,8 @@ class MemberActionUnavailableScreenJvmTest {
var opened: Route? = null
render(blocked(MemberActionBlocker.NoAdminsInThisRoom, adminRooms = rooms), onNavigateToRoute = { opened = it }) {
onNodeWithText("Open the admin room").assertDoesNotExist()
- onNodeWithText("Open &Checkers").assertExists()
- onNodeWithText("Open &Chess").performClick()
+ onNodeWithText("Open {Checkers}").assertExists()
+ onNodeWithText("Open {Chess}").performClick()
}
assertEquals(ChatRoomDetailRoute(activeUserPublicKey, "9".repeat(64), null), opened)
}
diff --git a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/RitualProgressNameJvmTest.kt b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/RitualProgressNameJvmTest.kt
index 4b98fa63..0e8b8cdb 100644
--- a/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/RitualProgressNameJvmTest.kt
+++ b/composeApp/src/jvmTest/kotlin/mobi/giza/compose/ui/composable/RitualProgressNameJvmTest.kt
@@ -67,7 +67,7 @@ class RitualProgressNameJvmTest {
}
@Test
- fun `a finished group is named`() = render(finished("Agora"), "Agora has a shared key.")
+ fun `a finished group is named`() = render(finished("Agora"), "{Agora} has a shared key.")
@Test
fun `a ceremony from before names keeps its words`() = render(finished(null), "The group has a shared key.")