Skip to content

Commit 805bc80

Browse files
authored
DROID-3596 Chats | Enhancement | Highlight the message you transition to when you click or tap on reply (#2538)
1 parent 22e221d commit 805bc80

File tree

4 files changed

+51
-18
lines changed

4 files changed

+51
-18
lines changed

domain/src/main/java/com/anytypeio/anytype/domain/chats/ChatContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ class ChatContainer @Inject constructor(
201201
messages = messages,
202202
intent = Intent.ScrollToMessage(
203203
id = transform.message,
204-
smooth = true
204+
smooth = true,
205+
highlight = true
205206
),
206207
state = state.state
207208
)
@@ -280,7 +281,6 @@ class ChatContainer @Inject constructor(
280281
logger.logException(e, "DROID-2966 Error while scrolling to bottom")
281282
}
282283
}
283-
284284
ChatStreamState(
285285
messages = messages,
286286
intent = Intent.ScrollToBottom,
@@ -737,9 +737,9 @@ class ChatContainer @Inject constructor(
737737
data class ScrollToMessage(
738738
val id: Id,
739739
val smooth: Boolean = false,
740-
val startOfUnreadMessageSection: Boolean = false
740+
val startOfUnreadMessageSection: Boolean = false,
741+
val highlight: Boolean = false
741742
) : Intent()
742-
data class Highlight(val id: Id) : Intent()
743743
data object ScrollToBottom : Intent()
744744
data object None : Intent()
745745
}

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/ui/ChatBubble.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ fun Bubble(
100100
onViewChatReaction: (String) -> Unit,
101101
onMentionClicked: (Id) -> Unit,
102102
isReadOnly: Boolean = false,
103-
onRequestVideoPlayer: (ChatView.Message.Attachment.Video) -> Unit = {}
103+
onRequestVideoPlayer: (ChatView.Message.Attachment.Video) -> Unit = {},
104+
isHighlighted: Boolean
104105
) {
105106
val haptic = LocalHapticFeedback.current
106107
var showDropdownMenu by remember { mutableStateOf(false) }
@@ -166,6 +167,7 @@ fun Bubble(
166167
Column(
167168
modifier = Modifier
168169
.wrapContentWidth()
170+
.then(if (isHighlighted) Modifier.alpha(0.5f) else Modifier.alpha(1f))
169171
.background(
170172
color = if (!isUserAuthor)
171173
colorResource(R.color.background_primary)

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/ui/ChatPreviews.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ fun ChatPreview() {
9090
onMentionClicked = {},
9191
onScrollToReplyClicked = {},
9292
onShareInviteClicked = {},
93-
onRequestVideoPlayer = {}
93+
onRequestVideoPlayer = {},
94+
highlightedMessageId = null,
95+
onHighlightMessage = {}
9496
)
9597
}
9698

@@ -142,7 +144,9 @@ fun ChatPreview2() {
142144
onMentionClicked = {},
143145
onScrollToReplyClicked = {},
144146
onShareInviteClicked = {},
145-
onRequestVideoPlayer = {}
147+
onRequestVideoPlayer = {},
148+
highlightedMessageId = null,
149+
onHighlightMessage = {}
146150
)
147151
}
148152

@@ -238,7 +242,8 @@ fun BubblePreview() {
238242
onScrollToReplyClicked = {},
239243
onAddReactionClicked = {},
240244
onViewChatReaction = {},
241-
onMentionClicked = {}
245+
onMentionClicked = {},
246+
isHighlighted = false
242247
)
243248
}
244249

@@ -268,7 +273,8 @@ fun BubbleEditedPreview() {
268273
onScrollToReplyClicked = {},
269274
onAddReactionClicked = {},
270275
onViewChatReaction = {},
271-
onMentionClicked = {}
276+
onMentionClicked = {},
277+
isHighlighted = false
272278
)
273279
}
274280

@@ -305,6 +311,7 @@ fun BubbleWithAttachmentPreview() {
305311
onScrollToReplyClicked = {},
306312
onAddReactionClicked = {},
307313
onViewChatReaction = {},
308-
onMentionClicked = {}
314+
onMentionClicked = {},
315+
isHighlighted = false
309316
)
310317
}

feature-chats/src/main/java/com/anytypeio/anytype/feature_chats/ui/ChatScreen.kt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ import com.anytypeio.anytype.feature_chats.presentation.ChatViewModel.MentionPan
9292
import com.anytypeio.anytype.feature_chats.presentation.ChatViewModel.UXCommand
9393
import com.anytypeio.anytype.feature_chats.presentation.ChatViewState
9494
import kotlinx.coroutines.android.awaitFrame
95+
import kotlinx.coroutines.delay
9596
import kotlinx.coroutines.flow.distinctUntilChanged
9697
import kotlinx.coroutines.flow.filterNotNull
9798
import kotlinx.coroutines.flow.first
@@ -414,22 +415,33 @@ fun ChatScreen(
414415

415416
Timber.d("DROID-2966 Render called with state, number of messages: ${messages.size}")
416417

418+
val scope = rememberCoroutineScope()
419+
417420
var text by rememberSaveable(stateSaver = TextFieldValue.Saver) {
418421
mutableStateOf(TextFieldValue())
419422
}
420423

424+
var highlightedMessageId by remember { mutableStateOf<Id?>(null) }
425+
426+
val triggerHighlight: (Id) -> Unit = { id ->
427+
highlightedMessageId = id
428+
scope.launch {
429+
delay(1000)
430+
highlightedMessageId = null
431+
}
432+
}
433+
421434
var spans by remember { mutableStateOf<List<ChatBoxSpan>>(emptyList()) }
422435

423436
val chatBoxFocusRequester = FocusRequester()
424437

425-
val scope = rememberCoroutineScope()
426-
427438
val isPerformingScrollIntent = remember { mutableStateOf(false) }
428439

429440
val offsetPx = with(LocalDensity.current) { 50.dp.toPx().toInt() }
430441

431442
// Applying view model intents
432443
LaunchedEffect(intent) {
444+
Timber.d("DROID-2966 New intent: $intent")
433445
when (intent) {
434446
is ChatContainer.Intent.ScrollToMessage -> {
435447
isPerformingScrollIntent.value = true
@@ -449,6 +461,12 @@ fun ChatScreen(
449461
}
450462
}
451463
awaitFrame()
464+
465+
if (intent.highlight) {
466+
highlightedMessageId = intent.id
467+
delay(500)
468+
highlightedMessageId = null
469+
}
452470
} else {
453471
Timber.d("DROID-2966 COMPOSE Could not find the scrolling target for the intent")
454472
}
@@ -463,9 +481,6 @@ fun ChatScreen(
463481
isPerformingScrollIntent.value = false
464482
onClearIntent()
465483
}
466-
is ChatContainer.Intent.Highlight -> {
467-
// maybe flash background, etc.
468-
}
469484
ChatContainer.Intent.None -> Unit
470485
}
471486
}
@@ -595,7 +610,9 @@ fun ChatScreen(
595610
isReadOnly = isReadOnly,
596611
onShareInviteClicked = onShareInviteClicked,
597612
canCreateInviteLink = canCreateInviteLink,
598-
onRequestVideoPlayer = onRequestVideoPlayer
613+
onRequestVideoPlayer = onRequestVideoPlayer,
614+
highlightedMessageId = highlightedMessageId,
615+
onHighlightMessage = triggerHighlight
599616
)
600617

601618
GoToMentionButton(
@@ -853,10 +870,12 @@ fun Messages(
853870
onMemberIconClicked: (Id?) -> Unit,
854871
onMentionClicked: (Id) -> Unit,
855872
onScrollToReplyClicked: (Id) -> Unit,
873+
onHighlightMessage: (Id) -> Unit,
856874
onShareInviteClicked: () -> Unit,
857875
canCreateInviteLink: Boolean = false,
858876
isReadOnly: Boolean = false,
859-
onRequestVideoPlayer: (ChatView.Message.Attachment.Video) -> Unit
877+
onRequestVideoPlayer: (ChatView.Message.Attachment.Video) -> Unit,
878+
highlightedMessageId: Id?
860879
) {
861880
// Timber.d("DROID-2966 Messages composition: ${messages.map { if (it is ChatView.Message) it.content.msg else it }}")
862881
val scope = rememberCoroutineScope()
@@ -876,6 +895,9 @@ fun Messages(
876895
}
877896
) { idx, msg ->
878897
if (msg is ChatView.Message) {
898+
899+
val isHighlighted = msg.id == highlightedMessageId
900+
879901
if (idx == 0)
880902
Spacer(modifier = Modifier.height(36.dp))
881903
Row(
@@ -935,6 +957,7 @@ fun Messages(
935957
scope.launch {
936958
if (targetIndex != -1 && targetIndex < scrollState.layoutInfo.totalItemsCount) {
937959
scrollState.animateScrollToItem(index = targetIndex)
960+
onHighlightMessage(reply.msg)
938961
} else {
939962
// Defer to VM: message likely not yet in the list (e.g. paged)
940963
onScrollToReplyClicked(reply.msg)
@@ -949,7 +972,8 @@ fun Messages(
949972
},
950973
onMentionClicked = onMentionClicked,
951974
isReadOnly = isReadOnly,
952-
onRequestVideoPlayer = onRequestVideoPlayer
975+
onRequestVideoPlayer = onRequestVideoPlayer,
976+
isHighlighted = isHighlighted
953977
)
954978
}
955979
if (idx == messages.lastIndex) {

0 commit comments

Comments
 (0)