remove unused persistence methods

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-07-26 21:55:03 +02:00
parent 3d0027d517
commit f951336d0d
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 3 additions and 80 deletions

View file

@ -18,7 +18,7 @@ class MainActivityTest {
fun login() {
val sut = activityRule.launchActivity(null)
val user = sut.userManager.createOrUpdateUser(
val user = sut.userManager.storeProfile(
"test",
UserManager.UserAttributes(
null,

View file

@ -98,29 +98,6 @@ abstract class UsersDao {
}
}
@Transaction
open fun markUserForDeletion(id: Long): Boolean {
getUserWithId(id).blockingGet()?.let { user ->
user.current = FALSE
updateUser(user)
}
return setAnyUserAsActive()
}
@Transaction
open fun setAnyUserAsActive(): Boolean {
val users = getUsers().blockingGet()
val result = users.firstOrNull()?.let { user ->
user.current = TRUE
updateUser(user)
TRUE
} ?: FALSE
return result
}
companion object {
const val TAG = "UsersDao"
}

View file

@ -41,6 +41,4 @@ interface UsersRepository {
fun insertUser(user: User): Long
fun setUserAsActiveWithId(id: Long): Single<Boolean>
fun deleteUser(user: User): Int
fun setAnyUserAsActive(): Boolean
fun markUserForDeletion(id: Long): Boolean
}

View file

@ -80,12 +80,4 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
override fun deleteUser(user: User): Int {
return usersDao.deleteUser(UserMapper.toEntity(user))
}
override fun setAnyUserAsActive(): Boolean {
return usersDao.setAnyUserAsActive()
}
override fun markUserForDeletion(id: Long): Boolean {
return usersDao.markUserForDeletion(id)
}
}

View file

@ -49,10 +49,6 @@ class UserManager internal constructor(private val userRepository: UsersReposito
return userRepository.deleteUser(userRepository.getUserWithId(internalId).blockingGet())
}
fun getUserById(userId: String): Maybe<User> {
return userRepository.getUserWithUserId(userId)
}
fun getUserWithId(id: Long): Maybe<User> {
return userRepository.getUserWithId(id)
}
@ -154,9 +150,7 @@ class UserManager internal constructor(private val userRepository: UsersReposito
}
fun storeProfile(username: String?, userAttributes: UserAttributes): Maybe<User> {
val userMaybe: Maybe<User> = findUser(null, userAttributes)
return userMaybe
return findUser(userAttributes)
.map { user: User? ->
when (user) {
null -> createUser(
@ -190,52 +184,14 @@ class UserManager internal constructor(private val userRepository: UsersReposito
}
}
@Deprecated("Only available for migration, use updateExternalSignalingServer or create new methods")
fun createOrUpdateUser(
username: String?,
userAttributes: UserAttributes
): Maybe<User> {
val userMaybe: Maybe<User> = findUser(username, userAttributes)
return userMaybe
.map { user: User? ->
when (user) {
null -> createUser(
username,
userAttributes
)
else -> {
updateUserData(
user,
userAttributes
)
user
}
}
}
.switchIfEmpty(Maybe.just(createUser(username, userAttributes)))
.map { user ->
userRepository.insertUser(user)
}
.flatMap { id ->
userRepository.getUserWithId(id)
}
}
private fun findUser(username: String?, userAttributes: UserAttributes): Maybe<User> {
private fun findUser(userAttributes: UserAttributes): Maybe<User> {
return if (userAttributes.id != null) {
userRepository.getUserWithId(userAttributes.id)
} else if (username != null && userAttributes.serverUrl != null) {
userRepository.getUserWithUsernameAndServer(username, userAttributes.serverUrl)
} else {
Maybe.empty()
}
}
fun getUserWithUsernameAndServer(username: String, server: String): Maybe<User> {
return userRepository.getUserWithUsernameAndServer(username, server)
}
private fun updateUserData(user: User, userAttributes: UserAttributes) {
user.userId = userAttributes.userId
user.token = userAttributes.token