mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 20:49:36 +01:00
fix detekt and ktlint issues
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
5ffa3c44fd
commit
730aeb2944
@ -23,6 +23,7 @@ package com.nextcloud.talk.data.source.local
|
|||||||
import androidx.room.migration.Migration
|
import androidx.room.migration.Migration
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
|
|
||||||
|
@Suppress("MagicNumber")
|
||||||
object Migrations {
|
object Migrations {
|
||||||
val MIGRATION_6_8 = object : Migration(6, 8) {
|
val MIGRATION_6_8 = object : Migration(6, 8) {
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(database: SupportSQLiteDatabase) {
|
||||||
|
@ -34,6 +34,7 @@ import java.lang.Boolean.FALSE
|
|||||||
import java.lang.Boolean.TRUE
|
import java.lang.Boolean.TRUE
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
abstract class UsersDao {
|
abstract class UsersDao {
|
||||||
// get active user
|
// get active user
|
||||||
@Query("SELECT * FROM User where current = 1")
|
@Query("SELECT * FROM User where current = 1")
|
||||||
|
@ -26,6 +26,7 @@ import androidx.lifecycle.LiveData
|
|||||||
import com.nextcloud.talk.data.user.model.UserNgEntity
|
import com.nextcloud.talk.data.user.model.UserNgEntity
|
||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
|
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
interface UsersRepository {
|
interface UsersRepository {
|
||||||
fun getActiveUserLiveData(): LiveData<UserNgEntity?>
|
fun getActiveUserLiveData(): LiveData<UserNgEntity?>
|
||||||
fun getActiveUser(): UserNgEntity?
|
fun getActiveUser(): UserNgEntity?
|
||||||
|
@ -29,6 +29,7 @@ import com.nextcloud.talk.data.user.model.UserNgEntity
|
|||||||
import com.nextcloud.talk.data.user.model.User
|
import com.nextcloud.talk.data.user.model.User
|
||||||
import com.nextcloud.talk.data.user.model.toUser
|
import com.nextcloud.talk.data.user.model.toUser
|
||||||
|
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
|
||||||
override fun getActiveUserLiveData(): LiveData<UserNgEntity?> {
|
override fun getActiveUserLiveData(): LiveData<UserNgEntity?> {
|
||||||
return usersDao.getActiveUserLiveData().distinctUntilChanged()
|
return usersDao.getActiveUserLiveData().distinctUntilChanged()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package com.nextcloud.talk.data.user.model
|
package com.nextcloud.talk.data.user.model
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
|
import com.nextcloud.talk.data.user.model.User.Companion.DEFAULT_CHAT_MESSAGE_LENGTH
|
||||||
import com.nextcloud.talk.models.ExternalSignalingServer
|
import com.nextcloud.talk.models.ExternalSignalingServer
|
||||||
import com.nextcloud.talk.models.json.capabilities.Capabilities
|
import com.nextcloud.talk.models.json.capabilities.Capabilities
|
||||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||||
@ -43,10 +44,15 @@ data class User(
|
|||||||
var externalSignalingServer: ExternalSignalingServer? = null,
|
var externalSignalingServer: ExternalSignalingServer? = null,
|
||||||
var current: Boolean = FALSE,
|
var current: Boolean = FALSE,
|
||||||
var scheduledForDeletion: Boolean = FALSE,
|
var scheduledForDeletion: Boolean = FALSE,
|
||||||
) : Parcelable
|
) : Parcelable {
|
||||||
|
companion object {
|
||||||
|
const val DEFAULT_CHAT_MESSAGE_LENGTH: Int = 1000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun User.getMaxMessageLength(): Int {
|
fun User.getMaxMessageLength(): Int {
|
||||||
return capabilities?.spreedCapability?.config?.get("chat")?.get("max-length")?.toInt() ?: 1000
|
return capabilities?.spreedCapability?.config?.get("chat")?.get("max-length")?.toInt()
|
||||||
|
?: DEFAULT_CHAT_MESSAGE_LENGTH
|
||||||
}
|
}
|
||||||
|
|
||||||
fun User.getAttachmentsConfig(key: String): Any? {
|
fun User.getAttachmentsConfig(key: String): Any? {
|
||||||
|
@ -31,6 +31,7 @@ import com.nextcloud.talk.models.json.capabilities.Capabilities
|
|||||||
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
import com.nextcloud.talk.models.json.push.PushConfigurationState
|
||||||
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew
|
||||||
|
|
||||||
|
@Suppress("TooManyFunctions")
|
||||||
class UserManager internal constructor(private val userRepository: UsersRepository) : CurrentUserProviderNew {
|
class UserManager internal constructor(private val userRepository: UsersRepository) : CurrentUserProviderNew {
|
||||||
fun anyUserExists(): Boolean {
|
fun anyUserExists(): Boolean {
|
||||||
return userRepository.getUsers().isNotEmpty()
|
return userRepository.getUsers().isNotEmpty()
|
||||||
@ -49,10 +50,10 @@ class UserManager internal constructor(private val userRepository: UsersReposito
|
|||||||
suspend fun setAnyUserAndSetAsActive(): UserNgEntity? {
|
suspend fun setAnyUserAndSetAsActive(): UserNgEntity? {
|
||||||
val results = userRepository.getUsersNotScheduledForDeletion()
|
val results = userRepository.getUsersNotScheduledForDeletion()
|
||||||
if (results.isNotEmpty()) {
|
if (results.isNotEmpty()) {
|
||||||
val UserNgEntity = results[0]
|
val user = results[0]
|
||||||
UserNgEntity.current = true
|
user.current = true
|
||||||
userRepository.updateUser(UserNgEntity)
|
userRepository.updateUser(user)
|
||||||
return UserNgEntity
|
return user
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -115,95 +116,148 @@ class UserManager internal constructor(private val userRepository: UsersReposito
|
|||||||
|
|
||||||
suspend fun createOrUpdateUser(
|
suspend fun createOrUpdateUser(
|
||||||
username: String?,
|
username: String?,
|
||||||
token: String?,
|
userAttributes: UserAttributes,
|
||||||
serverUrl: String?,
|
|
||||||
displayName: String?,
|
|
||||||
pushConfigurationState: String?,
|
|
||||||
currentUser: Boolean?,
|
|
||||||
userId: String?,
|
|
||||||
internalId: Long?,
|
|
||||||
capabilities: String?,
|
|
||||||
certificateAlias: String?,
|
|
||||||
externalSignalingServer: String?
|
|
||||||
): LiveData<UserNgEntity?> {
|
): LiveData<UserNgEntity?> {
|
||||||
var user = if (internalId == null && username != null && serverUrl != null) {
|
var user = if (userAttributes.id == null && username != null && userAttributes.serverUrl != null) {
|
||||||
userRepository.getUserWithUsernameAndServer(username, serverUrl)
|
userRepository.getUserWithUsernameAndServer(username, userAttributes.serverUrl)
|
||||||
} else if (internalId != null) {
|
} else if (userAttributes.id != null) {
|
||||||
userRepository.getUserWithId(internalId)
|
userRepository.getUserWithId(userAttributes.id)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = UserNgEntity()
|
user = createUser(
|
||||||
user.baseUrl = serverUrl
|
username,
|
||||||
user.username = username
|
userAttributes
|
||||||
user.token = token
|
)
|
||||||
if (!TextUtils.isEmpty(displayName)) {
|
|
||||||
user.displayName = displayName
|
|
||||||
}
|
|
||||||
if (pushConfigurationState != null) {
|
|
||||||
user.pushConfigurationState = LoganSquare
|
|
||||||
.parse(pushConfigurationState, PushConfigurationState::class.java)
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(userId)) {
|
|
||||||
user.userId = userId
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(capabilities)) {
|
|
||||||
user.capabilities = LoganSquare.parse(capabilities, Capabilities::class.java)
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(certificateAlias)) {
|
|
||||||
user.clientCertificate = certificateAlias
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(externalSignalingServer)) {
|
|
||||||
user.externalSignalingServer = LoganSquare
|
|
||||||
.parse(externalSignalingServer, ExternalSignalingServer::class.java)
|
|
||||||
}
|
|
||||||
user.current = true
|
|
||||||
} else {
|
} else {
|
||||||
if (userId != null && (user.userId == null || user.userId != userId)) {
|
updateUserData(
|
||||||
user.userId = userId
|
user,
|
||||||
}
|
userAttributes
|
||||||
if (token != null && token != user.token) {
|
)
|
||||||
user.token = token
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
displayName != null &&
|
|
||||||
user.displayName == null ||
|
|
||||||
displayName != null &&
|
|
||||||
(user.displayName != null) &&
|
|
||||||
displayName != user.displayName
|
|
||||||
) {
|
|
||||||
user.displayName = displayName
|
|
||||||
}
|
|
||||||
if (pushConfigurationState != null) {
|
|
||||||
val newPushConfigurationState = LoganSquare
|
|
||||||
.parse(pushConfigurationState, PushConfigurationState::class.java)
|
|
||||||
if (newPushConfigurationState != user.pushConfigurationState) {
|
|
||||||
user.pushConfigurationState = newPushConfigurationState
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (capabilities != null) {
|
|
||||||
val newCapabilities = LoganSquare.parse(capabilities, Capabilities::class.java)
|
|
||||||
if (newCapabilities != user.capabilities) {
|
|
||||||
user.capabilities = newCapabilities
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (certificateAlias != null && certificateAlias != user.clientCertificate) {
|
|
||||||
user.clientCertificate = certificateAlias
|
|
||||||
}
|
|
||||||
if (externalSignalingServer != null) {
|
|
||||||
val newExternalSignalingServer = LoganSquare
|
|
||||||
.parse(externalSignalingServer, ExternalSignalingServer::class.java)
|
|
||||||
if (newExternalSignalingServer != user.externalSignalingServer) {
|
|
||||||
user.externalSignalingServer = newExternalSignalingServer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (currentUser != null) {
|
|
||||||
user.current = currentUser
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
userRepository.insertUser(user)
|
userRepository.insertUser(user)
|
||||||
return userRepository.getUserWithIdLiveData(user.id)
|
return userRepository.getUserWithIdLiveData(user.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateUserData(user: UserNgEntity, userAttributes: UserAttributes) {
|
||||||
|
updateUserIdIfNeeded(userAttributes, user)
|
||||||
|
updateTokenIfNeeded(userAttributes, user)
|
||||||
|
updateDisplayNameIfNeeded(userAttributes, user)
|
||||||
|
updatePushConfigurationStateIfNeeded(userAttributes, user)
|
||||||
|
updateCapabilitiesIfNeeded(userAttributes, user)
|
||||||
|
updateCertificateAliasIfNeeded(userAttributes, user)
|
||||||
|
updateExternalSignalingServerIfNeeded(userAttributes, user)
|
||||||
|
updateCurrentUserStatusIfNeeded(userAttributes, user)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCurrentUserStatusIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.currentUser != null) {
|
||||||
|
user.current = userAttributes.currentUser
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateExternalSignalingServerIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.externalSignalingServer != null) {
|
||||||
|
val newExternalSignalingServer = LoganSquare
|
||||||
|
.parse(userAttributes.externalSignalingServer, ExternalSignalingServer::class.java)
|
||||||
|
if (newExternalSignalingServer != user.externalSignalingServer) {
|
||||||
|
user.externalSignalingServer = newExternalSignalingServer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCertificateAliasIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.certificateAlias != null && userAttributes.certificateAlias != user.clientCertificate) {
|
||||||
|
user.clientCertificate = userAttributes.certificateAlias
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCapabilitiesIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.capabilities != null) {
|
||||||
|
val newCapabilities = LoganSquare.parse(userAttributes.capabilities, Capabilities::class.java)
|
||||||
|
if (newCapabilities != user.capabilities) {
|
||||||
|
user.capabilities = newCapabilities
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updatePushConfigurationStateIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.pushConfigurationState != null) {
|
||||||
|
val newPushConfigurationState = LoganSquare
|
||||||
|
.parse(userAttributes.pushConfigurationState, PushConfigurationState::class.java)
|
||||||
|
if (newPushConfigurationState != user.pushConfigurationState) {
|
||||||
|
user.pushConfigurationState = newPushConfigurationState
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateDisplayNameIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (validDisplayName(userAttributes.displayName, user)) {
|
||||||
|
user.displayName = userAttributes.displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateTokenIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.token != null && userAttributes.token != user.token) {
|
||||||
|
user.token = userAttributes.token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateUserIdIfNeeded(userAttributes: UserAttributes, user: UserNgEntity) {
|
||||||
|
if (userAttributes.userId != null && (user.userId == null || user.userId != userAttributes.userId)) {
|
||||||
|
user.userId = userAttributes.userId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createUser(username: String?, userAttributes: UserAttributes): UserNgEntity {
|
||||||
|
val user = UserNgEntity()
|
||||||
|
user.baseUrl = userAttributes.serverUrl
|
||||||
|
user.username = username
|
||||||
|
user.token = userAttributes.token
|
||||||
|
if (!TextUtils.isEmpty(userAttributes.displayName)) {
|
||||||
|
user.displayName = userAttributes.displayName
|
||||||
|
}
|
||||||
|
if (userAttributes.pushConfigurationState != null) {
|
||||||
|
user.pushConfigurationState = LoganSquare
|
||||||
|
.parse(userAttributes.pushConfigurationState, PushConfigurationState::class.java)
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(userAttributes.userId)) {
|
||||||
|
user.userId = userAttributes.userId
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(userAttributes.capabilities)) {
|
||||||
|
user.capabilities = LoganSquare.parse(userAttributes.capabilities, Capabilities::class.java)
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(userAttributes.certificateAlias)) {
|
||||||
|
user.clientCertificate = userAttributes.certificateAlias
|
||||||
|
}
|
||||||
|
if (!TextUtils.isEmpty(userAttributes.externalSignalingServer)) {
|
||||||
|
user.externalSignalingServer = LoganSquare
|
||||||
|
.parse(userAttributes.externalSignalingServer, ExternalSignalingServer::class.java)
|
||||||
|
}
|
||||||
|
user.current = true
|
||||||
|
return user
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validDisplayName(displayName: String?, user: UserNgEntity): Boolean {
|
||||||
|
return if (displayName == null) {
|
||||||
|
false
|
||||||
|
} else {
|
||||||
|
user.displayName == null || user.displayName != null && displayName != user.displayName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class UserAttributes(
|
||||||
|
val id: Long?,
|
||||||
|
val serverUrl: String?,
|
||||||
|
val currentUser: Boolean?,
|
||||||
|
val userId: String?,
|
||||||
|
val token: String?,
|
||||||
|
val displayName: String?,
|
||||||
|
val pushConfigurationState: String?,
|
||||||
|
val capabilities: String?,
|
||||||
|
val certificateAlias: String?,
|
||||||
|
val externalSignalingServer: String?
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user