[SES-1002] Synced blind requests (#1303)

* feat: update config to use blinded-msg-requests pr

* feat: add block community message requests bool to protos

* feat: add everything needed for recipientDB to have blocked community requests potentially

* feat: add db migrations

* feat: add sending community block flags and preference options

* feat: add parsing block request flag

* fix: open group message requests were broken anyway

* fix: delete all encoded open group inbox ID bs, fix privacy settings using user config as privacy store

* feat: initial creation sets flag, rename to match libsession implementation value

* fix: recipient blinded checks from open group message for blocking community requests on blinded ID version of recipient, use correct (inverted) values from before for checking polling and empty states etc

* fix: pr comments for view model factory context ref, simplified user config object check for category in PrivacySettingsPreferenceFragment

* fix: pr comments

* fix: migrate some dependencies and functionality out of VM into repository to remove content resolver and context dependecy so tests pass again

* refactor: better naming for hidesInputBar and add more tests for expected recipient view states

* fix: use contact information as opposed to active conversations

* fix: PR comments
This commit is contained in:
0x330a
2023-08-28 09:51:48 +10:00
committed by GitHub
parent f6345c86ce
commit 2466d9b4c0
28 changed files with 522 additions and 157 deletions

View File

@@ -1,42 +1,46 @@
package org.thoughtcrime.securesms.conversation.v2
import com.goterl.lazysodium.utils.KeyPair
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.first
import org.hamcrest.CoreMatchers.endsWith
import org.hamcrest.CoreMatchers.equalTo
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.CoreMatchers.nullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.anyLong
import org.mockito.Mockito.anySet
import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.BaseViewModelTest
import org.thoughtcrime.securesms.database.Storage
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.repository.ConversationRepository
import org.thoughtcrime.securesms.repository.ResultOf
import org.mockito.Mockito.`when` as whenever
class ConversationViewModelTest: BaseViewModelTest() {
private val repository = mock(ConversationRepository::class.java)
private val storage = mock(Storage::class.java)
private val repository = mock<ConversationRepository>()
private val storage = mock<Storage>()
private val threadId = 123L
private val edKeyPair = mock(KeyPair::class.java)
private val edKeyPair = mock<KeyPair>()
private lateinit var recipient: Recipient
private val viewModel: ConversationViewModel by lazy {
ConversationViewModel(threadId, edKeyPair, mock(), repository, storage)
ConversationViewModel(threadId, edKeyPair, repository, storage)
}
@Before
fun setUp() {
recipient = mock(Recipient::class.java)
recipient = mock()
whenever(repository.maybeGetRecipientForThreadId(anyLong())).thenReturn(recipient)
whenever(repository.recipientUpdateFlow(anyLong())).thenReturn(emptyFlow())
}
@Test
@@ -79,7 +83,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
@Test
fun `should delete locally`() {
val message = mock(MessageRecord::class.java)
val message = mock<MessageRecord>()
viewModel.deleteLocally(message)
@@ -88,7 +92,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
@Test
fun `should emit error message on failure to delete a message for everyone`() = runBlockingTest {
val message = mock(MessageRecord::class.java)
val message = mock<MessageRecord>()
val error = Throwable()
whenever(repository.deleteForEveryone(anyLong(), any(), any()))
.thenReturn(ResultOf.Failure(error))
@@ -101,7 +105,7 @@ class ConversationViewModelTest: BaseViewModelTest() {
@Test
fun `should emit error message on failure to delete messages without unsend request`() =
runBlockingTest {
val message = mock(MessageRecord::class.java)
val message = mock<MessageRecord>()
val error = Throwable()
whenever(repository.deleteMessageWithoutUnsendRequest(anyLong(), anySet()))
.thenReturn(ResultOf.Failure(error))
@@ -181,4 +185,30 @@ class ConversationViewModelTest: BaseViewModelTest() {
assertThat(viewModel.uiState.value.uiMessages.size, equalTo(0))
}
@Test
fun `open group recipient should have no blinded recipient`() {
whenever(recipient.isOpenGroupRecipient).thenReturn(true)
whenever(recipient.isOpenGroupOutboxRecipient).thenReturn(false)
whenever(recipient.isOpenGroupInboxRecipient).thenReturn(false)
assertThat(viewModel.blindedRecipient, nullValue())
}
@Test
fun `local recipient should have input and no blinded recipient`() {
whenever(recipient.isLocalNumber).thenReturn(true)
assertThat(viewModel.hidesInputBar(), equalTo(false))
assertThat(viewModel.blindedRecipient, nullValue())
}
@Test
fun `contact recipient should hide input bar if not accepting requests`() {
whenever(recipient.isOpenGroupInboxRecipient).thenReturn(true)
val blinded = mock<Recipient> {
whenever(it.blocksCommunityMessageRequests).thenReturn(true)
}
whenever(repository.maybeGetBlindedRecipient(recipient)).thenReturn(blinded)
assertThat(viewModel.blindedRecipient, notNullValue())
assertThat(viewModel.hidesInputBar(), equalTo(true))
}
}