From abcd037802987a6964464b7c0e96eac6e512bd4f Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Wed, 11 Dec 2024 12:04:16 +0100 Subject: [PATCH] feat: add usecase to get team url (WPB-14872) (#3157) * feat: add usecase to get team url * feat:detekt * feat: detekt * feat: detekt --- .../server/ServerConfigRepository.kt | 3 ++ .../kalium/logic/feature/UserSessionScope.kt | 8 +++++ .../logic/feature/server/GetTeamUrlUseCase.kt | 31 +++++++++++++++++++ .../kalium/persistence/ServerConfiguration.sq | 3 ++ .../daokaliumdb/ServerConfigurationDAO.kt | 7 +++++ 5 files changed, 52 insertions(+) create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/server/GetTeamUrlUseCase.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepository.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepository.kt index 4fd77d402b4..a09c8241f17 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepository.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/configuration/server/ServerConfigRepository.kt @@ -66,6 +66,7 @@ interface ServerConfigRepository { */ suspend fun configForUser(userId: UserId): Either suspend fun commonApiVersion(domain: String): Either + suspend fun getTeamUrlForUser(userId: UserId): String? } @Suppress("LongParameterList", "TooManyFunctions") @@ -165,4 +166,6 @@ internal class ServerConfigDataSource( is ApiVersionDTO.Valid -> Either.Right(it) } }.map { serverConfigMapper.fromDTO(it) } + + override suspend fun getTeamUrlForUser(userId: UserId): String? = dao.teamUrlForUser(userId.toDao()) } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index 543d5f9030c..3b40fb7cab4 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -291,6 +291,7 @@ import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveSelfDeletionTim import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveTeamSettingsSelfDeletingStatusUseCase import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveTeamSettingsSelfDeletingStatusUseCaseImpl import com.wire.kalium.logic.feature.selfDeletingMessages.PersistNewSelfDeletionTimerUseCaseImpl +import com.wire.kalium.logic.feature.server.GetTeamUrlUseCase import com.wire.kalium.logic.feature.service.ServiceScope import com.wire.kalium.logic.feature.session.GetProxyCredentialsUseCase import com.wire.kalium.logic.feature.session.GetProxyCredentialsUseCaseImpl @@ -2144,6 +2145,13 @@ class UserSessionScope internal constructor( kaliumLogger = userScopedLogger, ) + val getTeamUrlUseCase: GetTeamUrlUseCase by lazy { + GetTeamUrlUseCase( + userId, + authenticationScope.serverConfigRepository, + ) + } + /** * This will start subscribers of observable work per user session, as long as the user is logged in. * When the user logs out, this work will be canceled. diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/server/GetTeamUrlUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/server/GetTeamUrlUseCase.kt new file mode 100644 index 00000000000..fc11e34b573 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/server/GetTeamUrlUseCase.kt @@ -0,0 +1,31 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.kalium.logic.feature.server + +import com.wire.kalium.logic.configuration.server.ServerConfigRepository +import com.wire.kalium.logic.data.user.UserId + +/** + * Use case to get the team url for the current user. + */ +class GetTeamUrlUseCase internal constructor( + private val selfUserId: UserId, + private val serverConfigRepository: ServerConfigRepository +) { + suspend operator fun invoke(): String = serverConfigRepository.getTeamUrlForUser(selfUserId) ?: "" +} diff --git a/persistence/src/commonMain/db_global/com/wire/kalium/persistence/ServerConfiguration.sq b/persistence/src/commonMain/db_global/com/wire/kalium/persistence/ServerConfiguration.sq index 4fa81bcab28..dfcd7807ffd 100644 --- a/persistence/src/commonMain/db_global/com/wire/kalium/persistence/ServerConfiguration.sq +++ b/persistence/src/commonMain/db_global/com/wire/kalium/persistence/ServerConfiguration.sq @@ -56,6 +56,9 @@ SELECT * FROM ServerConfiguration WHERE title = ? AND apiBaseUrl = ? AND webSock getByUser: SELECT * FROM ServerConfiguration WHERE id = (SELECT server_config_id FROM Accounts WHERE id = :userId); +getTeamUrlByUser: +SELECT teamsUrl FROM ServerConfiguration WHERE id = (SELECT server_config_id FROM Accounts WHERE id = :userId); + getServerConfigsWithAccIdWithLastCheckBeforeDate: SELECT sc.*, acc.id FROM Accounts AS acc LEFT JOIN ServerConfiguration AS sc ON acc.server_config_id == sc.id diff --git a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAO.kt b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAO.kt index 04c83e96f77..00b56040372 100644 --- a/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAO.kt +++ b/persistence/src/commonMain/kotlin/com/wire/kalium/persistence/daokaliumdb/ServerConfigurationDAO.kt @@ -118,6 +118,7 @@ internal object ServerConfigMapper { ) } +@Suppress("TooManyFunctions") interface ServerConfigurationDAO { suspend fun deleteById(id: String) suspend fun insert(insertData: InsertData) @@ -129,6 +130,7 @@ interface ServerConfigurationDAO { suspend fun updateServerMetaData(id: String, federation: Boolean, commonApiVersion: Int) suspend fun updateApiVersionAndDomain(id: String, domain: String, commonApiVersion: Int) suspend fun configForUser(userId: UserIDEntity): ServerConfigEntity? + suspend fun teamUrlForUser(userId: UserIDEntity): String? suspend fun setFederationToTrue(id: String) suspend fun getServerConfigsWithAccIdWithLastCheckBeforeDate(date: String): Flow> suspend fun updateBlackListCheckDate(configIds: Set, date: String) @@ -152,6 +154,7 @@ interface ServerConfigurationDAO { ) } +@Suppress("TooManyFunctions") internal class ServerConfigurationDAOImpl internal constructor( private val queries: ServerConfigurationQueries, private val queriesContext: CoroutineContext, @@ -240,4 +243,8 @@ internal class ServerConfigurationDAOImpl internal constructor( override suspend fun updateBlackListCheckDate(configIds: Set, date: String) = withContext(queriesContext) { queries.updateLastBlackListCheckByIds(date, configIds) } + + override suspend fun teamUrlForUser(userId: UserIDEntity): String? = withContext(queriesContext) { + queries.getTeamUrlByUser(userId).executeAsOneOrNull() + } }