@@ -11,6 +11,7 @@ import androidx.compose.foundation.text2.input.textAsFlow
1111import androidx.lifecycle.viewModelScope
1212import androidx.paging.PagingData
1313import androidx.paging.flatMap
14+ import androidx.paging.insertSeparators
1415import androidx.paging.map
1516import com.getcode.manager.BottomBarManager
1617import com.getcode.manager.TopBarManager
@@ -28,6 +29,7 @@ import com.getcode.ui.components.chat.messagecontents.MessageControlAction
2829import com.getcode.ui.components.chat.messagecontents.MessageControls
2930import com.getcode.ui.components.chat.utils.ChatItem
3031import com.getcode.ui.components.chat.utils.localizedText
32+ import com.getcode.util.formatDateRelatively
3133import com.getcode.util.resources.ResourceHelper
3234import com.getcode.util.toInstantFromMillis
3335import com.getcode.utils.CurrencyUtils
@@ -49,6 +51,7 @@ import kotlinx.coroutines.flow.filterNotNull
4951import kotlinx.coroutines.flow.flatMapLatest
5052import kotlinx.coroutines.flow.launchIn
5153import kotlinx.coroutines.flow.map
54+ import kotlinx.coroutines.flow.mapLatest
5255import kotlinx.coroutines.flow.mapNotNull
5356import kotlinx.coroutines.flow.onEach
5457import kotlinx.coroutines.launch
@@ -467,6 +470,17 @@ class ConversationViewModel @Inject constructor(
467470 key = contents.hashCode() + message.id.hashCode()
468471 )
469472 }
473+ }.mapLatest { page ->
474+ page.insertSeparators { before: ChatItem .Message ? , after: ChatItem .Message ? ->
475+ val beforeDate = before?.date?.formatDateRelatively()
476+ val afterDate = after?.date?.formatDateRelatively()
477+
478+ if (beforeDate != afterDate) {
479+ beforeDate?.let { ChatItem .Date (it) }
480+ } else {
481+ null
482+ }
483+ }
470484 }
471485
472486 private fun buildSelfDefenseControls (
0 commit comments