Add ActiveRoomsHolder to manage the active rooms for a session (#4758)
This commit is contained in:
committed by
GitHub
parent
b39100ef6f
commit
c67089edf7
@@ -37,6 +37,7 @@ dependencies {
|
||||
implementation(projects.libraries.roomselect.api)
|
||||
implementation(projects.libraries.uiStrings)
|
||||
implementation(projects.libraries.testtags)
|
||||
implementation(projects.services.appnavstate.api)
|
||||
api(libs.statemachine)
|
||||
api(projects.features.share.api)
|
||||
|
||||
|
||||
@@ -20,9 +20,11 @@ import io.element.android.libraries.architecture.runCatchingUpdatingState
|
||||
import io.element.android.libraries.core.bool.orFalse
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.room.JoinedRoom
|
||||
import io.element.android.libraries.mediaupload.api.MediaPreProcessor
|
||||
import io.element.android.libraries.mediaupload.api.MediaSender
|
||||
import io.element.android.libraries.preferences.api.store.SessionPreferencesStore
|
||||
import io.element.android.services.appnavstate.api.ActiveRoomsHolder
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -33,6 +35,7 @@ class SharePresenter @AssistedInject constructor(
|
||||
private val matrixClient: MatrixClient,
|
||||
private val mediaPreProcessor: MediaPreProcessor,
|
||||
private val sessionPreferencesStore: SessionPreferencesStore,
|
||||
private val activeRoomsHolder: ActiveRoomsHolder,
|
||||
) : Presenter<ShareState> {
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
@@ -59,6 +62,12 @@ class SharePresenter @AssistedInject constructor(
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun getJoinedRoom(roomId: RoomId): JoinedRoom? {
|
||||
return activeRoomsHolder.getActiveRoom(matrixClient.sessionId)
|
||||
?.takeIf { it.roomId == roomId }
|
||||
?: matrixClient.getJoinedRoom(roomId)
|
||||
}
|
||||
|
||||
private fun CoroutineScope.share(
|
||||
intent: Intent,
|
||||
roomIds: List<RoomId>,
|
||||
@@ -72,7 +81,7 @@ class SharePresenter @AssistedInject constructor(
|
||||
} else {
|
||||
roomIds
|
||||
.map { roomId ->
|
||||
val room = matrixClient.getJoinedRoom(roomId) ?: return@map false
|
||||
val room = getJoinedRoom(roomId) ?: return@map false
|
||||
val mediaSender = MediaSender(
|
||||
preProcessor = mediaPreProcessor,
|
||||
room = room,
|
||||
@@ -86,7 +95,11 @@ class SharePresenter @AssistedInject constructor(
|
||||
).isSuccess
|
||||
}
|
||||
.all { it }
|
||||
.also { room.destroy() }
|
||||
.also {
|
||||
if (activeRoomsHolder.getActiveRoomMatching(matrixClient.sessionId, roomId) == null) {
|
||||
room.destroy()
|
||||
}
|
||||
}
|
||||
}
|
||||
.all { it }
|
||||
}
|
||||
@@ -94,7 +107,7 @@ class SharePresenter @AssistedInject constructor(
|
||||
onPlainText = { text ->
|
||||
roomIds
|
||||
.map { roomId ->
|
||||
matrixClient.getJoinedRoom(roomId)?.liveTimeline?.sendMessage(
|
||||
getJoinedRoom(roomId)?.liveTimeline?.sendMessage(
|
||||
body = text,
|
||||
htmlBody = null,
|
||||
intentionalMentions = emptyList(),
|
||||
|
||||
@@ -28,6 +28,7 @@ import io.element.android.libraries.matrix.test.timeline.FakeTimeline
|
||||
import io.element.android.libraries.mediaupload.api.MediaPreProcessor
|
||||
import io.element.android.libraries.mediaupload.test.FakeMediaPreProcessor
|
||||
import io.element.android.libraries.preferences.test.InMemorySessionPreferencesStore
|
||||
import io.element.android.services.appnavstate.api.ActiveRoomsHolder
|
||||
import io.element.android.tests.testutils.WarmUpRule
|
||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
@@ -163,7 +164,8 @@ class SharePresenterTest {
|
||||
intent: Intent = Intent(),
|
||||
shareIntentHandler: ShareIntentHandler = FakeShareIntentHandler(),
|
||||
matrixClient: MatrixClient = FakeMatrixClient(),
|
||||
mediaPreProcessor: MediaPreProcessor = FakeMediaPreProcessor()
|
||||
mediaPreProcessor: MediaPreProcessor = FakeMediaPreProcessor(),
|
||||
activeRoomsHolder: ActiveRoomsHolder = ActiveRoomsHolder(),
|
||||
): SharePresenter {
|
||||
return SharePresenter(
|
||||
intent = intent,
|
||||
@@ -171,7 +173,8 @@ class SharePresenterTest {
|
||||
shareIntentHandler = shareIntentHandler,
|
||||
matrixClient = matrixClient,
|
||||
mediaPreProcessor = mediaPreProcessor,
|
||||
InMemorySessionPreferencesStore(),
|
||||
sessionPreferencesStore = InMemorySessionPreferencesStore(),
|
||||
activeRoomsHolder = activeRoomsHolder,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user