feat: add block to the delete all message requests, only if they're not open group inbox contacts

This commit is contained in:
0x330a 2023-05-11 13:40:35 +10:00
parent db18b156a3
commit ad09888c80
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
3 changed files with 9 additions and 6 deletions

View File

@ -48,6 +48,7 @@ class MessageRequestsAdapter(
private fun showPopupMenu(view: MessageRequestView) {
val popupMenu = PopupMenu(ContextThemeWrapper(context, R.style.PopupMenu_MessageRequests), view)
popupMenu.menuInflater.inflate(R.menu.menu_message_request, popupMenu.menu)
popupMenu.menu.findItem(R.id.menu_block_message_request)?.isVisible = !view.thread!!.recipient.isOpenGroupInboxRecipient
popupMenu.setOnMenuItemClickListener { menuItem ->
if (menuItem.itemId == R.id.menu_delete_message_request) {
listener.onDeleteConversationClick(view.thread!!)

View File

@ -25,8 +25,8 @@ class MessageRequestsViewModel @Inject constructor(
repository.deleteMessageRequest(thread)
}
fun clearAllMessageRequests() = viewModelScope.launch {
repository.clearAllMessageRequests()
fun clearAllMessageRequests(block: Boolean) = viewModelScope.launch {
repository.clearAllMessageRequests(block)
}
}

View File

@ -1,6 +1,5 @@
package org.thoughtcrime.securesms.repository
import org.jetbrains.annotations.Contract
import org.session.libsession.database.MessageDataProvider
import org.session.libsession.messaging.messages.Destination
import org.session.libsession.messaging.messages.control.MessageRequestResponse
@ -65,7 +64,7 @@ interface ConversationRepository {
suspend fun deleteMessageRequest(thread: ThreadRecord): ResultOf<Unit>
suspend fun clearAllMessageRequests(): ResultOf<Unit>
suspend fun clearAllMessageRequests(block: Boolean): ResultOf<Unit>
suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): ResultOf<Unit>
@ -131,7 +130,6 @@ class DefaultConversationRepository @Inject constructor(
}
// This assumes that recipient.isContactRecipient is true
@Contract
override fun setBlocked(recipient: Recipient, blocked: Boolean) {
storage.setBlocked(listOf(recipient), blocked)
}
@ -267,10 +265,14 @@ class DefaultConversationRepository @Inject constructor(
return ResultOf.Success(Unit)
}
override suspend fun clearAllMessageRequests(): ResultOf<Unit> {
override suspend fun clearAllMessageRequests(block: Boolean): ResultOf<Unit> {
threadDb.readerFor(threadDb.unapprovedConversationList).use { reader ->
while (reader.next != null) {
deleteMessageRequest(reader.current)
val recipient = reader.current.recipient
if (block && !recipient.isOpenGroupInboxRecipient) {
setBlocked(recipient, true)
}
}
}
return ResultOf.Success(Unit)