mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 21:15:30 +03:00
remove unused persistence methods
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
3d0027d517
commit
f951336d0d
5 changed files with 3 additions and 80 deletions
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue