Skip to content

Commit 5349ed2

Browse files
committed
chore(fc): attempt to fix state issues in typing indicator
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent e2a88b1 commit 5349ed2

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

services/flipchat/chat/src/main/kotlin/xyz/flipchat/services/internal/network/repository/messaging/RealMessagingRepository.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,21 @@ internal class RealMessagingRepository @Inject constructor(
5454
// Process new typing updates (excluding stops/timeouts)
5555
val newTypingUpdates = updates.filter {
5656
it.state != TypingState.Stopped && it.state != TypingState.TimedOut
57-
}.toSet()
57+
}
58+
59+
// Update existing users and collect truly new users
60+
val updatedList = afterRemovals.map { existing ->
61+
// If there's a new update for this user, use it instead
62+
newTypingUpdates.find { it.userId == existing.userId } ?: existing
63+
}
5864

59-
// Get new updates that aren't in the current state
65+
// Get users who are completely new (not in current state)
6066
val trulyNewUpdates = newTypingUpdates.filter { update ->
6167
afterRemovals.none { it.userId == update.userId }
6268
}
6369

64-
// Combine: keep existing users in their original order at the start,
65-
// then append truly new updates, while updates for existing users
66-
// are already handled by favoring the incoming update via filtering
67-
typingState.value = (afterRemovals + trulyNewUpdates)
70+
// Combine: updated existing users (in original order) + truly new users
71+
typingState.value = updatedList + trulyNewUpdates
6872
}
6973

7074
override suspend fun getMessages(
@@ -165,7 +169,6 @@ internal class RealMessagingRepository @Inject constructor(
165169
}
166170
is MessageStreamUpdate.Pointers -> Unit
167171
is MessageStreamUpdate.Typing -> {
168-
println("typing update=${update.data}")
169172
handleTypingUpdates(update.data.map { typingMapper.map(it) })
170173
}
171174
}

ui/components/src/main/kotlin/com/getcode/ui/components/chat/TypingIndicator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private fun AvatarRow(
9292
horizontalArrangement = Arrangement.spacedBy(-overlap)
9393
) {
9494
items(
95-
items = userImages.take(maxAvatars).reversed(),
95+
items = userImages.take(maxAvatars),
9696
key = { it.hashCode() }
9797
) { image ->
9898
val index = userImages.take(maxAvatars).indexOf(image)

0 commit comments

Comments
 (0)