Skip to content

Commit

Permalink
fix chat scroll freezing
Browse files Browse the repository at this point in the history
  • Loading branch information
crackededed committed Sep 7, 2024
1 parent a462f47 commit 4fe1a57
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {
minSdk = 21
targetSdk = 35
versionCode = 121
versionName = "2.34.1"
versionName = "2.34.2"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class ChatFragment : BaseNetworkFragment(), LifecycleListener, MessageClickedDia
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.newMessage.collect {
if (it) {
if (it != null) {
chatView.notifyMessageAdded()
viewModel.newMessage.value = false
viewModel.newMessage.value = null
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class ChatViewModel @Inject constructor(
private var messageLimit = 600
private val _chatMessages = MutableStateFlow<MutableList<ChatMessage>>(Collections.synchronizedList(ArrayList(messageLimit + 1)))
val chatMessages: StateFlow<MutableList<ChatMessage>> = _chatMessages
val newMessage = MutableStateFlow(false)
val newMessage = MutableStateFlow<ChatMessage?>(null)

var chat: ChatController? = null

Expand Down Expand Up @@ -406,13 +406,13 @@ class ChatViewModel @Inject constructor(
}?.let { list.add(it) }
}
if (list.isNotEmpty()) {
_chatMessages.value.addAll(0, list)
_chatMessages.value = mutableListOf<ChatMessage>().apply {
addAll(list)
addAll(_chatMessages.value)
}
if (!scrollDown.value) {
scrollDown.value = true
}
if (!reloadMessages.value) {
reloadMessages.value = true
}
}
} catch (e: Exception) {
Log.e(TAG, "Failed to load recent messages for channel $channelLogin", e)
Expand Down Expand Up @@ -1810,7 +1810,7 @@ class ChatViewModel @Inject constructor(

override fun onMessage(message: ChatMessage) {
_chatMessages.value.add(message)
newMessage.value = true
newMessage.value = message
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ChatView : ConstraintLayout {
}

fun notifyEmotesLoaded() {
adapter.messages?.size?.let { adapter.notifyItemRangeChanged(it - 40, 40) }
adapter.messages?.let { adapter.notifyItemRangeChanged(0, it.size) }
}

fun notifyRoomState(roomState: RoomState) {
Expand Down

0 comments on commit 4fe1a57

Please sign in to comment.