Rename method storeData to addSession.
This commit is contained in:
parent
a46b7c27a9
commit
06bcbb8bb8
6 changed files with 11 additions and 11 deletions
|
|
@ -158,7 +158,7 @@ class RustMatrixAuthenticationService(
|
||||||
)
|
)
|
||||||
val matrixClient = rustMatrixClientFactory.create(client)
|
val matrixClient = rustMatrixClientFactory.create(client)
|
||||||
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
||||||
sessionStore.storeData(sessionData)
|
sessionStore.addSession(sessionData)
|
||||||
|
|
||||||
// Clean up the strong reference held here since it's no longer necessary
|
// Clean up the strong reference held here since it's no longer necessary
|
||||||
currentClient = null
|
currentClient = null
|
||||||
|
|
@ -182,7 +182,7 @@ class RustMatrixAuthenticationService(
|
||||||
sessionPaths = currentSessionPaths,
|
sessionPaths = currentSessionPaths,
|
||||||
)
|
)
|
||||||
clear()
|
clear()
|
||||||
sessionStore.storeData(sessionData)
|
sessionStore.addSession(sessionData)
|
||||||
SessionId(sessionData.userId)
|
SessionId(sessionData.userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,7 +250,7 @@ class RustMatrixAuthenticationService(
|
||||||
|
|
||||||
val matrixClient = rustMatrixClientFactory.create(client)
|
val matrixClient = rustMatrixClientFactory.create(client)
|
||||||
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
||||||
sessionStore.storeData(sessionData)
|
sessionStore.addSession(sessionData)
|
||||||
|
|
||||||
// Clean up the strong reference held here since it's no longer necessary
|
// Clean up the strong reference held here since it's no longer necessary
|
||||||
currentClient = null
|
currentClient = null
|
||||||
|
|
@ -295,7 +295,7 @@ class RustMatrixAuthenticationService(
|
||||||
)
|
)
|
||||||
val matrixClient = rustMatrixClientFactory.create(client)
|
val matrixClient = rustMatrixClientFactory.create(client)
|
||||||
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
newMatrixClientObservers.forEach { it.invoke(matrixClient) }
|
||||||
sessionStore.storeData(sessionData)
|
sessionStore.addSession(sessionData)
|
||||||
|
|
||||||
// Clean up the strong reference held here since it's no longer necessary
|
// Clean up the strong reference held here since it's no longer necessary
|
||||||
currentClient = null
|
currentClient = null
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.map
|
||||||
interface SessionStore {
|
interface SessionStore {
|
||||||
fun isLoggedIn(): Flow<LoggedInState>
|
fun isLoggedIn(): Flow<LoggedInState>
|
||||||
fun sessionsFlow(): Flow<List<SessionData>>
|
fun sessionsFlow(): Flow<List<SessionData>>
|
||||||
suspend fun storeData(sessionData: SessionData)
|
suspend fun addSession(sessionData: SessionData)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will update the session data matching the userId, except the value of loginTimestamp.
|
* Will update the session data matching the userId, except the value of loginTimestamp.
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class DatabaseSessionStore(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun storeData(sessionData: SessionData) {
|
override suspend fun addSession(sessionData: SessionData) {
|
||||||
sessionDataMutex.withLock {
|
sessionDataMutex.withLock {
|
||||||
database.sessionDataQueries.insertSessionData(sessionData.toDbModel())
|
database.sessionDataQueries.insertSessionData(sessionData.toDbModel())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,10 +44,10 @@ class DatabaseSessionStoreTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `storeData persists the SessionData into the DB`() = runTest {
|
fun `addSession persists the SessionData into the DB`() = runTest {
|
||||||
assertThat(database.sessionDataQueries.selectFirst().executeAsOneOrNull()).isNull()
|
assertThat(database.sessionDataQueries.selectFirst().executeAsOneOrNull()).isNull()
|
||||||
|
|
||||||
databaseSessionStore.storeData(aSessionData.toApiModel())
|
databaseSessionStore.addSession(aSessionData.toApiModel())
|
||||||
|
|
||||||
assertThat(database.sessionDataQueries.selectFirst().executeAsOneOrNull()).isEqualTo(aSessionData)
|
assertThat(database.sessionDataQueries.selectFirst().executeAsOneOrNull()).isEqualTo(aSessionData)
|
||||||
assertThat(database.sessionDataQueries.selectAll().executeAsList().size).isEqualTo(1)
|
assertThat(database.sessionDataQueries.selectAll().executeAsList().size).isEqualTo(1)
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ import org.junit.Test
|
||||||
runCurrent()
|
runCurrent()
|
||||||
val listener = TestSessionListener()
|
val listener = TestSessionListener()
|
||||||
sut.addListener(listener)
|
sut.addListener(listener)
|
||||||
databaseSessionStore.storeData(sessionData.toApiModel())
|
databaseSessionStore.addSession(sessionData.toApiModel())
|
||||||
listener.assertEvents(TestSessionListener.Event.Created(sessionData.userId))
|
listener.assertEvents(TestSessionListener.Event.Created(sessionData.userId))
|
||||||
sut.removeListener(listener)
|
sut.removeListener(listener)
|
||||||
coroutineContext.cancelChildren()
|
coroutineContext.cancelChildren()
|
||||||
|
|
@ -64,7 +64,7 @@ import org.junit.Test
|
||||||
runCurrent()
|
runCurrent()
|
||||||
val listener = TestSessionListener()
|
val listener = TestSessionListener()
|
||||||
sut.addListener(listener)
|
sut.addListener(listener)
|
||||||
databaseSessionStore.storeData(sessionData.toApiModel())
|
databaseSessionStore.addSession(sessionData.toApiModel())
|
||||||
listener.assertEvents(TestSessionListener.Event.Created(sessionData.userId))
|
listener.assertEvents(TestSessionListener.Event.Created(sessionData.userId))
|
||||||
databaseSessionStore.removeSession(sessionData.userId)
|
databaseSessionStore.removeSession(sessionData.userId)
|
||||||
listener.assertEvents(
|
listener.assertEvents(
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ class InMemorySessionStore(
|
||||||
|
|
||||||
override fun sessionsFlow(): Flow<List<SessionData>> = sessionDataListFlow.asStateFlow()
|
override fun sessionsFlow(): Flow<List<SessionData>> = sessionDataListFlow.asStateFlow()
|
||||||
|
|
||||||
override suspend fun storeData(sessionData: SessionData) {
|
override suspend fun addSession(sessionData: SessionData) {
|
||||||
val currentList = sessionDataListFlow.value.toMutableList()
|
val currentList = sessionDataListFlow.value.toMutableList()
|
||||||
currentList.removeAll { it.userId == sessionData.userId }
|
currentList.removeAll { it.userId == sessionData.userId }
|
||||||
currentList.add(sessionData)
|
currentList.add(sessionData)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue