From d307f8f8e3d84c4f6bcd811244b5790a781577f7 Mon Sep 17 00:00:00 2001 From: Barry Deen Date: Wed, 1 Jul 2026 13:07:30 -0400 Subject: [PATCH] fix(dm): place date separators above whole day-group in reversed list The conversation list uses reverseLayout with newest-to-oldest iteration, but emitted each day's date header right after the group's newest message. Because reverseLayout inverts emission order on screen, the divider landed just above the single newest message, pushing all older same-day messages up under the previous day's header. Only the latest message showed below its correct divider. Emit each day's header at the group's older boundary (using a lookahead to the next, older message) so reverseLayout renders it on top of the whole day-group. --- .../com/wisp/app/ui/screen/DmConversationScreen.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/wisp/app/ui/screen/DmConversationScreen.kt b/app/src/main/kotlin/com/wisp/app/ui/screen/DmConversationScreen.kt index f1b5c0f..2199d8a 100644 --- a/app/src/main/kotlin/com/wisp/app/ui/screen/DmConversationScreen.kt +++ b/app/src/main/kotlin/com/wisp/app/ui/screen/DmConversationScreen.kt @@ -394,8 +394,8 @@ fun DmConversationScreen( reverseLayout = true, contentPadding = PaddingValues(bottom = with(density) { bottomBarHeightPx.toDp() }) ) { - var lastDateKey = "" - for (msg in messages.reversed()) { + val ordered = messages.reversed() // newest -> oldest (reverseLayout draws index 0 at bottom) + for ((i, msg) in ordered.withIndex()) { item(key = msg.id) { val icons = msg.relayUrls.map { url -> url to relayInfoRepo?.getIconUrl(url) @@ -422,9 +422,11 @@ fun DmConversationScreen( onOpenEmojiLibrary = onOpenEmojiLibrary ) } + // Emit each day's header at the group's older boundary so reverseLayout + // renders it on top of the whole group (not above just the newest message). + val olderMsg = ordered.getOrNull(i + 1) val dateKey = dayKey(msg.createdAt) - if (dateKey != lastDateKey) { - lastDateKey = dateKey + if (olderMsg == null || dayKey(olderMsg.createdAt) != dateKey) { item(key = "date-$dateKey") { DateHeader(formatDateHeader(msg.createdAt)) }