Added a control message when the current user accepts a message request

This commit is contained in:
ThomasSession 2024-09-05 13:33:50 +10:00 committed by fanchao
parent 14207c75c7
commit 2c3e73b2a7
5 changed files with 53 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
@ -17,10 +18,12 @@ import network.loki.messenger.libsession_util.util.ExpiryMode
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.messages.ExpirationConfiguration import org.session.libsession.messaging.messages.ExpirationConfiguration
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessages import org.thoughtcrime.securesms.conversation.disappearingmessages.DisappearingMessages
import org.thoughtcrime.securesms.conversation.disappearingmessages.expiryMode import org.thoughtcrime.securesms.conversation.disappearingmessages.expiryMode
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.dependencies.DatabaseComponent import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
@AndroidEntryPoint @AndroidEntryPoint
class ControlMessageView : LinearLayout { class ControlMessageView : LinearLayout {
@ -77,7 +80,18 @@ class ControlMessageView : LinearLayout {
} }
} }
message.isMessageRequestResponse -> { message.isMessageRequestResponse -> {
binding.textView.text = context.getString(R.string.messageRequestsAccepted) val msgRecipient = message.recipient.address.serialize()
val me = TextSecurePreferences.getLocalNumber(context)
binding.textView.text = if(me == msgRecipient) { // you accepted the user's request
val threadRecipient = DatabaseComponent.get(context).threadDatabase().getRecipientForThreadId(message.threadId)
context.getSubbedCharSequence(
R.string.messageRequestYouHaveAccepted,
NAME_KEY to (threadRecipient?.name ?: "")
)
} else { // they accepted your request
context.getString(R.string.messageRequestsAccepted)
}
binding.root.contentDescription = context.getString(R.string.AccessibilityId_message_request_config_message) binding.root.contentDescription = context.getString(R.string.AccessibilityId_message_request_config_message)
} }
message.isCallLog -> { message.isCallLog -> {

View File

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.database
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import network.loki.messenger.R
import java.security.MessageDigest import java.security.MessageDigest
import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.ConfigBase
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_HIDDEN import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_HIDDEN
@ -1448,7 +1449,10 @@ open class Storage(
SSKEnvironment.shared.messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode) SSKEnvironment.shared.messageExpirationManager.maybeStartExpiration(sentTimestamp, senderPublicKey, expiryMode)
} }
override fun insertMessageRequestResponse(response: MessageRequestResponse) { /**
* This will create a control message used to indicate that a contact has accepted our message request
*/
override fun insertMessageRequestResponseFromContact(response: MessageRequestResponse) {
val userPublicKey = getUserPublicKey() val userPublicKey = getUserPublicKey()
val senderPublicKey = response.sender!! val senderPublicKey = response.sender!!
val recipientPublicKey = response.recipient!! val recipientPublicKey = response.recipient!!
@ -1542,6 +1546,34 @@ open class Storage(
} }
} }
/**
* This will create a control message used to indicate that you have accepted a message request
*/
override fun insertMessageRequestResponseFromYou(threadId: Long){
val userPublicKey = getUserPublicKey() ?: return
val mmsDb = DatabaseComponent.get(context).mmsDatabase()
val message = IncomingMediaMessage(
fromSerialized(userPublicKey),
SnodeAPI.nowWithOffset,
-1,
0,
0,
false,
false,
true,
false,
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent(),
Optional.absent()
)
mmsDb.insertSecureDecryptedMessageInbox(message, threadId, runThreadUpdate = false)
}
override fun getRecipientApproved(address: Address): Boolean { override fun getRecipientApproved(address: Address): Boolean {
return DatabaseComponent.get(context).recipientDatabase().getApproved(address) return DatabaseComponent.get(context).recipientDatabase().getApproved(address)
} }

View File

@ -333,6 +333,8 @@ class DefaultConversationRepository @Inject constructor(
MessageSender.send(message, Destination.from(recipient.address), isSyncMessage = recipient.isLocalNumber) MessageSender.send(message, Destination.from(recipient.address), isSyncMessage = recipient.isLocalNumber)
.success { .success {
threadDb.setHasSent(threadId, true) threadDb.setHasSent(threadId, true)
// add a control message for our user
storage.insertMessageRequestResponseFromYou(threadId)
continuation.resume(Result.success(Unit)) continuation.resume(Result.success(Unit))
}.fail { error -> }.fail { error ->
continuation.resume(Result.failure(error)) continuation.resume(Result.failure(error))

View File

@ -202,7 +202,8 @@ interface StorageProtocol {
fun getLastSeen(threadId: Long): Long fun getLastSeen(threadId: Long): Long
fun updateThread(threadId: Long, unarchive: Boolean) fun updateThread(threadId: Long, unarchive: Boolean)
fun insertDataExtractionNotificationMessage(senderPublicKey: String, message: DataExtractionNotificationInfoMessage, sentTimestamp: Long) fun insertDataExtractionNotificationMessage(senderPublicKey: String, message: DataExtractionNotificationInfoMessage, sentTimestamp: Long)
fun insertMessageRequestResponse(response: MessageRequestResponse) fun insertMessageRequestResponseFromContact(response: MessageRequestResponse)
fun insertMessageRequestResponseFromYou(threadId: Long)
fun setRecipientApproved(recipient: Recipient, approved: Boolean) fun setRecipientApproved(recipient: Recipient, approved: Boolean)
fun getRecipientApproved(address: Address): Boolean fun getRecipientApproved(address: Address): Boolean
fun setRecipientApprovedMe(recipient: Recipient, approvedMe: Boolean) fun setRecipientApprovedMe(recipient: Recipient, approvedMe: Boolean)

View File

@ -1,7 +1,6 @@
package org.session.libsession.messaging.sending_receiving package org.session.libsession.messaging.sending_receiving
import android.text.TextUtils import android.text.TextUtils
import network.loki.messenger.libsession_util.ConfigBase
import network.loki.messenger.libsession_util.util.ExpiryMode import network.loki.messenger.libsession_util.util.ExpiryMode
import org.session.libsession.avatars.AvatarHelper import org.session.libsession.avatars.AvatarHelper
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
@ -266,7 +265,7 @@ fun MessageReceiver.handleUnsendRequest(message: UnsendRequest): Long? {
} }
fun handleMessageRequestResponse(message: MessageRequestResponse) { fun handleMessageRequestResponse(message: MessageRequestResponse) {
MessagingModuleConfiguration.shared.storage.insertMessageRequestResponse(message) MessagingModuleConfiguration.shared.storage.insertMessageRequestResponseFromContact(message)
} }
//endregion //endregion