Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fga/experiment await room #6543

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ interface Room {
*/
fun roomSummary(): RoomSummary?

/**
* Suspending version of [roomSummary] method
*/
suspend fun awaitRoomSummary(): RoomSummary?

/**
* Use this room as a Space, if the type is correct.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ interface RoomService {
*/
fun getRoom(roomId: String): Room?

/**
* Suspending version of [getRoom] method.
* @param roomId the roomId to look for.
* @return a room with roomId or null
*/
suspend fun awaitRoom(roomId: String): Room?

/**
* Get a roomSummary from a roomId or a room alias.
* @param roomIdOrAlias the roomId or the alias of a room to look for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ internal class DefaultRoom(
return roomSummaryDataSource.getRoomSummary(roomId)
}

override suspend fun awaitRoomSummary(): RoomSummary? {
return roomSummaryDataSource.awaitRoomSummary(roomId)
}

override fun asSpace(): Space? {
if (roomSummary()?.roomType != RoomType.SPACE) return null
return DefaultSpace(this, roomSummaryDataSource, viaParameterFinder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ internal class DefaultRoomService @Inject constructor(
return roomGetter.getRoom(roomId)
}

override suspend fun awaitRoom(roomId: String): Room? {
return roomGetter.awaitRoom(roomId)
}

override fun getExistingDirectRoomWithUser(otherUserId: String): String? {
return roomGetter.getDirectRoomWith(otherUserId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.matrix.android.sdk.internal.session.room

import io.realm.Realm
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.session.room.Room
import org.matrix.android.sdk.api.session.room.model.Membership
import org.matrix.android.sdk.internal.database.RealmSessionProvider
Expand All @@ -30,13 +32,16 @@ import javax.inject.Inject
internal interface RoomGetter {
fun getRoom(roomId: String): Room?

suspend fun awaitRoom(roomId: String): Room?

fun getDirectRoomWith(otherUserId: String): String?
}

@SessionScope
internal class DefaultRoomGetter @Inject constructor(
private val realmSessionProvider: RealmSessionProvider,
private val roomFactory: RoomFactory
private val roomFactory: RoomFactory,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
) : RoomGetter {

override fun getRoom(roomId: String): Room? {
Expand All @@ -45,6 +50,10 @@ internal class DefaultRoomGetter @Inject constructor(
}
}

override suspend fun awaitRoom(roomId: String) = withContext(coroutineDispatchers.io) {
getRoom(roomId)
}

override fun getDirectRoomWith(otherUserId: String): String? {
return realmSessionProvider.withRealm { realm ->
RoomSummaryEntity.where(realm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ internal class DefaultLeaveRoomTask @Inject constructor(
}

private suspend fun leaveRoom(roomId: String, reason: String?) {
val roomSummary = roomSummaryDataSource.getRoomSummary(roomId)
val roomSummary = roomSummaryDataSource.awaitRoomSummary(roomId)
if (roomSummary?.membership?.isActive() == false) {
Timber.v("Room $roomId is not joined so can't be left")
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import com.zhuinden.monarchy.Monarchy
import io.realm.Realm
import io.realm.RealmQuery
import io.realm.kotlin.where
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.query.QueryStringValue
import org.matrix.android.sdk.api.query.RoomCategoryFilter
import org.matrix.android.sdk.api.query.SpaceFilter
Expand Down Expand Up @@ -58,6 +60,7 @@ internal class RoomSummaryDataSource @Inject constructor(
@SessionDatabase private val monarchy: Monarchy,
private val roomSummaryMapper: RoomSummaryMapper,
private val queryStringValueProcessor: QueryStringValueProcessor,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
) {

fun getRoomSummary(roomIdOrAlias: String): RoomSummary? {
Expand All @@ -75,6 +78,10 @@ internal class RoomSummaryDataSource @Inject constructor(
})
}

suspend fun awaitRoomSummary(roomIdOrAlias: String) = withContext(coroutineDispatchers.io) {
getRoomSummary(roomIdOrAlias)
}

fun getRoomSummaryLive(roomId: String): LiveData<Optional<RoomSummary>> {
val liveData = monarchy.findAllMappedWithChanges(
{ realm -> RoomSummaryEntity.where(realm, roomId).isNotEmpty(RoomSummaryEntityFields.DISPLAY_NAME) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal class DefaultSpace(
) {
// Find best via
val bestVia = viaServers
?: (spaceSummaryDataSource.getRoomSummary(roomId)
?: (spaceSummaryDataSource.awaitRoomSummary(roomId)
?.takeIf { it.joinRules == RoomJoinRules.RESTRICTED }
?.let {
// for restricted room, best to take via from users that can invite in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ internal class DefaultSpaceService @Inject constructor(
// and if client want to bypass, it could use sendStateEvent directly?
if (canonical) {
// check that we can send m.child in the parent room
if (roomSummaryDataSource.getRoomSummary(parentSpaceId)?.membership != Membership.JOIN) {
if (roomSummaryDataSource.awaitRoomSummary(parentSpaceId)?.membership != Membership.JOIN) {
throw UnsupportedOperationException("Cannot add canonical child if not member of parent")
}
val powerLevelsEvent = stateEventDataSource.getStateEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CallUserMapper(private val session: Session, private val protocolsChecker:
protocolsChecker.awaitCheckProtocols()
if (!protocolsChecker.supportVirtualRooms) return
val invitedRoom = session.getRoom(invitedRoomId) ?: return
val inviterId = invitedRoom.roomSummary()?.inviterId ?: return
val inviterId = invitedRoom.awaitRoomSummary()?.inviterId ?: return
val nativeLookup = session.sipNativeLookup(inviterId).firstOrNull() ?: return
if (nativeLookup.fields.containsKey("is_virtual")) {
val nativeUser = nativeLookup.userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.billcarsonfr.jsonviewer.JSonViewerDialog
import org.commonmark.parser.Parser
Expand Down Expand Up @@ -381,18 +382,20 @@ class TimelineFragment @Inject constructor(
)
keyboardStateUtils = KeyboardStateUtils(requireActivity())
lazyLoadedViews.bind(views)
setupToolbar(views.roomToolbar)
.allowBack()
setupRecyclerView()
setupComposer()
setupNotificationView()
setupJumpToReadMarkerView()
setupActiveCallView()
setupJumpToBottomView()
setupEmojiButton()
setupRemoveJitsiWidgetView()
setupVoiceMessageView()
setupLiveLocationIndicator()
viewLifecycleOwner.lifecycleScope.launch {
setupToolbar(views.roomToolbar)
.allowBack()
setupRecyclerView()
setupComposer()
setupNotificationView()
setupJumpToReadMarkerView()
setupActiveCallView()
setupJumpToBottomView()
setupEmojiButton()
setupRemoveJitsiWidgetView()
setupVoiceMessageView()
setupLiveLocationIndicator()
}

views.includeRoomToolbar.roomToolbarContentView.debouncedClicks {
navigator.openRoomProfile(requireActivity(), timelineArgs.roomId)
Expand Down Expand Up @@ -979,16 +982,17 @@ class TimelineFragment @Inject constructor(
private fun setupJumpToBottomView() {
views.jumpToBottomView.visibility = View.INVISIBLE
views.jumpToBottomView.debouncedClicks {
timelineViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState)
views.jumpToBottomView.visibility = View.INVISIBLE
if (!timelineViewModel.timeline.isLive) {
scrollOnNewMessageCallback.forceScrollOnNextUpdate()
timelineViewModel.timeline.restartWithEventId(null)
} else {
layoutManager.scrollToPosition(0)
viewLifecycleOwner.lifecycleScope.launch {
timelineViewModel.handle(RoomDetailAction.ExitTrackingUnreadMessagesState)
views.jumpToBottomView.visibility = View.INVISIBLE
if (!timelineViewModel.timeline.await().isLive) {
scrollOnNewMessageCallback.forceScrollOnNextUpdate()
timelineViewModel.timeline.await().restartWithEventId(null)
} else {
layoutManager.scrollToPosition(0)
}
}
}

jumpToBottomViewVisibilityManager = JumpToBottomViewVisibilityManager(
views.jumpToBottomView,
debouncer,
Expand Down Expand Up @@ -1216,12 +1220,14 @@ class TimelineFragment @Inject constructor(
}

private fun handleSearchAction() {
navigator.openSearch(
context = requireContext(),
roomId = timelineArgs.roomId,
roomDisplayName = timelineViewModel.getRoomSummary()?.displayName,
roomAvatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
)
viewLifecycleOwner.lifecycleScope.launch {
navigator.openSearch(
context = requireContext(),
roomId = timelineArgs.roomId,
roomDisplayName = timelineViewModel.getRoomSummary()?.displayName,
roomAvatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
)
}
}

private fun displayDisabledIntegrationDialog() {
Expand Down Expand Up @@ -1416,9 +1422,9 @@ class TimelineFragment @Inject constructor(

// PRIVATE METHODS *****************************************************************************

private fun setupRecyclerView() {
private suspend fun setupRecyclerView() {
timelineEventController.callback = this
timelineEventController.timeline = timelineViewModel.timeline
timelineEventController.timeline = timelineViewModel.timeline.await()

views.timelineRecyclerView.trackItemsVisibilityChange()
layoutManager = object : LinearLayoutManager(context, RecyclerView.VERTICAL, true) {
Expand Down Expand Up @@ -2421,7 +2427,9 @@ class TimelineFragment @Inject constructor(
views.composerLayout.views.composerEditText.setText(Command.EMOTE.command + " ")
views.composerLayout.views.composerEditText.setSelection(Command.EMOTE.command.length + 1)
} else {
val roomMember = timelineViewModel.getMember(userId)
val roomMember = runBlocking {
timelineViewModel.getMember(userId)
}
// TODO move logic outside of fragment
(roomMember?.displayName ?: userId)
.let { sanitizeDisplayName(it) }
Expand Down Expand Up @@ -2491,18 +2499,21 @@ class TimelineFragment @Inject constructor(
* using the ThreadsActivity.
*/
private fun navigateToThreadTimeline(rootThreadEventId: String, startsThread: Boolean = false, showKeyboard: Boolean = false) {
analyticsTracker.capture(Interaction.Name.MobileRoomThreadSummaryItem.toAnalyticsInteraction())
context?.let {
val roomThreadDetailArgs = ThreadTimelineArgs(
startsThread = startsThread,
roomId = timelineArgs.roomId,
displayName = timelineViewModel.getRoomSummary()?.displayName,
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl,
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
rootThreadEventId = rootThreadEventId,
showKeyboard = showKeyboard
)
navigator.openThread(it, roomThreadDetailArgs)
viewLifecycleOwner.lifecycleScope.launch {
analyticsTracker.capture(Interaction.Name.MobileRoomThreadSummaryItem.toAnalyticsInteraction())
context?.let {
val roomSummary = timelineViewModel.awaitState().asyncRoomSummary()
val roomThreadDetailArgs = ThreadTimelineArgs(
startsThread = startsThread,
roomId = timelineArgs.roomId,
displayName = roomSummary?.displayName,
avatarUrl = roomSummary?.avatarUrl,
roomEncryptionTrustLevel = roomSummary?.roomEncryptionTrustLevel,
rootThreadEventId = rootThreadEventId,
showKeyboard = showKeyboard
)
navigator.openThread(it, roomThreadDetailArgs)
}
}
}

Expand Down Expand Up @@ -2530,15 +2541,18 @@ class TimelineFragment @Inject constructor(
* using the ThreadsActivity.
*/
private fun navigateToThreadList() {
analyticsTracker.capture(Interaction.Name.MobileRoomThreadListButton.toAnalyticsInteraction())
context?.let {
val roomThreadDetailArgs = ThreadTimelineArgs(
roomId = timelineArgs.roomId,
displayName = timelineViewModel.getRoomSummary()?.displayName,
roomEncryptionTrustLevel = timelineViewModel.getRoomSummary()?.roomEncryptionTrustLevel,
avatarUrl = timelineViewModel.getRoomSummary()?.avatarUrl
)
navigator.openThreadList(it, roomThreadDetailArgs)
viewLifecycleOwner.lifecycleScope.launch {
analyticsTracker.capture(Interaction.Name.MobileRoomThreadListButton.toAnalyticsInteraction())
context?.let {
val roomSummary = timelineViewModel.awaitState().asyncRoomSummary()
val roomThreadDetailArgs = ThreadTimelineArgs(
roomId = timelineArgs.roomId,
displayName = roomSummary?.displayName,
roomEncryptionTrustLevel = roomSummary?.roomEncryptionTrustLevel,
avatarUrl = roomSummary?.avatarUrl
)
navigator.openThreadList(it, roomThreadDetailArgs)
}
}
}

Expand Down
Loading