feat: admin changes for the group's direct messages (group-threshold-ecdh, Phase 10)
A device that sees its member removed as an admin forgets the room's kept conversation keys, its opened messages and its rounds, and says so in the room, once. Partials stop reaching it the moment the removal lands. A promoted admin answers rounds and reads the group's history; a share rotation after a removal leaves every kept key valid, since the group's key never changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7ddc3f3b65
commit
6f33f6f128
4 files changed
+204
-2
No files matched your search
@@ -527,6 +527,12 @@ data class ChatMessage(
|
||||
*/
|
||||
const val TYPE_GROUP_DM_RELAYS_SIGNED = "groupDmRelaysSigned"
|
||||
|
||||
/**
|
||||
* This device forgot the group's direct messages on seeing its member removed as an
|
||||
* admin. docs/group-threshold-ecdh.md, D14.
|
||||
*/
|
||||
const val TYPE_GROUP_DM_FORGOTTEN = "groupDmForgotten"
|
||||
|
||||
/**
|
||||
* Every line the group signed, for the one check the transcript
|
||||
* dispatches on. A type missing from here renders as a chat bubble,
|
||||
@@ -568,6 +574,7 @@ data class ChatMessage(
|
||||
TYPE_LEGACY_GROUP_RELAYS_SIGNED,
|
||||
TYPE_GROUP_POST_SIGNED,
|
||||
TYPE_GROUP_DM_RELAYS_SIGNED,
|
||||
TYPE_GROUP_DM_FORGOTTEN,
|
||||
TYPE_LEGACY_GROUP_SCHEMA_SIGNED,
|
||||
TYPE_LEGACY_GROUP_ENTRY_CURATED,
|
||||
TYPE_WALLET_NOT_TAKEN_PART_IN,
|
||||
|
||||
@@ -171,6 +171,38 @@ object GroupDmReceiver {
|
||||
if (inserted > 0) logger.i { "Filed a message of kind ${rumor.kind} to ${roomId.take(8)}" }
|
||||
}
|
||||
|
||||
/**
|
||||
* A device whose member is no longer one of [chatRoomId]'s admins forgets the room's mail:
|
||||
* its kept conversation keys, what it opened and the rounds in flight, and says so in the
|
||||
* room (D14). Cooperation, not enforcement -- what was read stays read -- and it is the
|
||||
* device's own: the group cut it off from new mail the moment the removal landed (D4).
|
||||
* Returns whether it forgot anything.
|
||||
*/
|
||||
suspend fun forgetIfRemoved(database: GizaDatabase, chatRoomId: HexKey, userPublicKey: HexKey): Boolean {
|
||||
val admins = RoomAdmins.of(database, chatRoomId)?.admins ?: return false
|
||||
if (userPublicKey in admins) return false
|
||||
val dao = database.groupDmDao()
|
||||
val holds = dao.getConversationKeys(chatRoomId).isNotEmpty() || dao.getMessages(chatRoomId).isNotEmpty() ||
|
||||
dao.getAllOpenRounds().any { it.chatRoomId == chatRoomId } || dao.newestWrapCreatedAt(chatRoomId) != null
|
||||
if (!holds) return false
|
||||
dao.wipeRoom(chatRoomId)
|
||||
database.scrubFreedPages()
|
||||
database.chatMessageDao().upsert(
|
||||
mobi.giza.compose.database.model.ChatMessage(
|
||||
senderPublicKey = userPublicKey,
|
||||
isUserMessage = true,
|
||||
giftWrapPayloadId = null,
|
||||
marmotGroupEventId = null,
|
||||
marmotInnerEventId = null,
|
||||
chatRoomId = chatRoomId,
|
||||
content = "You are no longer an admin, so this device forgot the group's direct messages",
|
||||
messageType = mobi.giza.compose.database.model.ChatMessage.TYPE_GROUP_DM_FORGOTTEN,
|
||||
)
|
||||
)
|
||||
logger.i { "Forgot ${chatRoomId.take(8)}'s direct messages: no longer an admin" }
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* What [ledger] waits on: how many more admins have to answer its open round, and which
|
||||
* current admins have not. Read from public rows only, so a screen can show it.
|
||||
|
||||
@@ -200,7 +200,12 @@ object GroupEcdhManager {
|
||||
return
|
||||
}
|
||||
if (innerEvent.kind != GroupEcdhEvents.PARTIALS) return
|
||||
val context = contextFor(database, localChatRoom, userPublicKey, nostrPrivateKey) ?: return
|
||||
val context = contextFor(database, localChatRoom, userPublicKey, nostrPrivateKey)
|
||||
if (context == null) {
|
||||
// Partials still reaching a device whose member was removed: it forgets (D14).
|
||||
GroupDmReceiver.forgetIfRemoved(database, localChatRoom.chatRoom.id, userPublicKey)
|
||||
return
|
||||
}
|
||||
val sender = innerEvent.pubKey
|
||||
if (sender == userPublicKey) return
|
||||
val (senderId, senderHost) = context.admins[sender] ?: return
|
||||
@@ -288,7 +293,9 @@ object GroupEcdhManager {
|
||||
suspend fun sweep(database: GizaDatabase, userPublicKey: HexKey, nostrPrivateKey: ByteArray) {
|
||||
database.chatRoomDao().getChatRoomListByUserPublicKey(userPublicKey).forEach { room ->
|
||||
runCatching {
|
||||
contextFor(database, room, userPublicKey, nostrPrivateKey)?.let { advance(database, it) }
|
||||
val context = contextFor(database, room, userPublicKey, nostrPrivateKey)
|
||||
if (context != null) advance(database, context)
|
||||
else GroupDmReceiver.forgetIfRemoved(database, room.chatRoom.id, userPublicKey)
|
||||
}.onFailure { logger.e("Could not advance the rounds of ${room.chatRoom.id}", it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user