mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-28 10:47:46 +00:00
Close MessageDetailsActivity when message is deleted
This commit is contained in:
parent
b56c3bd6c5
commit
779101ddc0
@ -5,9 +5,11 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.receiveAsFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import network.loki.messenger.R
|
||||
@ -26,6 +28,7 @@ import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
import org.thoughtcrime.securesms.mms.ImageSlide
|
||||
import org.thoughtcrime.securesms.mms.Slide
|
||||
import org.thoughtcrime.securesms.repository.ConversationRepository
|
||||
import org.thoughtcrime.securesms.ui.GetString
|
||||
import org.thoughtcrime.securesms.ui.TitledText
|
||||
import java.util.Date
|
||||
@ -38,8 +41,11 @@ class MessageDetailsViewModel @Inject constructor(
|
||||
private val lokiMessageDatabase: LokiMessageDatabase,
|
||||
private val mmsSmsDatabase: MmsSmsDatabase,
|
||||
private val threadDb: ThreadDatabase,
|
||||
private val repository: ConversationRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
private var job: Job? = null
|
||||
|
||||
private val state = MutableStateFlow(MessageDetailsState())
|
||||
val stateFlow = state.asStateFlow()
|
||||
|
||||
@ -48,6 +54,8 @@ class MessageDetailsViewModel @Inject constructor(
|
||||
|
||||
var timestamp: Long = 0L
|
||||
set(value) {
|
||||
job?.cancel()
|
||||
|
||||
field = value
|
||||
val record = mmsSmsDatabase.getMessageForTimestamp(timestamp)
|
||||
|
||||
@ -58,6 +66,12 @@ class MessageDetailsViewModel @Inject constructor(
|
||||
|
||||
val mmsRecord = record as? MmsMessageRecord
|
||||
|
||||
job = viewModelScope.launch {
|
||||
repository.changes(record.threadId)
|
||||
.filter { mmsSmsDatabase.getMessageForTimestamp(timestamp) == null }
|
||||
.collect { event.send(Event.Finish) }
|
||||
}
|
||||
|
||||
state.value = record.run {
|
||||
val slides = mmsRecord?.slideDeck?.slides ?: emptyList()
|
||||
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.repository
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import app.cash.copper.Query
|
||||
import app.cash.copper.flow.observeQuery
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@ -45,6 +46,7 @@ import kotlin.coroutines.suspendCoroutine
|
||||
interface ConversationRepository {
|
||||
fun maybeGetRecipientForThreadId(threadId: Long): Recipient?
|
||||
fun maybeGetBlindedRecipient(recipient: Recipient): Recipient?
|
||||
fun changes(threadId: Long): Flow<Query>
|
||||
fun recipientUpdateFlow(threadId: Long): Flow<Recipient?>
|
||||
fun saveDraft(threadId: Long, text: String)
|
||||
fun getDraft(threadId: Long): String?
|
||||
@ -117,6 +119,9 @@ class DefaultConversationRepository @Inject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
override fun changes(threadId: Long): Flow<Query> =
|
||||
contentResolver.observeQuery(DatabaseContentProviders.Conversation.getUriForThread(threadId))
|
||||
|
||||
override fun recipientUpdateFlow(threadId: Long): Flow<Recipient?> {
|
||||
return contentResolver.observeQuery(DatabaseContentProviders.Conversation.getUriForThread(threadId)).map {
|
||||
maybeGetRecipientForThreadId(threadId)
|
||||
|
Loading…
x
Reference in New Issue
Block a user