-
-
Notifications
You must be signed in to change notification settings - Fork 312
Expand file tree
/
Copy pathChatView.kt
More file actions
618 lines (556 loc) · 24.2 KB
/
Copy pathChatView.kt
File metadata and controls
618 lines (556 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
* Nextcloud Talk - Android Client
*
* SPDX-FileCopyrightText: 2017-2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package com.nextcloud.talk.ui.chat
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.animateScrollBy
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nextcloud.talk.R
import com.nextcloud.talk.chat.ui.model.ChatMessageUi
import com.nextcloud.talk.chat.ui.model.MessageStatusIcon
import com.nextcloud.talk.chat.ui.model.MessageTypeContent
import com.nextcloud.talk.chat.viewmodels.ChatViewModel
import com.nextcloud.talk.ui.theme.LocalViewThemeUtils
import com.nextcloud.talk.utils.preview.ComposePreviewUtils
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import java.time.format.DateTimeFormatter
private const val LONG_1000 = 1000L
private const val LOAD_MORE_BUFFER_ITEMS = 5
private const val STICKY_HEADER_HIDE_DELAY_MILLIS = 1200L
private const val PREVIEW_SAMPLE_CHAT_COUNT = 50
private const val PREVIEW_UNREAD_MARKER_OFFSET = 15
private data class QuoteHighlightEvent(val messageId: Int, val nonce: Long)
data class ChatViewState(
val chatItems: List<ChatViewModel.ChatItem>,
val isOneToOneConversation: Boolean,
val conversationThreadId: Long? = null,
val hasChatPermission: Boolean = true,
val initialUnreadCount: Int = 0,
val initialShowUnreadPopup: Boolean = false,
val chatMode: ChatViewModel.ChatMode = ChatViewModel.ChatMode.DEFAULT_MODE,
val highlightedMessageId: Int? = null,
val highlightedSearchTerm: String? = null,
val downloadingFileState: List<String> = listOf()
)
data class ChatViewCallbacks(
val onLoadMore: ((Int, ChatViewModel.LoadMoreDirection) -> Unit?)? = null,
val advanceLocalLastReadMessageIfNeeded: ((Int) -> Unit?)? = null,
val updateRemoteLastReadMessageIfNeeded: (() -> Unit?)? = null,
val onJumpToBottom: (() -> Unit)? = null,
val onLoadQuotedMessageClick: (Int) -> Unit = {},
val messageCallbacks: ChatMessageCallbacks = ChatMessageCallbacks()
)
@Suppress("Detekt.LongMethod", "Detekt.ComplexMethod")
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun ChatView(
state: ChatViewState,
callbacks: ChatViewCallbacks = ChatViewCallbacks(),
listState: LazyListState = rememberLazyListState()
) {
val viewThemeUtils = LocalViewThemeUtils.current
val colorScheme = viewThemeUtils.getColorScheme(LocalContext.current)
val showUnreadPopup = remember { mutableStateOf(state.initialShowUnreadPopup) }
val coroutineScope = rememberCoroutineScope()
val lastNewestIdRef = remember {
object {
var value: Int? = null
}
}
var unreadCount by remember { mutableIntStateOf(state.initialUnreadCount) }
val isDefaultMode = state.chatMode == ChatViewModel.ChatMode.DEFAULT_MODE
val isAtNewest by remember(listState, isDefaultMode) {
derivedStateOf {
isDefaultMode &&
listState.firstVisibleItemIndex == 0 &&
listState.firstVisibleItemScrollOffset == 0
}
}
val isNearNewest by remember(listState, isDefaultMode) {
derivedStateOf {
isDefaultMode &&
listState.firstVisibleItemIndex <= 2
}
}
val showScrollToNewest by remember(isNearNewest, isDefaultMode) {
derivedStateOf { !isNearNewest || !isDefaultMode }
}
val latestChatItems by rememberUpdatedState(state.chatItems)
val latestOnLoadQuotedMessageClick by rememberUpdatedState(callbacks.onLoadQuotedMessageClick)
var quoteHighlightEvent by remember { mutableStateOf<QuoteHighlightEvent?>(null) }
var isNewerBoundaryLoadArmed by remember(state.chatMode, state.highlightedMessageId) {
mutableStateOf(state.chatMode == ChatViewModel.ChatMode.DEFAULT_MODE)
}
val handleQuotedMessageClick: (Int) -> Unit = remember(coroutineScope, listState) {
{ messageId ->
coroutineScope.launch {
val targetIndex = latestChatItems.indexOfFirst { item ->
(item as? ChatViewModel.ChatItem.MessageItem)?.uiMessage?.id == messageId
}
if (targetIndex >= 0) {
val isVisible = listState.layoutInfo.visibleItemsInfo.any { it.index == targetIndex }
if (!isVisible) {
listState.scrollToItem(targetIndex)
listState.centerItemInViewportIfVisible(targetIndex)
}
quoteHighlightEvent = QuoteHighlightEvent(
messageId = messageId,
nonce = System.nanoTime()
)
} else {
latestOnLoadQuotedMessageClick(messageId)
}
}
}
}
// Track newest message and show unread popup
LaunchedEffect(state.chatItems) {
if (state.chatItems.isEmpty()) return@LaunchedEffect
if (!isDefaultMode) return@LaunchedEffect
val newestId = state.chatItems.firstNotNullOfOrNull { it.messageOrNull()?.id }
val previousNewestId = lastNewestIdRef.value
val isNearBottom = listState.firstVisibleItemIndex <= 2
val hasNewMessage = previousNewestId != null &&
newestId != previousNewestId &&
state.chatMode == ChatViewModel.ChatMode.DEFAULT_MODE
if (hasNewMessage) {
if (isNearBottom) {
listState.animateScrollToItem(0)
unreadCount = 0
} else {
unreadCount++
showUnreadPopup.value = true
}
}
lastNewestIdRef.value = newestId
}
// Hide unread popup when user scrolls to newest
LaunchedEffect(listState) {
snapshotFlow { listState.firstVisibleItemIndex }
.map { it <= 2 }
.distinctUntilChanged()
.collect { nearBottom ->
if (nearBottom) {
showUnreadPopup.value = false
unreadCount = 0
}
}
}
// Load older/newer messages when approaching the currently loaded block boundaries.
LaunchedEffect(listState, state.chatItems.size, state.chatMode) {
snapshotFlow {
val layoutInfo = listState.layoutInfo
val firstVisible = layoutInfo.visibleItemsInfo.firstOrNull()?.index ?: 0
val total = layoutInfo.totalItemsCount
val lastVisible = layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0
Triple(firstVisible, lastVisible, total)
}
.distinctUntilChanged()
.collect { (firstVisible, lastVisible, total) ->
if (total == 0) return@collect
val buffer = LOAD_MORE_BUFFER_ITEMS
if (!isNewerBoundaryLoadArmed && firstVisible > buffer) {
isNewerBoundaryLoadArmed = true
}
val shouldLoadOlder = lastVisible >= (total - 1 - buffer)
val shouldLoadNewer =
isNewerBoundaryLoadArmed &&
(
state.chatMode == ChatViewModel.ChatMode.SEARCH_MODE ||
state.chatMode == ChatViewModel.ChatMode.OLD_CHATBLOCK_MODE
) &&
firstVisible <= buffer
val oldestLoadedMessageId = latestChatItems
.asReversed()
.firstNotNullOfOrNull { (it as? ChatViewModel.ChatItem.MessageItem)?.uiMessage?.id }
val newestLoadedMessageId = latestChatItems
.firstNotNullOfOrNull { (it as? ChatViewModel.ChatItem.MessageItem)?.uiMessage?.id }
if (shouldLoadOlder && oldestLoadedMessageId != null) {
callbacks.onLoadMore?.invoke(oldestLoadedMessageId, ChatViewModel.LoadMoreDirection.OLDER)
}
if (shouldLoadNewer && newestLoadedMessageId != null) {
callbacks.onLoadMore?.invoke(newestLoadedMessageId, ChatViewModel.LoadMoreDirection.NEWER)
}
}
}
// Sticky date header
val stickyDateHeaderText by remember(listState, state.chatItems) {
derivedStateOf {
state.chatItems.getOrNull(
listState.layoutInfo.visibleItemsInfo.lastOrNull()?.index ?: 0
)?.let { item ->
when (item) {
is ChatViewModel.ChatItem.MessageItem ->
formatTime(item.uiMessage.timestamp * LONG_1000)
is ChatViewModel.ChatItem.DateHeaderItem ->
formatTime(item.date)
is ChatViewModel.ChatItem.UnreadMessagesMarkerItem ->
formatTime(item.date)
else -> ""
}
} ?: ""
}
}
var stickyDateHeader by remember { mutableStateOf(false) }
LaunchedEffect(listState, isNearNewest) {
if (!isNearNewest) {
callbacks.updateRemoteLastReadMessageIfNeeded?.invoke()
snapshotFlow { listState.isScrollInProgress }
.collectLatest { scrolling ->
if (scrolling) {
stickyDateHeader = true
} else {
delay(STICKY_HEADER_HIDE_DELAY_MILLIS)
stickyDateHeader = false
}
}
} else {
stickyDateHeader = false
}
}
LaunchedEffect(isAtNewest) {
if (!isAtNewest) return@LaunchedEffect
latestChatItems
.getOrNull(listState.firstVisibleItemIndex)
?.let { item ->
if (item is ChatViewModel.ChatItem.MessageItem) {
callbacks.advanceLocalLastReadMessageIfNeeded?.invoke(item.uiMessage.id)
}
}
}
val stickyDateHeaderAlpha by animateFloatAsState(
targetValue = if (stickyDateHeader && stickyDateHeaderText.isNotEmpty()) 1f else 0f,
animationSpec = tween(durationMillis = if (stickyDateHeader) 500 else 1000),
label = ""
)
Box(modifier = Modifier.fillMaxSize()) {
LazyColumn(
state = listState,
reverseLayout = true,
verticalArrangement = Arrangement.spacedBy(2.dp),
contentPadding = PaddingValues(bottom = 20.dp),
modifier = Modifier
.fillMaxSize()
) {
items(
items = state.chatItems,
key = { it.stableKey() }
) { chatItem ->
when (chatItem) {
is ChatViewModel.ChatItem.MessageItem -> {
Box(
modifier = Modifier.padding(
top = if (!chatItem.uiMessage.isGrouped) 4.dp else 0.dp
)
) {
ChatMessageView(
message = chatItem.uiMessage,
highlightTriggerKey = quoteHighlightEvent
?.takeIf { it.messageId == chatItem.uiMessage.id }
?.nonce,
isSelected = state.highlightedMessageId == chatItem.uiMessage.id,
highlightSearchTerm = state.highlightedSearchTerm,
context = ChatMessageContext(
isOneToOneConversation = state.isOneToOneConversation,
conversationThreadId = state.conversationThreadId,
hasChatPermission = state.hasChatPermission,
downloadingFileState = state.downloadingFileState
),
callbacks = ChatMessageCallbacks(
onLongClick = callbacks.messageCallbacks.onLongClick,
onSwipeReply = callbacks.messageCallbacks.onSwipeReply,
onFileClick = callbacks.messageCallbacks.onFileClick,
onPollClick = callbacks.messageCallbacks.onPollClick,
onVoicePlayPauseClick = callbacks.messageCallbacks.onVoicePlayPauseClick,
onVoiceSeek = callbacks.messageCallbacks.onVoiceSeek,
onVoiceSpeedClick = callbacks.messageCallbacks.onVoiceSpeedClick,
onReactionClick = callbacks.messageCallbacks.onReactionClick,
onReactionLongClick = callbacks.messageCallbacks.onReactionLongClick,
onOpenThreadClick = callbacks.messageCallbacks.onOpenThreadClick,
onQuotedMessageClick = handleQuotedMessageClick,
onSystemMessageExpandClick = callbacks.messageCallbacks.onSystemMessageExpandClick
)
)
}
}
is ChatViewModel.ChatItem.DateHeaderItem -> {
Box(modifier = Modifier.padding(top = 6.dp, start = 12.dp, end = 12.dp)) {
DateHeader(chatItem.date)
}
}
is ChatViewModel.ChatItem.UnreadMessagesMarkerItem -> {
Box(modifier = Modifier.padding(top = 6.dp, start = 12.dp, end = 12.dp)) {
UnreadMessagesMarker()
}
}
is ChatViewModel.ChatItem.LoadGapItem -> {
Box(modifier = Modifier.padding(top = 6.dp, start = 12.dp, end = 12.dp)) {
DateHeaderLabel(text = stringResource(R.string.chat_messages_load_gap))
}
}
}
}
}
// Sticky date header
DateHeaderLabel(
text = stickyDateHeaderText,
modifier = Modifier
.align(Alignment.TopCenter)
.padding(top = 2.dp)
.alpha(stickyDateHeaderAlpha)
)
// Unread messages popup
if (showUnreadPopup.value && isDefaultMode) {
UnreadMessagesPopup(
unreadCount = unreadCount,
onClick = {
callbacks.onJumpToBottom?.invoke()
coroutineScope.launch { listState.scrollToItem(0) }
unreadCount = 0
showUnreadPopup.value = false
},
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 20.dp)
)
}
// Floating scroll-to-newest button
AnimatedVisibility(
visible = showScrollToNewest,
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(end = 16.dp, bottom = 24.dp),
enter = fadeIn() + scaleIn(),
exit = fadeOut() + scaleOut()
) {
Surface(
onClick = {
callbacks.onJumpToBottom?.invoke()
coroutineScope.launch { listState.scrollToItem(0) }
unreadCount = 0
},
shape = CircleShape,
color = colorScheme.onSurfaceVariant.copy(alpha = 0.8f),
tonalElevation = 2.dp
) {
Icon(
imageVector = Icons.Default.KeyboardArrowDown,
contentDescription = stringResource(R.string.scroll_to_bottom),
modifier = Modifier
.size(44.dp)
.padding(8.dp),
tint = colorScheme.surfaceContainer.copy(alpha = 0.8f)
)
}
}
}
}
@Composable
fun UnreadMessagesPopup(unreadCount: Int, onClick: () -> Unit, modifier: Modifier = Modifier) {
val viewThemeUtils = LocalViewThemeUtils.current
val colorScheme = viewThemeUtils.getColorScheme(LocalContext.current)
Surface(
onClick = onClick,
shape = RoundedCornerShape(20.dp),
color = colorScheme.secondaryContainer,
tonalElevation = 3.dp,
modifier = modifier
) {
Text(
text = pluralStringResource(R.plurals.nc_new_messages_count, unreadCount, unreadCount),
modifier = Modifier.padding(horizontal = 16.dp, vertical = 10.dp),
color = colorScheme.onSecondaryContainer
)
}
}
@Composable
fun DateHeaderLabel(text: String, modifier: Modifier = Modifier) {
Text(
text = text,
modifier = modifier
.background(MaterialTheme.colorScheme.surfaceContainerHigh, RoundedCornerShape(12.dp))
.padding(horizontal = 12.dp, vertical = 4.dp),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface
)
}
@Composable
fun DateHeader(date: LocalDate) {
val text = when (date) {
LocalDate.now() -> stringResource(R.string.nc_date_header_today)
LocalDate.now().minusDays(1) -> stringResource(R.string.nc_date_header_yesterday)
else -> date.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"))
}
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
DateHeaderLabel(text = text)
}
}
@Composable
fun UnreadMessagesMarker() {
val viewThemeUtils = LocalViewThemeUtils.current
val colorScheme = viewThemeUtils.getColorScheme(LocalContext.current)
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
verticalAlignment = Alignment.CenterVertically
) {
HorizontalDivider(
modifier = Modifier.weight(1f),
color = colorScheme.outlineVariant,
thickness = 1.dp
)
Text(
text = stringResource(R.string.nc_new_messages),
modifier = Modifier.padding(horizontal = 12.dp),
fontSize = 12.sp,
color = colorScheme.onSurfaceVariant
)
HorizontalDivider(
modifier = Modifier.weight(1f),
color = colorScheme.outlineVariant,
thickness = 1.dp
)
}
}
fun formatTime(timestampMillis: Long): String {
val instant = Instant.ofEpochMilli(timestampMillis)
val dateTime = instant.atZone(ZoneId.systemDefault()).toLocalDate()
return formatTime(dateTime)
}
fun formatTime(localDate: LocalDate): String {
val formatter = DateTimeFormatter.ofPattern("MMM dd, yyyy")
val text = when (localDate) {
LocalDate.now() -> "Today"
LocalDate.now().minusDays(1) -> "Yesterday"
else -> localDate.format(formatter)
}
return text
}
private suspend fun LazyListState.centerItemInViewportIfVisible(index: Int) {
val targetItem = layoutInfo.visibleItemsInfo.firstOrNull { it.index == index } ?: return
val viewportCenter = (layoutInfo.viewportStartOffset + layoutInfo.viewportEndOffset) / 2f
val itemCenter = targetItem.offset + (targetItem.size / 2f)
val distanceToCenter = itemCenter - viewportCenter
if (distanceToCenter != 0f) {
animateScrollBy(distanceToCenter)
}
}
@Preview(showBackground = true)
@Composable
private fun ChatViewPreview() {
val context = LocalContext.current
val previewUtils = remember { ComposePreviewUtils.getInstance(context) }
val listState = rememberLazyListState(initialFirstVisibleItemIndex = 12)
CompositionLocalProvider(
LocalViewThemeUtils provides previewUtils.viewThemeUtils
) {
ChatView(
state = ChatViewState(
chatItems = createSampleChatItems(PREVIEW_SAMPLE_CHAT_COUNT),
isOneToOneConversation = false,
initialUnreadCount = 3,
initialShowUnreadPopup = true
),
listState = listState
)
}
}
private fun createSampleChatItems(count: Int): List<ChatViewModel.ChatItem> {
val now = LocalDate.now()
return buildList {
for (i in count downTo 1) {
val date = if (i > count / 2) now else now.minusDays(1)
// Add date header when date changes (since list is reversed, we check if next i is different day)
if (i == count || (i <= count / 2 && (i + 1) > count / 2)) {
add(ChatViewModel.ChatItem.DateHeaderItem(date))
}
// Add unread marker once at a visible position in the preview (initial index 12)
if (i == count - PREVIEW_UNREAD_MARKER_OFFSET) {
add(ChatViewModel.ChatItem.UnreadMessagesMarkerItem(date))
}
val isIncoming = i % 2 == 0
val text = "Sample message #$i"
add(
ChatViewModel.ChatItem.MessageItem(
ChatMessageUi(
id = i,
message = text,
plainMessage = text,
renderMarkdown = false,
actorDisplayName = if (isIncoming) "Alice" else "Me",
isThread = false,
threadTitle = "",
threadReplies = 0,
incoming = isIncoming,
isDeleted = false,
avatarUrl = null,
statusIcon = if (isIncoming) MessageStatusIcon.SENT else MessageStatusIcon.READ,
timestamp = System.currentTimeMillis() / 1000 - (count - i) * 60,
date = date,
content = MessageTypeContent.RegularText
)
)
)
}
}
}