Merge branch 'mantra' into claude/key-recovery-functionality-00e269

This commit is contained in:
Kgothatso Ngako
2026-09-08 09:27:48 +02:00
3 changed files with 62 additions and 3 deletions

View File

@@ -8,14 +8,35 @@ import press.mantra.compose.database.model.ChatMessage
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import kotlinx.coroutines.flow.Flow
/**
* The room's transcript, newest first -- the order the feed's `reverseLayout` draws from the
* bottom up, so the first row is the line sitting above the composer.
*
* `id DESC` is not decoration. [press.mantra.compose.database.converters.MantraConverters]
* stores an `Instant` as epoch seconds, so lines written inside one second tie: a ceremony
* puts a dozen into a room faster than that, and a request with the answer it triggers
* routinely lands inside one. `createdAt DESC` alone left those to whatever order the sorter
* produced -- the rows as scanned, which under a descending query drew a same-second burst
* backwards, and is free to change under a new index or a different plan, swapping two lines
* in a transcript the user has already read.
*
* The key [ChatRoomDao] already breaks its last-message tie on, which is what makes the chat
* list's preview and the bottom of the room it opens name the same line.
*
* One constant for both reads because they are the same list: the snapshot a screen loads
* with and the flow it then follows must not order it differently.
*/
private const val TRANSCRIPT =
"SELECT * FROM ChatMessage WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC, id DESC"
@Dao
interface ChatMessageDao {
@Transaction
@Query("SELECT * FROM ChatMessage WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
@Query(TRANSCRIPT)
fun observeChatMessagesByChatRoomId(chatRoomId: String): Flow<List<press.mantra.compose.database.model.intermdiate.LocalChatMessage>>
@Transaction
@Query("SELECT * FROM ChatMessage WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
@Query(TRANSCRIPT)
suspend fun getChatMessagesByChatRoomId(chatRoomId: String): List<press.mantra.compose.database.model.intermdiate.LocalChatMessage>
@Query("SELECT * FROM ChatMessage WHERE giftWrapPayloadId = :giftWrapPayloadId ORDER BY createdAt DESC")