fix: stop message load on channel switch

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-09-28 11:11:33 +02:00
parent 87bedf0553
commit 4de3190507
1 changed files with 4 additions and 1 deletions

View File

@ -101,8 +101,11 @@ class ChannelScreenViewModel @Inject constructor(
}
}
private var loadMessagesJob: Job? = null
fun switchChannel(id: String) {
// Reset state
this.loadMessagesJob?.cancel()
this.channel = RevoltAPI.channelCache[id]
this.items = mutableStateListOf(ChannelScreenItem.Loading)
this.activePane = ChannelScreenActivePane.None
@ -395,7 +398,7 @@ class ChannelScreenViewModel @Inject constructor(
ignoreExisting: Boolean = false
) {
channel?.id?.let { channelId ->
viewModelScope.launch {
loadMessagesJob = viewModelScope.launch {
try {
val messages = arrayListOf<Message>()