mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-21 15:05:19 +00:00
Added a control message when the current user accepts a message request
This commit is contained in:
parent
14207c75c7
commit
2c3e73b2a7
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.conversation.v2.messages
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
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.messages.ExpirationConfiguration
|
||||
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.expiryMode
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
|
||||
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
|
||||
|
||||
@AndroidEntryPoint
|
||||
class ControlMessageView : LinearLayout {
|
||||
@ -77,7 +80,18 @@ class ControlMessageView : LinearLayout {
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
message.isCallLog -> {
|
||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.database
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import network.loki.messenger.R
|
||||
import java.security.MessageDigest
|
||||
import network.loki.messenger.libsession_util.ConfigBase
|
||||
import network.loki.messenger.libsession_util.ConfigBase.Companion.PRIORITY_HIDDEN
|
||||
@ -1448,7 +1449,10 @@ open class Storage(
|
||||
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 senderPublicKey = response.sender!!
|
||||
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 {
|
||||
return DatabaseComponent.get(context).recipientDatabase().getApproved(address)
|
||||
}
|
||||
|
@ -333,6 +333,8 @@ class DefaultConversationRepository @Inject constructor(
|
||||
MessageSender.send(message, Destination.from(recipient.address), isSyncMessage = recipient.isLocalNumber)
|
||||
.success {
|
||||
threadDb.setHasSent(threadId, true)
|
||||
// add a control message for our user
|
||||
storage.insertMessageRequestResponseFromYou(threadId)
|
||||
continuation.resume(Result.success(Unit))
|
||||
}.fail { error ->
|
||||
continuation.resume(Result.failure(error))
|
||||
|
@ -202,7 +202,8 @@ interface StorageProtocol {
|
||||
fun getLastSeen(threadId: Long): Long
|
||||
fun updateThread(threadId: Long, unarchive: Boolean)
|
||||
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 getRecipientApproved(address: Address): Boolean
|
||||
fun setRecipientApprovedMe(recipient: Recipient, approvedMe: Boolean)
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.session.libsession.messaging.sending_receiving
|
||||
|
||||
import android.text.TextUtils
|
||||
import network.loki.messenger.libsession_util.ConfigBase
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.session.libsession.avatars.AvatarHelper
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
@ -266,7 +265,7 @@ fun MessageReceiver.handleUnsendRequest(message: UnsendRequest): Long? {
|
||||
}
|
||||
|
||||
fun handleMessageRequestResponse(message: MessageRequestResponse) {
|
||||
MessagingModuleConfiguration.shared.storage.insertMessageRequestResponse(message)
|
||||
MessagingModuleConfiguration.shared.storage.insertMessageRequestResponseFromContact(message)
|
||||
}
|
||||
//endregion
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user