From 8955049110d5df2e3c8f51e9e2c5dc715d4a091c Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 21 Jul 2021 17:35:08 +0200 Subject: [PATCH] Minor changes after benoits review --- .../sdk/internal/session/call/model/MxCallImpl.kt | 4 ++-- .../java/im/vector/app/core/services/CallService.kt | 12 ++++++------ .../im/vector/app/features/call/webrtc/WebRtcCall.kt | 2 +- .../vector/app/features/call/webrtc/WebRtcCallExt.kt | 9 +++++++-- .../app/features/notifications/NotificationUtils.kt | 6 +++--- vector/src/main/res/values/strings.xml | 10 ++++++++-- 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/model/MxCallImpl.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/model/MxCallImpl.kt index 31f3e114e5..2827b60b34 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/model/MxCallImpl.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/model/MxCallImpl.kt @@ -143,7 +143,7 @@ internal class MxCallImpl( override fun reject() { if (opponentVersion < 1) { Timber.v("Opponent version is less than 1 ($opponentVersion): sending hangup instead of reject") - hangUp() + hangUp(EndCallReason.USER_HANGUP) return } Timber.v("## VOIP reject $callId") @@ -162,7 +162,7 @@ internal class MxCallImpl( CallHangupContent( callId = callId, partyId = ourPartyId, - reason = reason ?: EndCallReason.USER_HANGUP, + reason = reason, version = MxCall.VOIP_PROTO_VERSION.toString() ) .let { createEventAndLocalEcho(type = EventType.CALL_HANGUP, roomId = roomId, content = it.toContent()) } diff --git a/vector/src/main/java/im/vector/app/core/services/CallService.kt b/vector/src/main/java/im/vector/app/core/services/CallService.kt index e5ba2ea10c..2cc33711ea 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallService.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallService.kt @@ -167,7 +167,7 @@ class CallService : VectorService() { } ).apply { viewBinder = IncomingCallAlert.ViewBinder( - matrixItem = callInformation.matrixItem, + matrixItem = callInformation.opponentMatrixItem, avatarRenderer = avatarRenderer, isVideoCall = isVideoCall, onAccept = { showCallScreen(call, VectorCallActivity.INCOMING_ACCEPT) }, @@ -179,7 +179,7 @@ class CallService : VectorService() { alertManager.postVectorAlert(incomingCallAlert) val notification = notificationUtils.buildIncomingCallNotification( call = call, - title = callInformation.matrixItem?.getBestName() ?: callInformation.opponentUserId, + title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId, fromBg = fromBg ) if (knownCalls.isEmpty()) { @@ -235,7 +235,7 @@ class CallService : VectorService() { Timber.v("displayOutgoingCallNotification : display the dedicated notification") val notification = notificationUtils.buildOutgoingRingingCallNotification( call = call, - title = callInformation.matrixItem?.getBestName() ?: callInformation.opponentUserId + title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId ) if (knownCalls.isEmpty()) { startForeground(callId.hashCode(), notification) @@ -259,7 +259,7 @@ class CallService : VectorService() { val callInformation = call.toCallInformation() val notification = notificationUtils.buildPendingCallNotification( call = call, - title = callInformation.matrixItem?.getBestName() ?: callInformation.opponentUserId + title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId ) if (knownCalls.isEmpty()) { startForeground(callId.hashCode(), notification) @@ -293,7 +293,7 @@ class CallService : VectorService() { callId = this.callId, nativeRoomId = this.nativeRoomId, opponentUserId = this.mxCall.opponentUserId, - matrixItem = vectorComponent().activeSessionHolder().getSafeActiveSession()?.let { + opponentMatrixItem = vectorComponent().activeSessionHolder().getSafeActiveSession()?.let { this.getOpponentAsMatrixItem(it) }, isVideoCall = this.mxCall.isVideoCall, @@ -305,7 +305,7 @@ class CallService : VectorService() { val callId: String, val nativeRoomId: String, val opponentUserId: String, - val matrixItem: MatrixItem?, + val opponentMatrixItem: MatrixItem?, val isVideoCall: Boolean, val isOutgoing: Boolean ) diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt index 7ec6715b42..3be942d9c8 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCall.kt @@ -798,7 +798,7 @@ class WebRtcCall( } } - fun endCall(reason: EndCallReason? = null) { + fun endCall(reason: EndCallReason = EndCallReason.USER_HANGUP) { sessionScope?.launch(dispatcher) { if (mxCall.state is CallState.Ended) { return@launch diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt index c99d097707..ef9ef3ef9a 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/WebRtcCallExt.kt @@ -21,7 +21,12 @@ import org.matrix.android.sdk.api.util.MatrixItem import org.matrix.android.sdk.api.util.toMatrixItem fun WebRtcCall.getOpponentAsMatrixItem(session: Session): MatrixItem? { - return session.getRoomSummary(nativeRoomId)?.otherMemberIds?.firstOrNull()?.let { - session.getUser(it)?.toMatrixItem() + return session.getRoomSummary(nativeRoomId)?.let { roomSummary -> + // Fallback to RoomSummary if there is no other member. + if (roomSummary.otherMemberIds.isEmpty()) { + roomSummary.toMatrixItem() + } else { + roomSummary.otherMemberIds.first().let { session.getUser(it)?.toMatrixItem() } + } } } diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index 3c4af56b37..24a64f3cdb 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -479,13 +479,13 @@ class NotificationUtils @Inject constructor(private val context: Context, */ fun buildCallMissedNotification(callInformation: CallService.CallInformation): Notification { val builder = NotificationCompat.Builder(context, SILENT_NOTIFICATION_CHANNEL_ID) - .setContentTitle(callInformation.matrixItem?.getBestName() ?: callInformation.opponentUserId) + .setContentTitle(callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId) .apply { if (callInformation.isVideoCall) { - setContentText(stringProvider.getString(R.string.missed_video_call)) + setContentText(stringProvider.getQuantityString(R.plurals.missed_video_call, 1, 1)) setSmallIcon(R.drawable.ic_missed_video_call) } else { - setContentText(stringProvider.getString(R.string.missed_audio_call)) + setContentText(stringProvider.getQuantityString(R.plurals.missed_audio_call, 1, 1)) setSmallIcon(R.drawable.ic_missed_voice_call) } } diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index f77c940cf9..4cd7f6f6c3 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -727,8 +727,14 @@ Call connected Call connecting… Call ended - Missed audio call - Missed video call + + Missed audio call + %d missed audio calls + + + Missed video call + %d missed video calls + Calling… Incoming Call Incoming Video Call