Merge pull request #2251 from nextcloud/chore/noid/roomCleanup

Persistence cleanup
This commit is contained in:
Andy Scherzinger 2022-07-27 09:15:41 +02:00 committed by GitHub
commit 441c321e6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 88 deletions

View File

@ -344,12 +344,17 @@ task installGitHooks(type: Copy, group: "development") {
into '../.git/hooks'
}
detekt {
tasks.named("detekt").configure {
reports {
xml {
enabled = false
}
html.required.set(true)
txt.required.set(true)
xml.required.set(false)
sarif.required.set(false)
md.required.set(false)
}
}
detekt {
config = files("../detekt.yml")
input = files("src/")
}

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

@ -33,8 +33,6 @@ import androidx.room.Update
import com.nextcloud.talk.data.user.model.UserEntity
import io.reactivex.Maybe
import io.reactivex.Single
import java.lang.Boolean.FALSE
import java.lang.Boolean.TRUE
@Dao
@Suppress("TooManyFunctions")
@ -98,29 +96,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

@ -26,7 +26,6 @@ import android.text.TextUtils;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.data.user.model.User;
import com.nextcloud.talk.models.ExternalSignalingServer;
import com.nextcloud.talk.users.UserManager;
import com.nextcloud.talk.webrtc.WebSocketConnectionHelper;

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

View File

@ -36,8 +36,8 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Build;
import android.util.Log;
import org.webrtc.ThreadUtils;
/**