refactor: handle in-thread call notifications better and replace deny button intent with denyCallIntent instead of hangup

This commit is contained in:
Harris
2021-11-24 11:57:23 +11:00
parent f05487f925
commit d6823d88e6
6 changed files with 29 additions and 25 deletions

View File

@@ -101,7 +101,7 @@ class WebRtcCallActivity: PassphraseRequiredActionBarActivity() {
}
declineCallButton.setOnClickListener {
val declineIntent = WebRtcCallService.hangupIntent(this)
val declineIntent = WebRtcCallService.denyCallIntent(this)
startService(declineIntent)
}

View File

@@ -1,9 +1,7 @@
package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context
import android.content.res.Resources
import android.util.AttributeSet
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
@@ -35,6 +33,9 @@ class ControlMessageView : LinearLayout {
} else if (message.isMediaSavedNotification) {
iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_file_download_white_36dp, context.theme))
iconImageView.visibility = View.VISIBLE
} else if (message.isCallLog) {
iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_baseline_call_24, context.theme))
iconImageView.visibility = View.VISIBLE
}
textView.text = message.getDisplayBody(context)
}

View File

@@ -225,15 +225,15 @@ public interface MmsSmsColumns {
}
public static boolean isIncomingCall(long type) {
return type == INCOMING_CALL_TYPE;
return (type & BASE_TYPE_MASK) == INCOMING_CALL_TYPE;
}
public static boolean isOutgoingCall(long type) {
return type == OUTGOING_CALL_TYPE;
return (type & BASE_TYPE_MASK) == OUTGOING_CALL_TYPE;
}
public static boolean isMissedCall(long type) {
return type == MISSED_CALL_TYPE;
return (type & BASE_TYPE_MASK) == MISSED_CALL_TYPE;
}
public static boolean isGroupUpdate(long type) {

View File

@@ -447,9 +447,8 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
}
private fun handleLocalHangup(intent: Intent) {
val intentRecipient = getRemoteRecipient(intent)
val callId = getCallId(intent)
callManager.handleLocalHangup(intentRecipient, callId)
val intentRecipient = getOptionalRemoteRecipient(intent)
callManager.handleLocalHangup(intentRecipient)
terminate()
}
@@ -574,6 +573,13 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
)
}
private fun getOptionalRemoteRecipient(intent: Intent): Recipient? =
if (intent.hasExtra(EXTRA_RECIPIENT_ADDRESS)) {
getRemoteRecipient(intent)
} else {
null
}
private fun getRemoteRecipient(intent: Intent): Recipient {
val remoteAddress = intent.getParcelableExtra<Address>(EXTRA_RECIPIENT_ADDRESS)
?: throw AssertionError("No recipient in intent!")
@@ -587,9 +593,11 @@ class WebRtcCallService: Service(), PeerConnection.Observer {
}
private fun insertMissedCall(recipient: Recipient, signal: Boolean) {
// TODO
// val messageAndThreadId = DatabaseComponent.get(this).smsDatabase().insertReceivedCall(recipient.address)
// MessageNotifier.updateNotification(this, messageAndThreadId.second, signal)
callManager.insertCallMessage(
threadPublicKey = recipient.address.serialize(),
callMessageType = CallMessageType.CALL_MISSED,
signal = signal
)
}
private fun isIncomingMessageExpired(intent: Intent) =

View File

@@ -9,7 +9,6 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.combine.and
import nl.komponents.kovenant.functional.bind
import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.calls.CallMessageType
@@ -17,10 +16,8 @@ import org.session.libsession.messaging.messages.control.CallMessage
import org.session.libsession.messaging.sending_receiving.MessageSender
import org.session.libsession.utilities.Address
import org.session.libsession.utilities.Debouncer
import org.session.libsession.utilities.TextSecurePreferences
import org.session.libsession.utilities.Util
import org.session.libsession.utilities.recipients.Recipient
import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.protos.SignalServiceProtos.CallMessage.Type.ICE_CANDIDATES
import org.session.libsignal.utilities.Log
import org.thoughtcrime.securesms.webrtc.CallManager.StateEvent.*
@@ -359,7 +356,6 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
this.callId = callId
preOfferCallData = PreOffer(callId, recipient)
postConnectionEvent(CallState.STATE_PRE_OFFER)
insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_INCOMING, sentTimestamp)
}
fun onNewOffer(offer: String, callId: UUID, recipient: Recipient): Promise<Unit, Exception> {
@@ -418,6 +414,8 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
callId
), recipient.address)
insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_INCOMING, false)
while (pendingIncomingIceUpdates.isNotEmpty()) {
val candidate = pendingIncomingIceUpdates.pop() ?: break
connection.addIceCandidate(candidate)
@@ -477,18 +475,15 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
val userAddress = storage.getUserPublicKey() ?: return
MessageSender.sendNonDurably(CallMessage.endCall(callId), Address.fromSerialized(userAddress))
MessageSender.sendNonDurably(CallMessage.endCall(callId), recipient.address)
insertCallMessage(recipient.address.serialize(), CallMessageType.CALL_MISSED)
}
fun handleLocalHangup(intentRecipient: Recipient, intentCallId: UUID) {
fun handleLocalHangup(intentRecipient: Recipient?) {
val recipient = recipient ?: return
val callId = callId ?: return
if (intentCallId != callId) {
Log.w(TAG,"Processing local hangup for non-active ring call ID")
return
}
val currentUserPublicKey = storage.getUserPublicKey()
val sendHangup = intentRecipient == recipient && recipient.address.serialize() != currentUserPublicKey
val sendHangup = intentRecipient == null || (intentRecipient == recipient && recipient.address.serialize() != currentUserPublicKey)
postViewModelState(CallViewModel.State.CALL_DISCONNECTED)
if (sendHangup) {
@@ -496,7 +491,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va
}
}
fun insertCallMessage(threadPublicKey: String, callMessageType: CallMessageType, sentTimestamp: Long = System.currentTimeMillis()) {
fun insertCallMessage(threadPublicKey: String, callMessageType: CallMessageType, signal: Boolean = false, sentTimestamp: Long = System.currentTimeMillis()) {
storage.insertCallMessage(threadPublicKey, callMessageType, sentTimestamp)
}

View File

@@ -111,9 +111,9 @@ object UpdateMessageBuilder {
CallMessageType.CALL_MISSED ->
context.getString(R.string.MessageRecord_missed_call_from, senderName)
CallMessageType.CALL_INCOMING ->
context.getString(R.string.MessageRecord_called_s, senderName)
CallMessageType.CALL_OUTGOING ->
context.getString(R.string.MessageRecord_s_called_you, senderName)
CallMessageType.CALL_OUTGOING ->
context.getString(R.string.MessageRecord_called_s, senderName)
}
}
}