Fix expiry mode application to Message

This commit is contained in:
Andrew 2024-02-09 11:13:10 +10:30
parent 181dd15028
commit 637b7f8249
5 changed files with 25 additions and 25 deletions

View File

@ -1617,7 +1617,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
val sentTimestamp = SnodeAPI.nowWithOffset val sentTimestamp = SnodeAPI.nowWithOffset
processMessageRequestApproval() processMessageRequestApproval()
// Create the message // Create the message
val message = VisibleMessage().applyExpiryMode() val message = VisibleMessage().applyExpiryMode(viewModel.threadId)
message.sentTimestamp = sentTimestamp message.sentTimestamp = sentTimestamp
message.text = body message.text = body
val quote = quotedMessage?.let { val quote = quotedMessage?.let {

View File

@ -26,6 +26,7 @@ import org.session.libsession.utilities.Util
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.protos.SignalServiceProtos.CallMessage.Type.ICE_CANDIDATES import org.session.libsignal.protos.SignalServiceProtos.CallMessage.Type.ICE_CANDIDATES
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.AudioDeviceUpdate import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.AudioDeviceUpdate
import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.AudioEnabled import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.AudioEnabled
import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.RecipientUpdate import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.RecipientUpdate
@ -299,6 +300,7 @@ class CallManager(
currentPendings.add(pendingOutgoingIceUpdates.pop()) currentPendings.add(pendingOutgoingIceUpdates.pop())
} }
val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(expectedRecipient)
CallMessage( CallMessage(
ICE_CANDIDATES, ICE_CANDIDATES,
sdps = currentPendings.map(IceCandidate::sdp), sdps = currentPendings.map(IceCandidate::sdp),
@ -306,7 +308,7 @@ class CallManager(
sdpMids = currentPendings.map(IceCandidate::sdpMid), sdpMids = currentPendings.map(IceCandidate::sdpMid),
currentCallId currentCallId
) )
.applyExpiryMode() .applyExpiryMode(thread)
.also { MessageSender.sendNonDurably(it, currentRecipient.address, isSyncMessage = currentRecipient.isLocalNumber) } .also { MessageSender.sendNonDurably(it, currentRecipient.address, isSyncMessage = currentRecipient.isLocalNumber) }
} }
} }
@ -423,6 +425,7 @@ class CallManager(
fun onNewOffer(offer: String, callId: UUID, recipient: Recipient): Promise<Unit, Exception> { fun onNewOffer(offer: String, callId: UUID, recipient: Recipient): Promise<Unit, Exception> {
if (callId != this.callId) return Promise.ofFail(NullPointerException("No callId")) if (callId != this.callId) return Promise.ofFail(NullPointerException("No callId"))
if (recipient != this.recipient) return Promise.ofFail(NullPointerException("No recipient")) if (recipient != this.recipient) return Promise.ofFail(NullPointerException("No recipient"))
val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
val connection = peerConnection ?: return Promise.ofFail(NullPointerException("No peer connection wrapper")) val connection = peerConnection ?: return Promise.ofFail(NullPointerException("No peer connection wrapper"))
@ -435,11 +438,9 @@ class CallManager(
mandatory.add(MediaConstraints.KeyValuePair("IceRestart", "true")) mandatory.add(MediaConstraints.KeyValuePair("IceRestart", "true"))
}) })
connection.setLocalDescription(answer) connection.setLocalDescription(answer)
pendingIncomingIceUpdates.toList().forEach { update -> pendingIncomingIceUpdates.toList().forEach(connection::addIceCandidate)
connection.addIceCandidate(update)
}
pendingIncomingIceUpdates.clear() pendingIncomingIceUpdates.clear()
val answerMessage = CallMessage.answer(answer.description, callId) val answerMessage = CallMessage.answer(answer.description, callId).applyExpiryMode(thread)
Log.i("Loki", "Posting new answer") Log.i("Loki", "Posting new answer")
MessageSender.sendNonDurably(answerMessage, recipient.address, isSyncMessage = recipient.isLocalNumber) MessageSender.sendNonDurably(answerMessage, recipient.address, isSyncMessage = recipient.isLocalNumber)
} else { } else {
@ -483,13 +484,14 @@ class CallManager(
connection.setRemoteDescription(SessionDescription(SessionDescription.Type.OFFER, offer)) connection.setRemoteDescription(SessionDescription(SessionDescription.Type.OFFER, offer))
val answer = connection.createAnswer(MediaConstraints()) val answer = connection.createAnswer(MediaConstraints())
connection.setLocalDescription(answer) connection.setLocalDescription(answer)
val answerMessage = CallMessage.answer(answer.description, callId) val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
val answerMessage = CallMessage.answer(answer.description, callId).applyExpiryMode(thread)
val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key")) val userAddress = storage.getUserPublicKey() ?: return Promise.ofFail(NullPointerException("No user public key"))
MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress), isSyncMessage = true) MessageSender.sendNonDurably(answerMessage, Address.fromSerialized(userAddress), isSyncMessage = true)
val sendAnswerMessage = MessageSender.sendNonDurably(CallMessage.answer( val sendAnswerMessage = MessageSender.sendNonDurably(CallMessage.answer(
answer.description, answer.description,
callId callId
), recipient.address, isSyncMessage = recipient.isLocalNumber) ).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber)
insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_INCOMING, false) insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_INCOMING, false)
@ -537,15 +539,16 @@ class CallManager(
connection.setLocalDescription(offer) connection.setLocalDescription(offer)
Log.d("Loki", "Sending pre-offer") Log.d("Loki", "Sending pre-offer")
val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
return MessageSender.sendNonDurably(CallMessage.preOffer( return MessageSender.sendNonDurably(CallMessage.preOffer(
callId callId
), recipient.address, isSyncMessage = recipient.isLocalNumber).bind { ).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber).bind {
Log.d("Loki", "Sent pre-offer") Log.d("Loki", "Sent pre-offer")
Log.d("Loki", "Sending offer") Log.d("Loki", "Sending offer")
MessageSender.sendNonDurably(CallMessage.offer( MessageSender.sendNonDurably(CallMessage.offer(
offer.description, offer.description,
callId callId
), recipient.address, isSyncMessage = recipient.isLocalNumber).success { ).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber).success {
Log.d("Loki", "Sent offer") Log.d("Loki", "Sent offer")
}.fail { }.fail {
Log.e("Loki", "Failed to send offer", it) Log.e("Loki", "Failed to send offer", it)
@ -559,8 +562,9 @@ class CallManager(
val recipient = recipient ?: return val recipient = recipient ?: return
val userAddress = storage.getUserPublicKey() ?: return val userAddress = storage.getUserPublicKey() ?: return
stateProcessor.processEvent(Event.DeclineCall) { stateProcessor.processEvent(Event.DeclineCall) {
MessageSender.sendNonDurably(CallMessage.endCall(callId), Address.fromSerialized(userAddress), isSyncMessage = true) val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address, isSyncMessage = recipient.isLocalNumber) MessageSender.sendNonDurably(CallMessage.endCall(callId).applyExpiryMode(thread), Address.fromSerialized(userAddress), isSyncMessage = true)
MessageSender.sendNonDurably(CallMessage.endCall(callId).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber)
insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_MISSED) insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_MISSED)
} }
} }
@ -579,7 +583,9 @@ class CallManager(
val buffer = DataChannel.Buffer(ByteBuffer.wrap(HANGUP_JSON.toString().encodeToByteArray()), false) val buffer = DataChannel.Buffer(ByteBuffer.wrap(HANGUP_JSON.toString().encodeToByteArray()), false)
channel.send(buffer) channel.send(buffer)
} }
MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address, isSyncMessage = recipient.isLocalNumber)
val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
MessageSender.sendNonDurably(CallMessage.endCall(callId).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber)
} }
} }
@ -729,8 +735,8 @@ class CallManager(
mandatory.add(MediaConstraints.KeyValuePair("IceRestart", "true")) mandatory.add(MediaConstraints.KeyValuePair("IceRestart", "true"))
}) })
connection.setLocalDescription(offer) connection.setLocalDescription(offer)
val thread = DatabaseComponent.get(context).threadDatabase().getOrCreateThreadIdFor(recipient)
MessageSender.sendNonDurably(CallMessage.offer(offer.description, callId), recipient.address, isSyncMessage = recipient.isLocalNumber) MessageSender.sendNonDurably(CallMessage.offer(offer.description, callId).applyExpiryMode(thread), recipient.address, isSyncMessage = recipient.isLocalNumber)
} }
} }

View File

@ -94,12 +94,6 @@ fun SignalServiceProtos.Content.expiryMode(): ExpiryMode =
/** /**
* Apply ExpiryMode from the current setting. * Apply ExpiryMode from the current setting.
*/ */
inline fun <reified M: Message> M.applyExpiryMode(): M {
val address = Address.fromSerialized(sender ?: return this)
MessagingModuleConfiguration.shared.storage.getThreadId(address)?.let(::applyExpiryMode)
return this
}
inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M { inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M {
val storage = MessagingModuleConfiguration.shared.storage val storage = MessagingModuleConfiguration.shared.storage
expiryMode = storage.getExpirationConfiguration(thread)?.expiryMode?.coerceSendToRead(coerceDisappearAfterSendToRead) ?: ExpiryMode.NONE expiryMode = storage.getExpirationConfiguration(thread)?.expiryMode?.coerceSendToRead(coerceDisappearAfterSendToRead) ?: ExpiryMode.NONE

View File

@ -42,21 +42,21 @@ class CallMessage(): ControlMessage() {
listOf(), listOf(),
listOf(), listOf(),
callId callId
).applyExpiryMode() )
fun preOffer(callId: UUID) = CallMessage(PRE_OFFER, fun preOffer(callId: UUID) = CallMessage(PRE_OFFER,
listOf(), listOf(),
listOf(), listOf(),
listOf(), listOf(),
callId callId
).applyExpiryMode() )
fun offer(sdp: String, callId: UUID) = CallMessage(OFFER, fun offer(sdp: String, callId: UUID) = CallMessage(OFFER,
listOf(sdp), listOf(sdp),
listOf(), listOf(),
listOf(), listOf(),
callId callId
).applyExpiryMode() )
fun endCall(callId: UUID) = CallMessage(END_CALL, emptyList(), emptyList(), emptyList(), callId) fun endCall(callId: UUID) = CallMessage(END_CALL, emptyList(), emptyList(), emptyList(), callId)

View File

@ -471,8 +471,8 @@ object MessageSender {
@JvmStatic @JvmStatic
fun send(message: Message, address: Address) { fun send(message: Message, address: Address) {
message.applyExpiryMode()
val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address) val threadID = MessagingModuleConfiguration.shared.storage.getThreadId(address)
threadID?.let(message::applyExpiryMode)
message.threadID = threadID message.threadID = threadID
val destination = Destination.from(address) val destination = Destination.from(address)
val job = MessageSendJob(message, destination) val job = MessageSendJob(message, destination)