Skip to content

Commit c401035

Browse files
committed
chore(fc): add back date separators to chat
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent bdcc91f commit c401035

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationViewModel.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.foundation.text2.input.textAsFlow
1111
import androidx.lifecycle.viewModelScope
1212
import androidx.paging.PagingData
1313
import androidx.paging.flatMap
14+
import androidx.paging.insertSeparators
1415
import androidx.paging.map
1516
import com.getcode.manager.BottomBarManager
1617
import com.getcode.manager.TopBarManager
@@ -28,6 +29,7 @@ import com.getcode.ui.components.chat.messagecontents.MessageControlAction
2829
import com.getcode.ui.components.chat.messagecontents.MessageControls
2930
import com.getcode.ui.components.chat.utils.ChatItem
3031
import com.getcode.ui.components.chat.utils.localizedText
32+
import com.getcode.util.formatDateRelatively
3133
import com.getcode.util.resources.ResourceHelper
3234
import com.getcode.util.toInstantFromMillis
3335
import com.getcode.utils.CurrencyUtils
@@ -49,6 +51,7 @@ import kotlinx.coroutines.flow.filterNotNull
4951
import kotlinx.coroutines.flow.flatMapLatest
5052
import kotlinx.coroutines.flow.launchIn
5153
import kotlinx.coroutines.flow.map
54+
import kotlinx.coroutines.flow.mapLatest
5255
import kotlinx.coroutines.flow.mapNotNull
5356
import kotlinx.coroutines.flow.onEach
5457
import 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

Comments
 (0)