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 Marcel Hibbe
parent 0d9c5bfcb9
commit 9bdaf68232
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 8 additions and 5 deletions

View File

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

View File

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

View File

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