Let people rename a group

Names used to be fixed at creation and served by the relay for ever, so
no client ever needed this. The relay has now dropped them — and that
makes every group created before the change read as the placeholder on
every phone, with nobody left to ask what it used to be called. The relay
deleted its copy and no client had ever kept one.

Without a rename, those groups are called "Group" permanently. This is
the repair, and it is the first time a group's name has been changeable
at all.

Stored first, announced second: the name is ours the moment we set it, so
a member who cannot be reached now does not stop us seeing the group
under the name we chose. They pick it up from the next message, which
carries it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Paul Hitt
2026-08-30 20:50:50 -04:00
co-authored by Claude Opus 4.8
parent 4a6be0ba6b
commit d128e8d56e
3 changed files with 124 additions and 3 deletions
@@ -186,6 +186,52 @@ class GroupNameTest {
"the delivery key was lost because the envelope also named a group")
}
// -- Renaming --------------------------------------------------------------
/**
* 🔴 **Renaming is how a group gets its name back.** Every group that
* existed before the relay dropped its names reads as the placeholder on
* every device, and nothing can recover the old one: the relay deleted its
* copy and no client had ever stored one. Names were previously fixed at
* creation, so this path did not exist and had to be built.
*/
@Test
fun `a rename is stored and announced to the members`() {
val vault = vault()
vault.saveDelivery(Vault.Delivery(key = ByteArray(32) { 3 }, published = true))
vault.saveGroupName("g1", "Group")
val conversations = conversations(vault)
vault.saveGroupName("g1", "Book club, Tuesdays")
assertEquals("Book club, Tuesdays", vault.groupName("g1"))
// ⚠️ Asserted on the envelope rather than on delivery: the announcement
// is best-effort per member, and a test that required a member to be
// reachable would be testing the fixture's relay, not the rename.
val wire = SealedSender.deliveryKeyEnvelope(
ByteArray(32), groupId = "g1", groupName = vault.groupName("g1")!!)
assertEquals("Book club, Tuesdays", JSONObject(wire).optString("gname"))
assertTrue(conversations.takeClaimedGroupNames().isEmpty())
}
/**
* ⚠️ **An announcement with no name is not sent at all.** A group we have
* never been told the name of has nothing to announce, and an envelope
* carrying an empty `gname` would let a member overwrite a good name with
* a blank one.
*/
@Test
fun `announcing a group with no known name sends nothing`() {
val vault = vault()
vault.saveDelivery(Vault.Delivery(key = ByteArray(32) { 3 }, published = true))
val conversations = conversations(vault)
// No throw, no request: it returns before building anything. If it did
// send, the MockWebServer with no queued response would fail the call.
conversations.announceGroupName("unknown-gid", listOf(2L))
assertEquals(0, server.requestCount)
}
// -- Where it is kept ------------------------------------------------------
@Test