Skip to content

Commit

Permalink
Saves state now
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Sep 12, 2024
1 parent 3b53a0e commit 5efc67d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import com.nextcloud.talk.utils.text.Spans
import com.otaliastudios.autocomplete.Autocomplete
import com.stfalcon.chatkit.commons.models.IMessage
import com.vanniktech.emoji.EmojiPopup
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -141,6 +142,11 @@ class MessageInputFragment : Fragment() {
saveState()
}

override fun onResume() {
super.onResume()
chatActivity.messageInputViewModel.restoreMessageQueue(chatActivity.roomToken)
}

override fun onDestroyView() {
super.onDestroyView()
if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) {
Expand Down Expand Up @@ -178,6 +184,7 @@ class MessageInputFragment : Fragment() {
val connectionGained = (!wasOnline && isOnline)
wasOnline = !binding.fragmentMessageInputView.isShown
Log.d(TAG, "isOnline: $isOnline\nwasOnline: $wasOnline\nconnectionGained: $connectionGained")
delay(500)
handleMessageQueue(isOnline)
handleUI(isOnline, connectionGained)
}.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MessageInputViewModel @Inject constructor(
)

private var isQueueing: Boolean = false
private val messageQueue: MutableList<QueuedMessage> = mutableListOf()
private var messageQueue: MutableList<QueuedMessage> = mutableListOf()

override fun onResume(owner: LifecycleOwner) {
super.onResume(owner)
Expand Down Expand Up @@ -267,4 +267,9 @@ class MessageInputViewModel @Inject constructor(
fun switchToMessageQueue(shouldQueue: Boolean) {
isQueueing = shouldQueue
}

fun restoreMessageQueue(roomToken: String) {
messageQueue = dataStore.getMessageQueue(roomToken)
_messageQueueSizeFlow.tryEmit(messageQueue.size)
}
}

0 comments on commit 5efc67d

Please sign in to comment.