mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
TI: create account
This commit is contained in:
parent
fc6d845c0d
commit
6746f68411
6 changed files with 284 additions and 305 deletions
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.matrix.android.account
|
||||||
|
|
||||||
|
import im.vector.matrix.android.InstrumentedTest
|
||||||
|
import im.vector.matrix.android.common.CommonTestHelper
|
||||||
|
import im.vector.matrix.android.common.SessionTestParams
|
||||||
|
import im.vector.matrix.android.common.TestConstants
|
||||||
|
import org.junit.FixMethodOrder
|
||||||
|
import org.junit.Test
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
import org.junit.runners.JUnit4
|
||||||
|
import org.junit.runners.MethodSorters
|
||||||
|
|
||||||
|
@RunWith(JUnit4::class)
|
||||||
|
@FixMethodOrder(MethodSorters.JVM)
|
||||||
|
class AccountCreationTest : InstrumentedTest {
|
||||||
|
|
||||||
|
private val commonTestHelper = CommonTestHelper(context())
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun createAccountTest() {
|
||||||
|
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))
|
||||||
|
|
||||||
|
commonTestHelper.signout(session)
|
||||||
|
|
||||||
|
session.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME This test does not past yet, due to usage of the EventBus.
|
||||||
|
@Test
|
||||||
|
fun createAccountAndLoginAgainTest() {
|
||||||
|
val session = commonTestHelper.createAccount(TestConstants.USER_ALICE, SessionTestParams(withInitialSync = true))
|
||||||
|
|
||||||
|
// Log again to the same account
|
||||||
|
val session2 = commonTestHelper.logIntoAccount(session.myUserId, SessionTestParams(withInitialSync = true))
|
||||||
|
|
||||||
|
session.close()
|
||||||
|
session2.close()
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,85 +17,77 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.common
|
package im.vector.matrix.android.common
|
||||||
|
|
||||||
// import android.content.Context
|
import android.content.Context
|
||||||
// import android.net.Uri
|
import android.net.Uri
|
||||||
// import androidx.test.InstrumentationRegistry
|
import im.vector.matrix.android.api.Matrix
|
||||||
//
|
import im.vector.matrix.android.api.MatrixConfiguration
|
||||||
// import org.junit.Assert
|
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||||
//
|
import im.vector.matrix.android.api.auth.data.LoginFlowResult
|
||||||
// import java.util.ArrayList
|
import im.vector.matrix.android.api.auth.registration.RegistrationResult
|
||||||
// import java.util.HashMap
|
import im.vector.matrix.android.api.session.Session
|
||||||
// import java.util.UUID
|
import org.junit.Assert.assertNotNull
|
||||||
// import java.util.concurrent.CountDownLatch
|
import org.junit.Assert.assertTrue
|
||||||
// import java.util.concurrent.TimeUnit
|
import java.util.*
|
||||||
//
|
import java.util.concurrent.CountDownLatch
|
||||||
// import im.vector.matrix.android.api.Matrix
|
import java.util.concurrent.TimeUnit
|
||||||
// import im.vector.matrix.android.api.auth.data.Credentials
|
|
||||||
// import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
/**
|
||||||
// import im.vector.matrix.android.api.session.Session
|
* This class exposes methods to be used in common cases
|
||||||
// import im.vector.matrix.android.internal.auth.registration.AuthParams
|
* Registration, login, Sync, Sending messages...
|
||||||
// import im.vector.matrix.android.internal.auth.registration.RegistrationFlowResponse
|
*/
|
||||||
// import im.vector.matrix.android.internal.auth.registration.RegistrationParams
|
class CommonTestHelper(context: Context) {
|
||||||
// import io.realm.internal.android.JsonUtils
|
|
||||||
//
|
val matrix: Matrix
|
||||||
//
|
|
||||||
// /**
|
init {
|
||||||
// * This class exposes methods to be used in common cases
|
Matrix.initialize(context, MatrixConfiguration("TestFlavor"))
|
||||||
// * Registration, login, Sync, Sending messages...
|
|
||||||
// */
|
matrix = Matrix.getInstance(context)
|
||||||
// class CommonTestHelper {
|
}
|
||||||
//
|
|
||||||
// @Throws(InterruptedException::class)
|
|
||||||
// fun createAccount(userNamePrefix: String, testParams: SessionTestParams): Session {
|
fun createAccount(userNamePrefix: String, testParams: SessionTestParams): Session {
|
||||||
// return createAccount(userNamePrefix, TestConstants.PASSWORD, testParams)
|
return createAccount(userNamePrefix, TestConstants.PASSWORD, testParams)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Throws(InterruptedException::class)
|
fun logIntoAccount(userId: String, testParams: SessionTestParams): Session {
|
||||||
// fun logIntoAccount(userId: String, testParams: SessionTestParams): Session {
|
return logIntoAccount(userId, TestConstants.PASSWORD, testParams)
|
||||||
// return logIntoAccount(userId, TestConstants.PASSWORD, testParams)
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// /**
|
* Create a Home server configuration, with Http connection allowed for test
|
||||||
// * Create a Home server configuration, with Http connection allowed for test
|
*/
|
||||||
// */
|
fun createHomeServerConfig(): HomeServerConnectionConfig {
|
||||||
// fun createHomeServerConfig(): HomeServerConnectionConfig {
|
return HomeServerConnectionConfig.Builder()
|
||||||
// return HomeServerConnectionConfig.Builder()
|
.withHomeServerUri(Uri.parse(TestConstants.TESTS_HOME_SERVER_URL))
|
||||||
// .withHomeServerUri(Uri.parse(TestConstants.TESTS_HOME_SERVER_URL))
|
.build()
|
||||||
// .build()
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// /**
|
* This methods init the event stream and check for initial sync
|
||||||
// * This methods init the event stream and check for initial sync
|
*
|
||||||
// *
|
* @param session the session to sync
|
||||||
// * @param session the session to sync
|
*/
|
||||||
// * @param withCrypto true if crypto is enabled and should be checked
|
fun syncSession(session: Session) {
|
||||||
// */
|
//val lock = CountDownLatch(1)
|
||||||
// @Throws(InterruptedException::class)
|
|
||||||
// fun syncSession(session: Session, withCrypto: Boolean) {
|
// val observer = androidx.lifecycle.Observer<SyncState> { syncState ->
|
||||||
// val params = HashMap<String, Boolean>()
|
// if (syncState is SyncState.Idle) {
|
||||||
// val sizeOfLock = if (withCrypto) 2 else 1
|
// lock.countDown()
|
||||||
// val lock2 = CountDownLatch(sizeOfLock)
|
// }
|
||||||
// session.getDataHandler().addListener(object : MXEventListener() {
|
// }
|
||||||
// fun onInitialSyncComplete(toToken: String) {
|
|
||||||
// params["isInit"] = true
|
// TODO observe?
|
||||||
// lock2.countDown()
|
// while (session.syncState().value !is SyncState.Idle) {
|
||||||
// }
|
// sleep(100)
|
||||||
//
|
// }
|
||||||
// fun onCryptoSyncComplete() {
|
|
||||||
// params["onCryptoSyncComplete"] = true
|
session.open()
|
||||||
// lock2.countDown()
|
session.startSync(true)
|
||||||
// }
|
//await(lock)
|
||||||
// })
|
//session.syncState().removeObserver(observer)
|
||||||
// session.getDataHandler().getStore().open()
|
}
|
||||||
// session.startEventStream(null)
|
|
||||||
//
|
|
||||||
// await(lock2)
|
|
||||||
// Assert.assertTrue(params.containsKey("isInit"))
|
|
||||||
// if (withCrypto) {
|
|
||||||
// Assert.assertTrue(params.containsKey("onCryptoSyncComplete"))
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
// /**
|
||||||
// * Sends text messages in a room
|
// * Sends text messages in a room
|
||||||
// *
|
// *
|
||||||
|
@ -140,216 +132,153 @@ package im.vector.matrix.android.common
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// // PRIVATE METHODS *****************************************************************************
|
// PRIVATE METHODS *****************************************************************************
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * Creates a unique account
|
* Creates a unique account
|
||||||
// *
|
*
|
||||||
// * @param userNamePrefix the user name prefix
|
* @param userNamePrefix the user name prefix
|
||||||
// * @param password the password
|
* @param password the password
|
||||||
// * @param testParams test params about the session
|
* @param testParams test params about the session
|
||||||
// * @return the session associated with the newly created account
|
* @return the session associated with the newly created account
|
||||||
// */
|
*/
|
||||||
// @Throws(InterruptedException::class)
|
@Throws(InterruptedException::class)
|
||||||
// private fun createAccount(userNamePrefix: String,
|
private fun createAccount(userNamePrefix: String,
|
||||||
// password: String,
|
password: String,
|
||||||
// testParams: SessionTestParams): Session {
|
testParams: SessionTestParams): Session {
|
||||||
// val context = InstrumentationRegistry.getContext()
|
val session = createAccountAndSync(
|
||||||
// val session = createAccountAndSync(
|
userNamePrefix + "_" + System.currentTimeMillis() + UUID.randomUUID(),
|
||||||
// context,
|
password,
|
||||||
// userNamePrefix + "_" + System.currentTimeMillis() + UUID.randomUUID(),
|
testParams
|
||||||
// password,
|
)
|
||||||
// testParams
|
assertNotNull(session)
|
||||||
// )
|
return session
|
||||||
// Assert.assertNotNull(session)
|
}
|
||||||
// return session
|
|
||||||
// }
|
/**
|
||||||
//
|
* Logs into an existing account
|
||||||
// /**
|
*
|
||||||
// * Logs into an existing account
|
* @param userId the userId to log in
|
||||||
// *
|
* @param password the password to log in
|
||||||
// * @param userId the userId to log in
|
* @param testParams test params about the session
|
||||||
// * @param password the password to log in
|
* @return the session associated with the existing account
|
||||||
// * @param testParams test params about the session
|
*/
|
||||||
// * @return the session associated with the existing account
|
@Throws(InterruptedException::class)
|
||||||
// */
|
private fun logIntoAccount(userId: String,
|
||||||
// @Throws(InterruptedException::class)
|
password: String,
|
||||||
// private fun logIntoAccount(userId: String,
|
testParams: SessionTestParams): Session {
|
||||||
// password: String,
|
val session = logAccountAndSync(userId, password, testParams)
|
||||||
// testParams: SessionTestParams): Session {
|
assertNotNull(session)
|
||||||
// val context = InstrumentationRegistry.getContext()
|
return session
|
||||||
// val session = logAccountAndSync(context, userId, password, testParams)
|
}
|
||||||
// Assert.assertNotNull(session)
|
|
||||||
// return session
|
/**
|
||||||
// }
|
* Create an account and a dedicated session
|
||||||
//
|
*
|
||||||
// /**
|
* @param userName the account username
|
||||||
// * Create an account and a dedicated session
|
* @param password the password
|
||||||
// *
|
* @param sessionTestParams parameters for the test
|
||||||
// * @param context the context
|
*/
|
||||||
// * @param userName the account username
|
private fun createAccountAndSync(userName: String,
|
||||||
// * @param password the password
|
password: String,
|
||||||
// * @param sessionTestParams parameters for the test
|
sessionTestParams: SessionTestParams): Session {
|
||||||
// */
|
val hs = createHomeServerConfig()
|
||||||
// @Throws(InterruptedException::class)
|
|
||||||
// private fun createAccountAndSync(context: Context,
|
var lock = CountDownLatch(1)
|
||||||
// userName: String,
|
matrix.authenticationService.getLoginFlow(hs, object : TestMatrixCallback<LoginFlowResult>(lock) {})
|
||||||
// password: String,
|
await(lock)
|
||||||
// sessionTestParams: SessionTestParams): Session {
|
|
||||||
// val hs = createHomeServerConfig()
|
lock = CountDownLatch(1)
|
||||||
//
|
matrix.authenticationService.getRegistrationWizard().createAccount(userName, password, null, object : TestMatrixCallback<RegistrationResult>(lock) {
|
||||||
// val loginRestClient = LoginRestClient(hs)
|
override fun onSuccess(data: RegistrationResult) {
|
||||||
//
|
super.onSuccess(data)
|
||||||
// val params = HashMap<String, Any>()
|
}
|
||||||
// val registrationParams = RegistrationParams()
|
})
|
||||||
//
|
await(lock)
|
||||||
// var lock = CountDownLatch(1)
|
|
||||||
//
|
// Preform dummy step
|
||||||
// // get the registration session id
|
lock = CountDownLatch(1)
|
||||||
// loginRestClient.register(registrationParams, object : TestMatrixCallback<Credentials>(lock, false) {
|
var registrationResult: RegistrationResult? = null
|
||||||
// override fun onFailure(failure: Throwable) {
|
matrix.authenticationService.getRegistrationWizard().dummy(object : TestMatrixCallback<RegistrationResult>(lock) {
|
||||||
// // detect if a parameter is expected
|
override fun onSuccess(data: RegistrationResult) {
|
||||||
// var registrationFlowResponse: RegistrationFlowResponse? = null
|
registrationResult = data
|
||||||
//
|
super.onSuccess(data)
|
||||||
// // when a response is not completed the server returns an error message
|
}
|
||||||
// if (null != failure.mStatus && failure.mStatus === 401) {
|
})
|
||||||
// try {
|
await(lock)
|
||||||
// registrationFlowResponse = JsonUtils.toRegistrationFlowResponse(e.mErrorBodyAsString)
|
|
||||||
// } catch (castExcept: Exception) {
|
assertTrue(registrationResult is RegistrationResult.Success)
|
||||||
// }
|
val session = (registrationResult as RegistrationResult.Success).session
|
||||||
//
|
if (sessionTestParams.withInitialSync) {
|
||||||
// }
|
syncSession(session)
|
||||||
//
|
}
|
||||||
// // check if the server response can be casted
|
|
||||||
// if (null != registrationFlowResponse) {
|
return session
|
||||||
// params["session"] = registrationFlowResponse!!.session
|
}
|
||||||
// }
|
|
||||||
//
|
/**
|
||||||
// super.onFailure(failure)
|
* Start an account login
|
||||||
// }
|
*
|
||||||
// })
|
* @param userName the account username
|
||||||
//
|
* @param password the password
|
||||||
// await(lock)
|
* @param sessionTestParams session test params
|
||||||
//
|
*/
|
||||||
// val session = params["session"] as String?
|
private fun logAccountAndSync(userName: String,
|
||||||
//
|
password: String,
|
||||||
// Assert.assertNotNull(session)
|
sessionTestParams: SessionTestParams): Session {
|
||||||
//
|
val hs = createHomeServerConfig()
|
||||||
// registrationParams.username = userName
|
|
||||||
// registrationParams.password = password
|
var lock = CountDownLatch(1)
|
||||||
// val authParams = AuthParams(LOGIN_FLOW_TYPE_DUMMY)
|
matrix.authenticationService.getLoginFlow(hs, object : TestMatrixCallback<LoginFlowResult>(lock) {})
|
||||||
// authParams.session = session
|
await(lock)
|
||||||
//
|
|
||||||
// registrationParams.auth = authParams
|
lock = CountDownLatch(1)
|
||||||
//
|
var session: Session? = null
|
||||||
// lock = CountDownLatch(1)
|
matrix.authenticationService.getLoginWizard().login(userName, password, "myDevice", object : TestMatrixCallback<Session>(lock) {
|
||||||
// loginRestClient.register(registrationParams, object : TestMatrixCallback<Credentials>(lock) {
|
override fun onSuccess(data: Session) {
|
||||||
// fun onSuccess(credentials: Credentials) {
|
session = data
|
||||||
// params["credentials"] = credentials
|
super.onSuccess(data)
|
||||||
// super.onSuccess(credentials)
|
}
|
||||||
// }
|
})
|
||||||
// })
|
await(lock)
|
||||||
//
|
|
||||||
// await(lock)
|
assertNotNull(session)
|
||||||
//
|
|
||||||
// val credentials = params["credentials"] as Credentials?
|
if (sessionTestParams.withInitialSync) {
|
||||||
//
|
syncSession(session!!)
|
||||||
// Assert.assertNotNull(credentials)
|
}
|
||||||
//
|
|
||||||
// hs.setCredentials(credentials)
|
return session!!
|
||||||
//
|
}
|
||||||
// val store = MXFileStore(hs, false, context)
|
|
||||||
//
|
/**
|
||||||
// val dataHandler = MXDataHandler(store, credentials)
|
* Await for a latch and ensure the result is true
|
||||||
// dataHandler.setLazyLoadingEnabled(sessionTestParams.withLazyLoading)
|
*
|
||||||
//
|
* @param latch
|
||||||
// val Session = Session.Builder(hs, dataHandler, context)
|
* @throws InterruptedException
|
||||||
// .withLegacyCryptoStore(sessionTestParams.withLegacyCryptoStore)
|
*/
|
||||||
// .build()
|
fun await(latch: CountDownLatch) {
|
||||||
//
|
assertTrue(latch.await(TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
||||||
// if (sessionTestParams.withCryptoEnabled) {
|
}
|
||||||
// Session.enableCryptoWhenStarting()
|
|
||||||
// }
|
/**
|
||||||
// if (sessionTestParams.withInitialSync) {
|
* Clear all provided sessions
|
||||||
// syncSession(Session, sessionTestParams.withCryptoEnabled)
|
*
|
||||||
// }
|
* @param sessions the sessions to clear
|
||||||
// return Session
|
*/
|
||||||
// }
|
fun closeAllSessions(sessions: List<Session>) {
|
||||||
//
|
for (session in sessions) {
|
||||||
// /**
|
session.close()
|
||||||
// * Start an account login
|
}
|
||||||
// *
|
}
|
||||||
// * @param context the context
|
|
||||||
// * @param userName the account username
|
fun signout(session: Session) {
|
||||||
// * @param password the password
|
val lock = CountDownLatch(1)
|
||||||
// * @param sessionTestParams session test params
|
session.signOut(true, object : TestMatrixCallback<Unit>(lock) {})
|
||||||
// */
|
await(lock)
|
||||||
// @Throws(InterruptedException::class)
|
}
|
||||||
// private fun logAccountAndSync(context: Context,
|
|
||||||
// userName: String,
|
|
||||||
// password: String,
|
|
||||||
// sessionTestParams: SessionTestParams): Session {
|
|
||||||
// val hs = createHomeServerConfig(null)
|
|
||||||
// val loginRestClient = LoginRestClient(hs)
|
|
||||||
// val params = HashMap<String, Any>()
|
|
||||||
// val lock = CountDownLatch(1)
|
|
||||||
//
|
|
||||||
// // get the registration session id
|
|
||||||
// loginRestClient.loginWithUser(userName, password, object : TestMatrixCallback<Credentials>(lock) {
|
|
||||||
// fun onSuccess(credentials: Credentials) {
|
|
||||||
// params["credentials"] = credentials
|
|
||||||
// super.onSuccess(credentials)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// await(lock)
|
|
||||||
//
|
|
||||||
// val credentials = params["credentials"] as Credentials?
|
|
||||||
//
|
|
||||||
// Assert.assertNotNull(credentials)
|
|
||||||
//
|
|
||||||
// hs.setCredentials(credentials)
|
|
||||||
//
|
|
||||||
// val store = MXFileStore(hs, false, context)
|
|
||||||
//
|
|
||||||
// val mxDataHandler = MXDataHandler(store, credentials)
|
|
||||||
// mxDataHandler.setLazyLoadingEnabled(sessionTestParams.withLazyLoading)
|
|
||||||
//
|
|
||||||
// val Session = Session.Builder(hs, mxDataHandler, context)
|
|
||||||
// .withLegacyCryptoStore(sessionTestParams.withLegacyCryptoStore)
|
|
||||||
// .build()
|
|
||||||
//
|
|
||||||
// if (sessionTestParams.withCryptoEnabled) {
|
|
||||||
// Session.enableCryptoWhenStarting()
|
|
||||||
// }
|
|
||||||
// if (sessionTestParams.withInitialSync) {
|
|
||||||
// syncSession(Session, sessionTestParams.withCryptoEnabled)
|
|
||||||
// }
|
|
||||||
// return Session
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Await for a latch and ensure the result is true
|
|
||||||
// *
|
|
||||||
// * @param latch
|
|
||||||
// * @throws InterruptedException
|
|
||||||
// */
|
|
||||||
// @Throws(InterruptedException::class)
|
|
||||||
// fun await(latch: CountDownLatch) {
|
|
||||||
// Assert.assertTrue(latch.await(TestConstants.timeOutMillis, TimeUnit.MILLISECONDS))
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Clear all provided sessions
|
|
||||||
// *
|
|
||||||
// * @param sessions the sessions to clear
|
|
||||||
// */
|
|
||||||
// fun closeAllSessions(sessions: List<Session>) {
|
|
||||||
// for (session in sessions) {
|
|
||||||
// session.close()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
// /**
|
||||||
// * Clone a session.
|
// * Clone a session.
|
||||||
// * It simulate that the user launches again the application with the same Credentials, contrary to login which will create a new DeviceId
|
// * It simulate that the user launches again the application with the same Credentials, contrary to login which will create a new DeviceId
|
||||||
|
@ -404,4 +333,4 @@ package im.vector.matrix.android.common
|
||||||
//
|
//
|
||||||
// return session2
|
// return session2
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
|
|
|
@ -15,7 +15,11 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.matrix.android.common
|
package im.vector.matrix.android.common
|
||||||
|
|
||||||
import okhttp3.*
|
import okhttp3.Interceptor
|
||||||
|
import okhttp3.Protocol
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import okhttp3.ResponseBody.Companion.toResponseBody
|
||||||
import javax.net.ssl.HttpsURLConnection
|
import javax.net.ssl.HttpsURLConnection
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +77,7 @@ class MockOkHttpInterceptor : Interceptor {
|
||||||
.protocol(Protocol.HTTP_1_1)
|
.protocol(Protocol.HTTP_1_1)
|
||||||
.request(originalRequest)
|
.request(originalRequest)
|
||||||
.message("mocked answer")
|
.message("mocked answer")
|
||||||
.body(ResponseBody.create(null, body))
|
.body(body.toResponseBody(null))
|
||||||
.code(code)
|
.code(code)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,8 @@ interface SignOutService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign out, and release the session, clear all the session data, including crypto data
|
* Sign out, and release the session, clear all the session data, including crypto data
|
||||||
* @param sigOutFromHomeserver true if the sign out request has to be done
|
* @param signOutFromHomeserver true if the sign out request has to be done
|
||||||
*/
|
*/
|
||||||
fun signOut(sigOutFromHomeserver: Boolean,
|
fun signOut(signOutFromHomeserver: Boolean,
|
||||||
callback: MatrixCallback<Unit>): Cancelable
|
callback: MatrixCallback<Unit>): Cancelable
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,6 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
|
||||||
|
|
||||||
@MainThread
|
@MainThread
|
||||||
override fun open() {
|
override fun open() {
|
||||||
assertMainThread()
|
|
||||||
assert(!isOpen)
|
assert(!isOpen)
|
||||||
isOpen = true
|
isOpen = true
|
||||||
liveEntityObservers.forEach { it.start() }
|
liveEntityObservers.forEach { it.start() }
|
||||||
|
@ -201,12 +200,4 @@ internal class DefaultSession @Inject constructor(override val sessionParams: Se
|
||||||
override fun removeListener(listener: Session.Listener) {
|
override fun removeListener(listener: Session.Listener) {
|
||||||
sessionListeners.removeListener(listener)
|
sessionListeners.removeListener(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private methods *****************************************************************************
|
|
||||||
|
|
||||||
private fun assertMainThread() {
|
|
||||||
if (Looper.getMainLooper().thread !== Thread.currentThread()) {
|
|
||||||
throw IllegalStateException("This method can only be called on the main thread!")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,10 +50,10 @@ internal class DefaultSignOutService @Inject constructor(private val signOutTask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun signOut(sigOutFromHomeserver: Boolean,
|
override fun signOut(signOutFromHomeserver: Boolean,
|
||||||
callback: MatrixCallback<Unit>): Cancelable {
|
callback: MatrixCallback<Unit>): Cancelable {
|
||||||
return signOutTask
|
return signOutTask
|
||||||
.configureWith(SignOutTask.Params(sigOutFromHomeserver)) {
|
.configureWith(SignOutTask.Params(signOutFromHomeserver)) {
|
||||||
this.callback = callback
|
this.callback = callback
|
||||||
}
|
}
|
||||||
.executeBy(taskExecutor)
|
.executeBy(taskExecutor)
|
||||||
|
|
Loading…
Reference in a new issue