From 370b9dabff4225a812ef8f748904870652fc6464 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 9 Feb 2021 19:42:05 +0100 Subject: [PATCH] VoIP: made some minor changes after review --- .../sdk/api/session/events/model/EventType.kt | 1 + .../room/summary/RoomSummaryConstants.kt | 4 ++++ .../im/vector/app/core/services/CallService.kt | 5 +---- .../call/webrtc/PeerConnectionObserver.kt | 4 ++-- .../app/features/call/webrtc/WebRtcCall.kt | 2 +- .../detail/timeline/factory/CallItemFactory.kt | 9 ++++----- .../timeline/format/NoticeEventFormatter.kt | 10 ++++++++++ .../timeline/item/CallTileTimelineItem.kt | 17 +++++++++++++---- 8 files changed, 36 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt index e6e8107f3c..d79117ad87 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/model/EventType.kt @@ -72,6 +72,7 @@ object EventType { const val CALL_NEGOTIATE = "m.call.negotiate" const val CALL_REJECT = "m.call.reject" const val CALL_HANGUP = "m.call.hangup" + // This type is not processed by the client, just sent to the server const val CALL_REPLACES = "m.call.replaces" // Key share events diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomSummaryConstants.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomSummaryConstants.kt index dcaf5f3276..ef6300eae2 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomSummaryConstants.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/summary/RoomSummaryConstants.kt @@ -20,11 +20,15 @@ import org.matrix.android.sdk.api.session.events.model.EventType object RoomSummaryConstants { + /** + * + */ val PREVIEWABLE_TYPES = listOf( // TODO filter message type (KEY_VERIFICATION_READY, etc.) EventType.MESSAGE, EventType.CALL_INVITE, EventType.CALL_HANGUP, + EventType.CALL_REJECT, EventType.CALL_ANSWER, EventType.ENCRYPTED, EventType.STICKER, 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 2b7d878d49..e9e855e760 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 @@ -33,7 +33,6 @@ import im.vector.app.features.call.telecom.CallConnection import im.vector.app.features.call.webrtc.WebRtcCall import im.vector.app.features.call.webrtc.WebRtcCallManager import im.vector.app.features.home.AvatarRenderer -import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.notifications.NotificationUtils import im.vector.app.features.popup.IncomingCallAlert import im.vector.app.features.popup.PopupAlertManager @@ -160,9 +159,7 @@ class CallService : VectorService() { Timber.v("displayIncomingCallNotification : display the dedicated notification") val incomingCallAlert = IncomingCallAlert(callId, shouldBeDisplayedIn = { activity -> - if (activity is RoomDetailActivity) { - call.roomId != activity.currentRoomId - } else if (activity is VectorCallActivity) { + if (activity is VectorCallActivity) { activity.intent.getParcelableExtra(MvRx.KEY_ARG)?.callId != call.callId } else true } diff --git a/vector/src/main/java/im/vector/app/features/call/webrtc/PeerConnectionObserver.kt b/vector/src/main/java/im/vector/app/features/call/webrtc/PeerConnectionObserver.kt index 9b4adcf955..f14bb2f849 100644 --- a/vector/src/main/java/im/vector/app/features/call/webrtc/PeerConnectionObserver.kt +++ b/vector/src/main/java/im/vector/app/features/call/webrtc/PeerConnectionObserver.kt @@ -129,7 +129,7 @@ class PeerConnectionObserver(private val webRtcCall: WebRtcCall) : PeerConnectio * It is, however, possible that the ICE agent did find compatible connections for some components. */ PeerConnection.IceConnectionState.FAILED -> { - webRtcCall.onRenegationNeeded(restartIce = true) + webRtcCall.onRenegotiationNeeded(restartIce = true) } /** * The ICE agent has finished gathering candidates, has checked all pairs against one another, and has found a connection for all components. @@ -168,7 +168,7 @@ class PeerConnectionObserver(private val webRtcCall: WebRtcCall) : PeerConnectio override fun onRenegotiationNeeded() { Timber.v("## VOIP StreamObserver onRenegotiationNeeded") - webRtcCall.onRenegationNeeded(restartIce = false) + webRtcCall.onRenegotiationNeeded(restartIce = false) } /** 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 ddfea11066..40b4e7469d 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 @@ -190,7 +190,7 @@ class WebRtcCall(val mxCall: MxCall, fun onIceCandidate(iceCandidate: IceCandidate) = iceCandidateSource.onNext(iceCandidate) - fun onRenegationNeeded(restartIce: Boolean) { + fun onRenegotiationNeeded(restartIce: Boolean) { GlobalScope.launch(dispatcher) { if (mxCall.state != CallState.CreateOffer && mxCall.opponentVersion == 0) { Timber.v("Opponent does not support renegotiation: ignoring onRenegotiationNeeded event") diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/CallItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/CallItemFactory.kt index 3992bd7bed..1afaf20b4e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/CallItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/CallItemFactory.kt @@ -26,7 +26,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHold import im.vector.app.features.home.room.detail.timeline.item.CallTileTimelineItem import im.vector.app.features.home.room.detail.timeline.item.CallTileTimelineItem_ import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData -import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel import org.matrix.android.sdk.api.session.room.model.call.CallAnswerContent @@ -57,10 +56,10 @@ class CallItemFactory @Inject constructor( val callSignalingContent = event.getCallSignallingContent() ?: return null val callId = callSignalingContent.callId ?: return null val call = callManager.getCallById(callId) - val callKind = if (call?.mxCall?.isVideoCall.orFalse()) { - CallTileTimelineItem.CallKind.VIDEO - } else { - CallTileTimelineItem.CallKind.AUDIO + val callKind = when { + call == null -> CallTileTimelineItem.CallKind.UNKNOWN + call.mxCall.isVideoCall -> CallTileTimelineItem.CallKind.VIDEO + else -> CallTileTimelineItem.CallKind.AUDIO } return when (event.root.getClearType()) { EventType.CALL_ANSWER -> { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt index f36f91a9d9..6107f4280b 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/format/NoticeEventFormatter.kt @@ -91,7 +91,11 @@ class NoticeEventFormatter @Inject constructor( EventType.CALL_INVITE, EventType.CALL_CANDIDATES, EventType.CALL_HANGUP, + EventType.CALL_REJECT, EventType.CALL_ANSWER -> formatCallEvent(type, timelineEvent.root, timelineEvent.senderInfo.disambiguatedDisplayName) + EventType.CALL_NEGOTIATE, + EventType.CALL_SELECT_ANSWER, + EventType.CALL_REPLACES, EventType.MESSAGE, EventType.REACTION, EventType.KEY_VERIFICATION_START, @@ -179,6 +183,7 @@ class NoticeEventFormatter @Inject constructor( EventType.STATE_ROOM_HISTORY_VISIBILITY -> formatRoomHistoryVisibilityEvent(event, senderName, rs) EventType.CALL_INVITE, EventType.CALL_HANGUP, + EventType.CALL_REJECT, EventType.CALL_ANSWER -> formatCallEvent(type, event, senderName) EventType.STATE_ROOM_TOMBSTONE -> formatRoomTombstoneEvent(event, senderName, rs) else -> { @@ -347,6 +352,11 @@ class NoticeEventFormatter @Inject constructor( } else { sp.getString(R.string.notice_call_candidates, senderName) } + EventType.CALL_REJECT -> if (event.isSentByCurrentUser()) { + sp.getString(R.string.call_tile_you_declined, "") + } else { + sp.getString(R.string.call_tile_other_declined, senderName) + } else -> null } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt index baf4a2b5cd..20d8cb50ef 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/CallTileTimelineItem.kt @@ -35,6 +35,7 @@ import im.vector.app.features.home.room.detail.RoomDetailAction import im.vector.app.features.home.room.detail.timeline.MessageColorProvider import im.vector.app.features.home.room.detail.timeline.TimelineEventController import org.matrix.android.sdk.api.util.MatrixItem +import timber.log.Timber @EpoxyModelClass(layout = R.layout.item_timeline_event_base_state) abstract class CallTileTimelineItem : AbsBaseMessageItem() { @@ -52,11 +53,15 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem { this.marginEnd = leftGuideline } - holder.creatorNameView.text = attributes.userOfInterest.getBestName() attributes.avatarRenderer.render(attributes.userOfInterest, holder.creatorAvatarView) - holder.callKindView.setText(attributes.callKind.title) - holder.callKindView.setLeftDrawable(attributes.callKind.icon) + if (attributes.callKind != CallKind.UNKNOWN) { + holder.callKindView.isVisible = true + holder.callKindView.setText(attributes.callKind.title) + holder.callKindView.setLeftDrawable(attributes.callKind.icon) + } else { + holder.callKindView.isVisible = false + } if (attributes.callStatus == CallStatus.INVITED && !attributes.informationData.sentByMe && attributes.isStillActive) { holder.acceptRejectViewGroup.isVisible = true holder.acceptView.setOnClickListener { @@ -83,6 +88,9 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem { + Timber.w("Shouldn't be in that state") + } } } else { holder.acceptRejectViewGroup.isVisible = false @@ -147,7 +155,8 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem