fixed deletion bug, implemented Marcel's suggestions

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
rapterjet2004 2024-10-04 10:17:14 -05:00 committed by backportbot[bot]
parent 2a4910e194
commit 250dbe37e3
3 changed files with 8 additions and 5 deletions

View file

@ -178,12 +178,12 @@ class MessageInputFragment : Fragment() {
}
viewLifecycleOwner.lifecycleScope.launch {
var wasOnline = true
networkMonitor.isOnline.onEach { isOnline ->
var wasOnline: Boolean // TODO maye redo this logic, seems it might be misfiring
networkMonitor.isOnline
.onEach { isOnline ->
wasOnline = !binding.fragmentConnectionLost.isShown
val connectionGained = (!wasOnline && isOnline)
wasOnline = !binding.fragmentMessageInputView.isShown
Log.d(TAG, "isOnline: $isOnline\nwasOnline: $wasOnline\nconnectionGained: $connectionGained")
// delay(2000)
handleMessageQueue(isOnline)
handleUI(isOnline, connectionGained)
}.collect()

View file

@ -142,6 +142,7 @@ class MessageInputViewModel @Inject constructor(
if (isQueueing) {
val tempID = System.currentTimeMillis().toInt()
val qMsg = QueuedMessage(tempID, message, displayName, replyTo, sendWithoutNotification)
messageQueue = dataStore.getMessageQueue(roomToken)
messageQueue.add(qMsg)
dataStore.saveMessageQueue(roomToken, messageQueue)
_messageQueueSizeFlow.update { messageQueue.size }
@ -257,7 +258,7 @@ class MessageInputViewModel @Inject constructor(
val queue = dataStore.getMessageQueue(roomToken)
dataStore.saveMessageQueue(roomToken, null) // empties the queue
while (queue.size > 0) {
val msg = queue.removeFirst()
val msg = queue.removeAt(0)
sendChatMessage(
roomToken,
credentials,

View file

@ -20,6 +20,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject
import javax.inject.Singleton
@ -73,6 +74,7 @@ class NetworkMonitorImpl @Inject constructor(
}
}
}
.distinctUntilChanged()
.flowOn(Dispatchers.IO)
.conflate()