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