Call transfer: handle unknown person correctly

This commit is contained in:
ganfra 2021-05-28 14:28:32 +02:00
parent 8e8bc0055d
commit 34b012732e
4 changed files with 49 additions and 39 deletions

View File

@ -198,8 +198,13 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
}
is CallState.Connected -> {
if (callState.iceConnectionState == MxPeerConnectionState.CONNECTED) {
if (state.transfereeName.hasValue()) {
views.callActionText.text = getString(R.string.call_transfer_transfer_to_title, state.transfereeName.get())
if (state.transferee !is VectorCallViewState.TransfereeState.NoTransferee) {
val transfereeName = if (state.transferee is VectorCallViewState.TransfereeState.KnownTransferee) {
state.transferee.name
} else {
getString(R.string.call_transfer_unknown_person)
}
views.callActionText.text = getString(R.string.call_transfer_transfer_to_title, transfereeName)
views.callActionText.isVisible = true
views.callActionText.setOnClickListener { callViewModel.handle(VectorCallViewActions.TransferCall) }
views.callStatusText.text = state.formattedDuration
@ -253,10 +258,10 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
state.callInfo.otherUserItem?.let {
val colorFilter = ContextCompat.getColor(this, R.color.bg_call_screen)
avatarRenderer.renderBlur(it, views.bgCallView, sampling = 20, rounded = false, colorFilter = colorFilter)
if (state.transfereeName.hasValue()) {
views.participantNameText.text = getString(R.string.call_transfer_consulting_with, it.getBestName())
} else {
if (state.transferee is VectorCallViewState.TransfereeState.NoTransferee) {
views.participantNameText.text = it.getBestName()
} else {
views.participantNameText.text = getString(R.string.call_transfer_consulting_with, it.getBestName())
}
if (blurAvatar) {
avatarRenderer.renderBlur(it, views.otherMemberAvatar, sampling = 2, rounded = true, colorFilter = colorFilter)

View File

@ -23,8 +23,8 @@ import com.airbnb.mvrx.MvRxViewModelFactory
import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.call.audio.CallAudioManager
@ -39,7 +39,6 @@ import org.matrix.android.sdk.api.session.call.CallState
import org.matrix.android.sdk.api.session.call.MxCall
import org.matrix.android.sdk.api.session.call.MxPeerConnectionState
import org.matrix.android.sdk.api.session.room.model.call.supportCallTransfer
import org.matrix.android.sdk.api.util.Optional
class VectorCallViewModel @AssistedInject constructor(
@Assisted initialState: VectorCallViewState,
@ -109,22 +108,22 @@ class VectorCallViewModel @AssistedInject constructor(
}
}
}
val transfereeName = computeTransfereeNameIfAny(call)
setState {
copy(
callState = Success(callState),
canOpponentBeTransferred = call.capabilities.supportCallTransfer(),
transfereeName = transfereeName
transferee = computeTransfereeState(call)
)
}
}
}
private fun computeTransfereeNameIfAny(call: MxCall): Optional<String> {
val transfereeCall = callManager.getTransfereeForCallId(call.callId) ?: return Optional.empty()
private fun computeTransfereeState(call: MxCall): VectorCallViewState.TransfereeState {
val transfereeCall = callManager.getTransfereeForCallId(call.callId) ?: return VectorCallViewState.TransfereeState.NoTransferee
val transfereeRoom = session.getRoomSummary(transfereeCall.nativeRoomId)
val transfereeName = transfereeRoom?.displayName ?: "Unknown person"
return Optional.from(transfereeName)
return transfereeRoom?.displayName?.let {
VectorCallViewState.TransfereeState.KnownTransferee(it)
} ?: VectorCallViewState.TransfereeState.UnknownTransferee
}
private val currentCallListener = object : WebRtcCallManager.CurrentCallListener {
@ -196,7 +195,7 @@ class VectorCallViewModel @AssistedInject constructor(
formattedDuration = webRtcCall.formattedDuration(),
isHD = webRtcCall.mxCall.isVideoCall && webRtcCall.currentCaptureFormat() is CaptureFormat.HD,
canOpponentBeTransferred = webRtcCall.mxCall.capabilities.supportCallTransfer(),
transfereeName = computeTransfereeNameIfAny(webRtcCall.mxCall)
transferee = computeTransfereeState(webRtcCall.mxCall)
)
}
updateOtherKnownCall(webRtcCall)

View File

@ -22,7 +22,6 @@ import com.airbnb.mvrx.Uninitialized
import im.vector.app.features.call.audio.CallAudioManager
import org.matrix.android.sdk.api.session.call.CallState
import org.matrix.android.sdk.api.util.MatrixItem
import org.matrix.android.sdk.api.util.Optional
data class VectorCallViewState(
val callId: String,
@ -43,9 +42,15 @@ data class VectorCallViewState(
val callInfo: CallInfo = CallInfo(callId),
val formattedDuration: String = "",
val canOpponentBeTransferred: Boolean = false,
val transfereeName: Optional<String> = Optional.empty()
val transferee: TransfereeState = TransfereeState.NoTransferee
) : MvRxState {
sealed class TransfereeState {
object NoTransferee: TransfereeState()
data class KnownTransferee(val name:String): TransfereeState()
object UnknownTransferee: TransfereeState()
}
data class CallInfo(
val callId: String,
val otherUserItem: MatrixItem? = null

View File

@ -3234,6 +3234,7 @@
<string name="call_transfer_users_tab_title">Users</string>
<string name="call_transfer_consulting_with">Consulting with %1$s</string>
<string name="call_transfer_transfer_to_title">Transfer to %1$s</string>
<string name="call_transfer_unknown_person">Unknown person</string>
<string name="re_authentication_activity_title">Re-Authentication Needed</string>
<!-- Note to translators: the translation MUST contain the string "${app_name}", which will be replaced by the application name -->