From dcbe548891e58752b4622f51cc490e79747e737f Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Mon, 15 May 2023 15:03:44 +1000 Subject: [PATCH] fix: self sync sync message failures for default values --- .../repository/ConversationRepository.kt | 2 +- .../util/ConfigurationMessageUtilities.kt | 2 +- .../securesms/webrtc/CallManager.kt | 20 +++++++++---------- .../messaging/jobs/MessageSendJob.kt | 3 ++- .../sending_receiving/MessageSender.kt | 10 +++++----- .../MessageSenderClosedGroupHandler.kt | 8 +++++--- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt index 76a9039e71..dd013afa74 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/repository/ConversationRepository.kt @@ -281,7 +281,7 @@ class DefaultConversationRepository @Inject constructor( override suspend fun acceptMessageRequest(threadId: Long, recipient: Recipient): ResultOf = suspendCoroutine { continuation -> storage.setRecipientApproved(recipient, true) val message = MessageRequestResponse(true) - MessageSender.send(message, Destination.from(recipient.address)) + MessageSender.send(message, Destination.from(recipient.address), isSyncMessage = recipient.isLocalNumber) .success { threadDb.setHasSent(threadId, true) continuation.resume(ResultOf.Success(Unit)) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt index 64ec59341d..e23fa59f7d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ConfigurationMessageUtilities.kt @@ -98,7 +98,7 @@ object ConfigurationMessageUtilities { ) } val configurationMessage = ConfigurationMessage.getCurrent(contacts) ?: return Promise.ofSuccess(Unit) - val promise = MessageSender.send(configurationMessage, Destination.from(Address.fromSerialized(userPublicKey))) + val promise = MessageSender.send(configurationMessage, Destination.from(Address.fromSerialized(userPublicKey)), isSyncMessage = true) TextSecurePreferences.setLastConfigurationSyncTime(context, System.currentTimeMillis()) return promise } diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index 07e73bedd2..d8694bae55 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -299,7 +299,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va sdpMLineIndexes = sdpMLineIndexes, sdpMids = sdpMids, currentCallId - ), currentRecipient.address) + ), currentRecipient.address, isSyncMessage = currentRecipient.isLocalNumber) } } } @@ -433,7 +433,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va pendingIncomingIceUpdates.clear() val answerMessage = CallMessage.answer(answer.description, callId) Log.i("Loki", "Posting new answer") - MessageSender.sendNonDurably(answerMessage, recipient.address) + MessageSender.sendNonDurably(answerMessage, recipient.address, isSyncMessage = recipient.isLocalNumber) } else { Promise.ofFail(Exception("Couldn't reconnect from current state")) } @@ -477,11 +477,11 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va connection.setLocalDescription(answer) val answerMessage = CallMessage.answer(answer.description, callId) val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key")) - MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress)) + MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress), isSyncMessage = true) val sendAnswerMessage = MessageSender.sendNonDurably(CallMessage.answer( answer.description, callId - ), recipient.address) + ), recipient.address, isSyncMessage = recipient.isLocalNumber) insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_INCOMING, false) @@ -531,13 +531,13 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va Log.d("Loki", "Sending pre-offer") return MessageSender.sendNonDurably(CallMessage.preOffer( callId - ), recipient.address).bind { + ), recipient.address, isSyncMessage = recipient.isLocalNumber).bind { Log.d("Loki", "Sent pre-offer") Log.d("Loki", "Sending offer") MessageSender.sendNonDurably(CallMessage.offer( offer.description, callId - ), recipient.address).success { + ), recipient.address, isSyncMessage = recipient.isLocalNumber).success { Log.d("Loki", "Sent offer") }.fail { Log.e("Loki", "Failed to send offer", it) @@ -551,8 +551,8 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va val recipient = recipient ?: return val userAddress = storage.getUserPublicKey() ?: return stateProcessor.processEvent(Event.DeclineCall) { - MessageSender.sendNonDurably(CallMessage.endCall(callId), Address.fromSerialized(userAddress)) - MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address) + MessageSender.sendNonDurably(CallMessage.endCall(callId), Address.fromSerialized(userAddress), isSyncMessage = true) + MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address, isSyncMessage = recipient.isLocalNumber) insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_MISSED) } } @@ -571,7 +571,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va val buffer = DataChannel.Buffer(ByteBuffer.wrap(HANGUP_JSON.toString().encodeToByteArray()), false) channel.send(buffer) } - MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address) + MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address, isSyncMessage = recipient.isLocalNumber) } } @@ -722,7 +722,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va }) connection.setLocalDescription(offer) - MessageSender.sendNonDurably(CallMessage.offer(offer.description, callId), recipient.address) + MessageSender.sendNonDurably(CallMessage.offer(offer.description, callId), recipient.address, isSyncMessage = recipient.isLocalNumber) } } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageSendJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageSendJob.kt index 850faf5664..2a152d0a01 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageSendJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/MessageSendJob.kt @@ -64,7 +64,8 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job { return } // Wait for all attachments to upload before continuing } - val promise = MessageSender.send(this.message, this.destination).success { + val isSync = destination is Destination.Contact && destination.publicKey == sender + val promise = MessageSender.send(this.message, this.destination, isSync).success { this.handleSuccess(dispatcherName) }.fail { exception -> var logStacktrace = true diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt index 0154a87171..804b2f15be 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt @@ -62,7 +62,7 @@ object MessageSender { } // Convenience - fun send(message: Message, destination: Destination, isSyncMessage: Boolean = false): Promise { + fun send(message: Message, destination: Destination, isSyncMessage: Boolean): Promise { return if (destination is Destination.LegacyOpenGroup || destination is Destination.OpenGroup || destination is Destination.OpenGroupInbox) { sendToOpenGroupDestination(destination, message) } else { @@ -440,17 +440,17 @@ object MessageSender { JobQueue.shared.add(job) } - fun sendNonDurably(message: VisibleMessage, attachments: List, address: Address): Promise { + fun sendNonDurably(message: VisibleMessage, attachments: List, address: Address, isSyncMessage: Boolean): Promise { val attachmentIDs = MessagingModuleConfiguration.shared.messageDataProvider.getAttachmentIDsFor(message.id!!) message.attachmentIDs.addAll(attachmentIDs) - return sendNonDurably(message, address) + return sendNonDurably(message, address, isSyncMessage) } - fun sendNonDurably(message: Message, address: Address): Promise { + fun sendNonDurably(message: Message, address: Address, isSyncMessage: Boolean): Promise { val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address) message.threadID = threadID val destination = Destination.from(address) - return send(message, destination) + return send(message, destination, isSyncMessage) } // Closed groups diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt index 2c01f5f452..2c4088c78e 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSenderClosedGroupHandler.kt @@ -55,11 +55,12 @@ fun MessageSender.create(name: String, members: Collection): Promise