Skip to content

Commit

Permalink
feat: add usecase to get team url (WPB-14872) (#3157)
Browse files Browse the repository at this point in the history
* feat: add usecase to get team url

* feat:detekt

* feat: detekt

* feat: detekt
  • Loading branch information
ohassine authored Dec 11, 2024
1 parent 26b7d4b commit abcd037
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ interface ServerConfigRepository {
*/
suspend fun configForUser(userId: UserId): Either<StorageFailure, ServerConfig>
suspend fun commonApiVersion(domain: String): Either<CoreFailure, Int>
suspend fun getTeamUrlForUser(userId: UserId): String?
}

@Suppress("LongParameterList", "TooManyFunctions")
Expand Down Expand Up @@ -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())
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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) ?: ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal object ServerConfigMapper {
)
}

@Suppress("TooManyFunctions")
interface ServerConfigurationDAO {
suspend fun deleteById(id: String)
suspend fun insert(insertData: InsertData)
Expand All @@ -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<List<ServerConfigWithUserIdEntity>>
suspend fun updateBlackListCheckDate(configIds: Set<String>, date: String)
Expand All @@ -152,6 +154,7 @@ interface ServerConfigurationDAO {
)
}

@Suppress("TooManyFunctions")
internal class ServerConfigurationDAOImpl internal constructor(
private val queries: ServerConfigurationQueries,
private val queriesContext: CoroutineContext,
Expand Down Expand Up @@ -240,4 +243,8 @@ internal class ServerConfigurationDAOImpl internal constructor(
override suspend fun updateBlackListCheckDate(configIds: Set<String>, date: String) = withContext(queriesContext) {
queries.updateLastBlackListCheckByIds(date, configIds)
}

override suspend fun teamUrlForUser(userId: UserIDEntity): String? = withContext(queriesContext) {
queries.getTeamUrlByUser(userId).executeAsOneOrNull()
}
}

0 comments on commit abcd037

Please sign in to comment.