mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-24 16:51:07 +01:00
Use ActiveSessionHolder in stop live use case
This commit is contained in:
parent
519d43ceb7
commit
945026730c
@ -44,11 +44,11 @@ class ActiveSessionHolder @Inject constructor(
|
||||
private val guardServiceStarter: GuardServiceStarter
|
||||
) {
|
||||
|
||||
private var activeSession: AtomicReference<Session?> = AtomicReference()
|
||||
private var activeSessionReference: AtomicReference<Session?> = AtomicReference()
|
||||
|
||||
fun setActiveSession(session: Session) {
|
||||
Timber.w("setActiveSession of ${session.myUserId}")
|
||||
activeSession.set(session)
|
||||
activeSessionReference.set(session)
|
||||
activeSessionDataSource.post(Option.just(session))
|
||||
|
||||
keyRequestHandler.start(session)
|
||||
@ -68,7 +68,7 @@ class ActiveSessionHolder @Inject constructor(
|
||||
it.removeListener(sessionListener)
|
||||
}
|
||||
|
||||
activeSession.set(null)
|
||||
activeSessionReference.set(null)
|
||||
activeSessionDataSource.post(Option.empty())
|
||||
|
||||
keyRequestHandler.stop()
|
||||
@ -80,15 +80,15 @@ class ActiveSessionHolder @Inject constructor(
|
||||
}
|
||||
|
||||
fun hasActiveSession(): Boolean {
|
||||
return activeSession.get() != null
|
||||
return activeSessionReference.get() != null
|
||||
}
|
||||
|
||||
fun getSafeActiveSession(): Session? {
|
||||
return activeSession.get()
|
||||
return activeSessionReference.get()
|
||||
}
|
||||
|
||||
fun getActiveSession(): Session {
|
||||
return activeSession.get()
|
||||
return activeSessionReference.get()
|
||||
?: throw IllegalStateException("You should authenticate before using this")
|
||||
}
|
||||
|
||||
|
@ -16,21 +16,22 @@
|
||||
|
||||
package im.vector.app.features.location.live
|
||||
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import org.matrix.android.sdk.api.session.getRoom
|
||||
import org.matrix.android.sdk.api.session.room.location.UpdateLiveLocationShareResult
|
||||
import javax.inject.Inject
|
||||
|
||||
class StopLiveLocationShareUseCase @Inject constructor(
|
||||
private val session: Session
|
||||
private val activeSessionHolder: ActiveSessionHolder
|
||||
) {
|
||||
|
||||
suspend fun execute(roomId: String): UpdateLiveLocationShareResult? {
|
||||
return sendStoppedBeaconInfo(session, roomId)
|
||||
return sendStoppedBeaconInfo(roomId)
|
||||
}
|
||||
|
||||
private suspend fun sendStoppedBeaconInfo(session: Session, roomId: String): UpdateLiveLocationShareResult? {
|
||||
return session.getRoom(roomId)
|
||||
private suspend fun sendStoppedBeaconInfo(roomId: String): UpdateLiveLocationShareResult? {
|
||||
return activeSessionHolder.getActiveSession()
|
||||
.getRoom(roomId)
|
||||
?.locationSharingService()
|
||||
?.stopLiveLocationShare()
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package im.vector.app.features.location.live
|
||||
|
||||
import im.vector.app.test.fakes.FakeSession
|
||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||
import io.mockk.unmockkAll
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
@ -29,10 +29,10 @@ private const val AN_EVENT_ID = "event_id"
|
||||
|
||||
class StopLiveLocationShareUseCaseTest {
|
||||
|
||||
private val fakeSession = FakeSession()
|
||||
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
|
||||
|
||||
private val stopLiveLocationShareUseCase = StopLiveLocationShareUseCase(
|
||||
session = fakeSession
|
||||
activeSessionHolder = fakeActiveSessionHolder.instance
|
||||
)
|
||||
|
||||
@After
|
||||
@ -43,7 +43,9 @@ class StopLiveLocationShareUseCaseTest {
|
||||
@Test
|
||||
fun `given a room id when calling use case then the current live is stopped with success`() = runTest {
|
||||
val updateLiveResult = UpdateLiveLocationShareResult.Success(AN_EVENT_ID)
|
||||
fakeSession.roomService()
|
||||
fakeActiveSessionHolder
|
||||
.fakeSession
|
||||
.roomService()
|
||||
.getRoom(A_ROOM_ID)
|
||||
.locationSharingService()
|
||||
.givenStopLiveLocationShareReturns(updateLiveResult)
|
||||
@ -57,7 +59,9 @@ class StopLiveLocationShareUseCaseTest {
|
||||
fun `given a room id and error during the process when calling use case then result is failure`() = runTest {
|
||||
val error = Throwable()
|
||||
val updateLiveResult = UpdateLiveLocationShareResult.Failure(error)
|
||||
fakeSession.roomService()
|
||||
fakeActiveSessionHolder
|
||||
.fakeSession
|
||||
.roomService()
|
||||
.getRoom(A_ROOM_ID)
|
||||
.locationSharingService()
|
||||
.givenStopLiveLocationShareReturns(updateLiveResult)
|
||||
|
@ -23,7 +23,7 @@ import io.mockk.mockk
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
|
||||
class FakeActiveSessionHolder(
|
||||
private val fakeSession: FakeSession = FakeSession()
|
||||
val fakeSession: FakeSession = FakeSession()
|
||||
) {
|
||||
val instance = mockk<ActiveSessionHolder> {
|
||||
every { getActiveSession() } returns fakeSession
|
||||
|
Loading…
Reference in New Issue
Block a user