mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
feat: add in activity finish if recipient no longer exists (deleted thread) from sync
This commit is contained in:
parent
61e8935725
commit
aadbcf36d0
@ -241,7 +241,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
}
|
}
|
||||||
} ?: finish()
|
} ?: finish()
|
||||||
}
|
}
|
||||||
viewModelFactory.create(threadId, MessagingModuleConfiguration.shared.getUserED25519KeyPair())
|
viewModelFactory.create(threadId, MessagingModuleConfiguration.shared.getUserED25519KeyPair(), contentResolver)
|
||||||
}
|
}
|
||||||
private var actionMode: ActionMode? = null
|
private var actionMode: ActionMode? = null
|
||||||
private var unreadCount = 0
|
private var unreadCount = 0
|
||||||
@ -665,6 +665,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
if (uiState.isMessageRequestAccepted == true) {
|
if (uiState.isMessageRequestAccepted == true) {
|
||||||
binding?.messageRequestBar?.visibility = View.GONE
|
binding?.messageRequestBar?.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
if (!uiState.conversationExists && !isFinishing) {
|
||||||
|
// Conversation should be deleted now, just go back
|
||||||
|
finish()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package org.thoughtcrime.securesms.conversation.v2
|
package org.thoughtcrime.securesms.conversation.v2
|
||||||
|
|
||||||
|
import android.content.ContentResolver
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import app.cash.copper.flow.observeQuery
|
||||||
import com.goterl.lazysodium.utils.KeyPair
|
import com.goterl.lazysodium.utils.KeyPair
|
||||||
import dagger.assisted.Assisted
|
import dagger.assisted.Assisted
|
||||||
import dagger.assisted.AssistedInject
|
import dagger.assisted.AssistedInject
|
||||||
@ -19,6 +21,7 @@ import org.session.libsession.messaging.utilities.SodiumUtilities
|
|||||||
import org.session.libsession.utilities.recipients.Recipient
|
import org.session.libsession.utilities.recipients.Recipient
|
||||||
import org.session.libsignal.utilities.IdPrefix
|
import org.session.libsignal.utilities.IdPrefix
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
|
import org.thoughtcrime.securesms.database.DatabaseContentProviders
|
||||||
import org.thoughtcrime.securesms.database.Storage
|
import org.thoughtcrime.securesms.database.Storage
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||||
import org.thoughtcrime.securesms.repository.ConversationRepository
|
import org.thoughtcrime.securesms.repository.ConversationRepository
|
||||||
@ -27,11 +30,12 @@ import java.util.UUID
|
|||||||
class ConversationViewModel(
|
class ConversationViewModel(
|
||||||
val threadId: Long,
|
val threadId: Long,
|
||||||
val edKeyPair: KeyPair?,
|
val edKeyPair: KeyPair?,
|
||||||
|
private val contentResolver: ContentResolver,
|
||||||
private val repository: ConversationRepository,
|
private val repository: ConversationRepository,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _uiState = MutableStateFlow(ConversationUiState())
|
private val _uiState = MutableStateFlow(ConversationUiState(conversationExists = recipient != null))
|
||||||
val uiState: StateFlow<ConversationUiState> = _uiState
|
val uiState: StateFlow<ConversationUiState> = _uiState
|
||||||
|
|
||||||
val recipient: Recipient?
|
val recipient: Recipient?
|
||||||
@ -49,6 +53,18 @@ class ConversationViewModel(
|
|||||||
?.let { SessionId(IdPrefix.BLINDED, it) }?.hexString
|
?.let { SessionId(IdPrefix.BLINDED, it) }?.hexString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
contentResolver.observeQuery(DatabaseContentProviders.Conversation.getUriForThread(threadId))
|
||||||
|
.collect {
|
||||||
|
val recipientExists = storage.getRecipientForThread(threadId) != null
|
||||||
|
if (!recipientExists && _uiState.value.conversationExists) {
|
||||||
|
_uiState.update { it.copy(conversationExists = false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun saveDraft(text: String) {
|
fun saveDraft(text: String) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
repository.saveDraft(threadId, text)
|
repository.saveDraft(threadId, text)
|
||||||
@ -172,19 +188,20 @@ class ConversationViewModel(
|
|||||||
|
|
||||||
@dagger.assisted.AssistedFactory
|
@dagger.assisted.AssistedFactory
|
||||||
interface AssistedFactory {
|
interface AssistedFactory {
|
||||||
fun create(threadId: Long, edKeyPair: KeyPair?): Factory
|
fun create(threadId: Long, edKeyPair: KeyPair?, contentResolver: ContentResolver): Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
class Factory @AssistedInject constructor(
|
class Factory @AssistedInject constructor(
|
||||||
@Assisted private val threadId: Long,
|
@Assisted private val threadId: Long,
|
||||||
@Assisted private val edKeyPair: KeyPair?,
|
@Assisted private val edKeyPair: KeyPair?,
|
||||||
|
@Assisted private val contentResolver: ContentResolver,
|
||||||
private val repository: ConversationRepository,
|
private val repository: ConversationRepository,
|
||||||
private val storage: Storage
|
private val storage: Storage
|
||||||
) : ViewModelProvider.Factory {
|
) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||||
return ConversationViewModel(threadId, edKeyPair, repository, storage) as T
|
return ConversationViewModel(threadId, edKeyPair, contentResolver, repository, storage) as T
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,5 +210,6 @@ data class UiMessage(val id: Long, val message: String)
|
|||||||
|
|
||||||
data class ConversationUiState(
|
data class ConversationUiState(
|
||||||
val uiMessages: List<UiMessage> = emptyList(),
|
val uiMessages: List<UiMessage> = emptyList(),
|
||||||
val isMessageRequestAccepted: Boolean? = null
|
val isMessageRequestAccepted: Boolean? = null,
|
||||||
|
val conversationExists: Boolean
|
||||||
)
|
)
|
||||||
|
@ -138,7 +138,7 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
|||||||
namespace,
|
namespace,
|
||||||
updateLatestHash = true,
|
updateLatestHash = true,
|
||||||
updateStoredHashes = true,
|
updateStoredHashes = true,
|
||||||
) // TODO: might not be needed anymore .filter { (_, hash) -> !forConfigObject.currentHashes().contains(hash) }
|
)
|
||||||
|
|
||||||
if (messages.isEmpty()) {
|
if (messages.isEmpty()) {
|
||||||
// no new messages to process
|
// no new messages to process
|
||||||
@ -186,12 +186,6 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
|||||||
requestSparseArray[request.namespace!!] = request
|
requestSparseArray[request.namespace!!] = request
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestSparseArray.size() == 1) {
|
|
||||||
// only one (the personal messages)
|
|
||||||
Log.d("Loki-DBG", "Not building requests for the configs, current config state:")
|
|
||||||
Log.d("Loki-DBG", "${listOf(configFactory.user, configFactory.contacts, configFactory.convoVolatile)}")
|
|
||||||
}
|
|
||||||
|
|
||||||
val requests = requestSparseArray.valueIterator().asSequence().toList()
|
val requests = requestSparseArray.valueIterator().asSequence().toList()
|
||||||
|
|
||||||
SnodeAPI.getRawBatchResponse(snode, userPublicKey, requests).bind { rawResponses ->
|
SnodeAPI.getRawBatchResponse(snode, userPublicKey, requests).bind { rawResponses ->
|
||||||
|
Loading…
Reference in New Issue
Block a user