diff --git a/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt b/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt index 04177bd2b0..e55d70d79c 100644 --- a/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt +++ b/vector/src/main/java/im/vector/app/features/call/lookup/CallUserMapper.kt @@ -32,6 +32,14 @@ class CallUserMapper(private val session: Session, private val protocolsChecker: return virtualRoomEvent?.content?.toModel()?.nativeRoomId } + fun virtualRoomForNativeRoom(roomId: String): String? { + val virtualRoomEvents = session.accountDataService().getRoomAccountDataEvents(setOf(RoomAccountDataTypes.EVENT_TYPE_VIRTUAL_ROOM)) + return virtualRoomEvents.firstOrNull { + val virtualRoomContent = it.content.toModel() + virtualRoomContent?.nativeRoomId == roomId + }?.roomId + } + suspend fun getOrCreateVirtualRoomForRoom(roomId: String, opponentUserId: String): String? { protocolsChecker.awaitCheckProtocols() if (!protocolsChecker.supportVirtualRooms) return null diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index a2041c0a80..2abff09b88 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -49,6 +49,7 @@ import im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrate import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider import im.vector.app.features.home.room.detail.composer.rainbow.RainbowGenerator import im.vector.app.features.home.room.detail.sticker.StickerPickerActionHandler +import im.vector.app.features.home.room.detail.timeline.factory.TimelineFactory import im.vector.app.features.home.room.detail.timeline.helper.RoomSummariesHolder import im.vector.app.features.home.room.detail.timeline.helper.TimelineSettingsFactory import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever @@ -119,7 +120,7 @@ class RoomDetailViewModel @AssistedInject constructor( private val chatEffectManager: ChatEffectManager, private val directRoomHelper: DirectRoomHelper, private val jitsiService: JitsiService, - timelineSettingsFactory: TimelineSettingsFactory + private val timelineFactory: TimelineFactory, ) : VectorViewModel(initialState), Timeline.Listener, ChatEffectManager.Delegate, CallProtocolsChecker.Listener { @@ -127,9 +128,8 @@ class RoomDetailViewModel @AssistedInject constructor( private val eventId = initialState.eventId private val invisibleEventsObservable = BehaviorRelay.create() private val visibleEventsObservable = BehaviorRelay.create() - private val timelineSettings = timelineSettingsFactory.create() private var timelineEvents = PublishRelay.create>() - val timeline = room.createTimeline(eventId, timelineSettings) + val timeline = timelineFactory.createTimeline(viewModelScope, room, eventId) // Same lifecycle than the ViewModel (survive to screen rotation) val previewUrlRetriever = PreviewUrlRetriever(session, viewModelScope) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt new file mode 100644 index 0000000000..c10fd5065a --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/TimelineFactory.kt @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.home.room.detail.timeline.factory + +import im.vector.app.features.call.vectorCallService +import im.vector.app.features.home.room.detail.timeline.helper.TimelineSettingsFactory +import im.vector.app.features.home.room.detail.timeline.merged.MergedTimelines +import kotlinx.coroutines.CoroutineScope +import org.matrix.android.sdk.api.session.Session +import org.matrix.android.sdk.api.session.events.model.EventType +import org.matrix.android.sdk.api.session.room.Room +import org.matrix.android.sdk.api.session.room.timeline.Timeline +import javax.inject.Inject + +private val secondaryTimelineAllowedTypes = listOf( + EventType.CALL_HANGUP, + EventType.CALL_INVITE, + EventType.CALL_REJECT, + EventType.CALL_ANSWER +) + +class TimelineFactory @Inject constructor(private val session: Session, private val timelineSettingsFactory: TimelineSettingsFactory) { + + fun createTimeline(coroutineScope: CoroutineScope, room: Room, eventId: String?): Timeline { + val settings = timelineSettingsFactory.create() + if (!session.vectorCallService.protocolChecker.supportVirtualRooms) { + return room.createTimeline(eventId, settings) + } + val virtualRoomId = session.vectorCallService.userMapper.virtualRoomForNativeRoom(room.roomId) + return if (virtualRoomId == null) { + room.createTimeline(eventId, settings) + } else { + val virtualRoom = session.getRoom(virtualRoomId)!! + MergedTimelines( + coroutineScope, + room.createTimeline(eventId, settings), + secondaryTimelineParams = MergedTimelines.SecondaryTimelineParams( + virtualRoom.createTimeline(null, settings), + shouldFilterTypes = true, + allowedTypes = secondaryTimelineAllowedTypes + ) + ) + } + } +}