feat: each group's room hears of a change to its confederation's profile (confederation-profile, Phase 3)

A line in each member group's room a device holds, for every change,
endorsement, objection and withdrawal it files, once each, and for the
answers that arrived before their change once the change does. The line
carries the change's id so the next phase can make it open the change.
Another group proposing a change notifies; the answers are quiet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-22 23:34:55 +02:00
1 parent c293514dc1
commit 44cbe596d2
6 files changed
+210 -2

No files matched your search

@@ -561,7 +561,26 @@ data class ChatMessage(
const val TYPE_CONFEDERATION_SIGNING_PROPOSED = "confederationSigningProposed"
const val TYPE_CONFEDERATION_SIGNING_FAILED = "confederationSigningFailed"
val CONFEDERATION_TYPES = setOf(
/**
* A formed confederation's profile, decided by its groups (docs/confederation-profile.md, D8):
* a group proposing a change, another endorsing or objecting to it, and the new profile once
* the confederation has signed it. Written by each device into its own member groups' rooms.
* [frostSigningSessionId] carries the change's id, or for a published profile the
* confederation's, so the line opens what it is about.
*/
const val TYPE_CONFEDERATION_PROFILE_PROPOSED = "confederationProfileProposed"
const val TYPE_CONFEDERATION_PROFILE_ENDORSED = "confederationProfileEndorsed"
const val TYPE_CONFEDERATION_PROFILE_OBJECTED = "confederationProfileObjected"
const val TYPE_CONFEDERATION_PROFILE_PUBLISHED = "confederationProfilePublished"
val CONFEDERATION_PROFILE_TYPES = setOf(
TYPE_CONFEDERATION_PROFILE_PROPOSED,
TYPE_CONFEDERATION_PROFILE_ENDORSED,
TYPE_CONFEDERATION_PROFILE_OBJECTED,
TYPE_CONFEDERATION_PROFILE_PUBLISHED,
)
val CONFEDERATION_TYPES = CONFEDERATION_PROFILE_TYPES + setOf(
TYPE_CONFEDERATION_PROPOSED,
TYPE_CONFEDERATION_ACCEPTED,
TYPE_CONFEDERATION_REJECTED,
@@ -6,7 +6,9 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.crypto.verify
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import kotlin.time.Clock
import kotlin.time.Instant
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.model.ChatMessage
import mobi.giza.compose.database.model.ConfederationEvent
import mobi.giza.compose.database.model.FrostSigningSession
import mobi.giza.compose.database.model.GroupSignedEvent
@@ -54,7 +56,7 @@ object ConfederationProfileManager {
logger.w("Profile statement ${rumor.id.take(8)} of kind ${rumor.kind} is not well formed; dropping")
return false
}
return database.confederationDao().record(
val filed = database.confederationDao().record(
ConfederationEvent(
id = rumor.id,
kind = rumor.kind,
@@ -67,6 +69,61 @@ object ConfederationProfileManager {
confederationId = confederation,
)
)
// Once per statement, by construction: the row above is written once. An answer filed before
// its change had nothing to name, so the change writes their lines now: wraps arrive in any order.
if (filed) runCatching {
announce(database, rumor, changeId)
if (rumor.kind == ConfederationKinds.PROFILE_CHANGE) {
database.confederationDao().getEventsForProposal(changeId)
.filter { it.kind == ConfederationKinds.ENDORSEMENT || it.kind == ConfederationKinds.OBJECTION }
.forEach { announce(database, it.toEvent(), changeId) }
}
}.onFailure { logger.w(throwable = it) { "Filed ${rumor.id.take(8)} but could not write its line" } }
return filed
}
/**
* A system line in each member group's room this device holds, for [statement] about [changeId]
* (D8). Written by each device for itself, sending nothing; the line carries the change's id so
* it opens the change.
*/
private suspend fun announce(database: GizaDatabase, statement: Event, changeId: HexKey) {
val change = change(database, changeId) ?: return
val name = membership(database, change.confederation)?.name ?: "the confederation"
change.groups.mapNotNull { database.chatRoomDao().findChatRoomById(it) }.forEach { room ->
val roomId = room.chatRoom.id
val who = ConfederationManager.nameOf(database, statement.pubKey, roomId)
val proposer = ConfederationManager.nameOf(database, change.proposingGroup, roomId).let { if (it == "This group") "this group" else it }
val (type, content) = when (statement.kind) {
ConfederationKinds.PROFILE_CHANGE -> ChatMessage.TYPE_CONFEDERATION_PROFILE_PROPOSED to
if (statement.pubKey == roomId) "This group proposed a new profile for $name" else "$who proposes a new profile for $name"
ConfederationKinds.ENDORSEMENT -> ChatMessage.TYPE_CONFEDERATION_PROFILE_ENDORSED to
"$who endorsed $proposer's change to $name's profile"
ConfederationKinds.OBJECTION -> {
val reason = ConfederationProfileStatements.parseAnswer(statement)?.reason?.takeIf { it.isNotBlank() }?.let { ": $it" } ?: ""
ChatMessage.TYPE_CONFEDERATION_PROFILE_OBJECTED to if (statement.pubKey == change.proposingGroup) {
"$who withdrew its change to $name's profile$reason"
} else {
"$who objected to $proposer's change to $name's profile$reason"
}
}
else -> return@forEach
}
database.chatMessageDao().upsert(
ChatMessage(
senderPublicKey = statement.pubKey,
isUserMessage = false,
giftWrapPayloadId = null,
marmotGroupEventId = null,
marmotInnerEventId = null,
chatRoomId = roomId,
content = content,
messageType = type,
createdAt = Instant.fromEpochSeconds(statement.createdAt),
frostSigningSessionId = changeId,
)
)
}
}
/**
@@ -57,6 +57,9 @@ object NotificationClassifier {
Line.TYPE_CONFEDERATION_ACCEPTED,
Line.TYPE_CONFEDERATION_REJECTED,
Line.TYPE_CONFEDERATION_FORMED,
// Another group asking this one about the confederation's profile, and the profile it ends in.
Line.TYPE_CONFEDERATION_PROFILE_PROPOSED,
Line.TYPE_CONFEDERATION_PROFILE_PUBLISHED,
Line.TYPE_INBOX_KEY_COMPLETE,
Line.TYPE_MEMBER_ADDED,
Line.TYPE_MEMBER_LEFT,
@@ -102,6 +105,8 @@ object NotificationClassifier {
Line.TYPE_CONFEDERATION_CEREMONY_FAILED,
Line.TYPE_CONFEDERATION_SIGNING_PROPOSED,
Line.TYPE_CONFEDERATION_SIGNING_FAILED,
Line.TYPE_CONFEDERATION_PROFILE_ENDORSED,
Line.TYPE_CONFEDERATION_PROFILE_OBJECTED,
Line.TYPE_INBOX_KEY_STARTED,
Line.TYPE_INBOX_KEY_FAILED,
Line.TYPE_INBOX_ANNOUNCED,
@@ -40,6 +40,7 @@ import androidx.compose.material.icons.filled.CallMerge
import androidx.compose.material.icons.filled.Campaign
import androidx.compose.material.icons.filled.FactCheck
import androidx.compose.material.icons.filled.Draw
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.History
import androidx.compose.material.icons.filled.Hub
@@ -916,6 +917,10 @@ private fun RitualNotice(
ChatMessage.TYPE_CONFEDERATION_FORMED -> Icons.Default.Hub
ChatMessage.TYPE_CONFEDERATION_SIGNING_PROPOSED -> Icons.Default.Draw
ChatMessage.TYPE_CONFEDERATION_SIGNING_FAILED -> Icons.Default.ErrorOutline
ChatMessage.TYPE_CONFEDERATION_PROFILE_PROPOSED -> Icons.Default.Edit
ChatMessage.TYPE_CONFEDERATION_PROFILE_ENDORSED -> Icons.Default.CheckCircle
ChatMessage.TYPE_CONFEDERATION_PROFILE_OBJECTED -> Icons.Default.Block
ChatMessage.TYPE_CONFEDERATION_PROFILE_PUBLISHED -> Icons.Default.Hub
else -> Icons.Default.PanTool