Skip to content

Commit

Permalink
Merge branch 'develop' into feat/need-to-remove-locally-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
yamilmedina authored Dec 13, 2024
2 parents ef01333 + 5396afa commit 375400a
Show file tree
Hide file tree
Showing 27 changed files with 297 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/label-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ jobs:
name: Label PR based on title
runs-on: ubuntu-latest
steps:
- uses: srvaroa/labeler@v1.8.2
- uses: srvaroa/labeler@v1.12.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
*/
package com.wire.kalium.logic.data.conversation

enum class ConversationFilter {
ALL,
FAVORITES,
GROUPS,
ONE_ON_ONE
import kotlinx.serialization.Serializable

@Serializable
sealed class ConversationFilter {
@Serializable
data object All : ConversationFilter()

@Serializable
data object Favorites : ConversationFilter()

@Serializable
data object Groups : ConversationFilter()

@Serializable
data object OneOnOne : ConversationFilter()

@Serializable
data class Folder(val folderName: String, val folderId: String) : ConversationFilter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
package com.wire.kalium.logic.data.conversation

import com.wire.kalium.logic.data.id.QualifiedID
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ConversationFolder(
val id: String,
val name: String,
val type: FolderType
@SerialName("id") val id: String,
@SerialName("name") val name: String,
@SerialName("folder_type") val type: FolderType
)

data class FolderWithConversations(
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ pbandk = "0.14.2"
turbine = "1.1.0"
avs = "9.10.16"
jna = "5.14.0"
core-crypto = "2.0.0"
core-crypto = "3.0.0"
core-crypto-multiplatform = "0.6.0-rc.3-multiplatform-pre1"
completeKotlin = "1.1.0"
desugar-jdk = "2.0.4"
kermit = "2.0.3"
detekt = "1.23.6"
detekt = "1.23.7"
agp = "8.5.2"
dokka = "1.8.20"
carthage = "0.0.1"
Expand Down
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 @@ -676,15 +676,16 @@ internal fun ConversationEntity.VerificationStatus.toModel(): Conversation.Verif
}

internal fun ConversationFilter.toDao(): ConversationFilterEntity = when (this) {
ConversationFilter.ALL -> ConversationFilterEntity.ALL
ConversationFilter.FAVORITES -> ConversationFilterEntity.FAVORITES
ConversationFilter.GROUPS -> ConversationFilterEntity.GROUPS
ConversationFilter.ONE_ON_ONE -> ConversationFilterEntity.ONE_ON_ONE
ConversationFilter.All -> ConversationFilterEntity.ALL
ConversationFilter.Favorites -> ConversationFilterEntity.FAVORITES
ConversationFilter.Groups -> ConversationFilterEntity.GROUPS
ConversationFilter.OneOnOne -> ConversationFilterEntity.ONE_ON_ONE
is ConversationFilter.Folder -> ConversationFilterEntity.ALL // TODO think how to secure that
}

internal fun ConversationFilterEntity.toModel(): ConversationFilter = when (this) {
ConversationFilterEntity.ALL -> ConversationFilter.ALL
ConversationFilterEntity.FAVORITES -> ConversationFilter.FAVORITES
ConversationFilterEntity.GROUPS -> ConversationFilter.GROUPS
ConversationFilterEntity.ONE_ON_ONE -> ConversationFilter.ONE_ON_ONE
ConversationFilterEntity.ALL -> ConversationFilter.All
ConversationFilterEntity.FAVORITES -> ConversationFilter.Favorites
ConversationFilterEntity.GROUPS -> ConversationFilter.Groups
ConversationFilterEntity.ONE_ON_ONE -> ConversationFilter.OneOnOne
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ interface ConversationRepository {
suspend fun observeConversationList(): Flow<List<Conversation>>
suspend fun observeConversationListDetails(
fromArchive: Boolean,
conversationFilter: ConversationFilter = ConversationFilter.ALL
conversationFilter: ConversationFilter = ConversationFilter.All
): Flow<List<ConversationDetails>>

suspend fun observeConversationListDetailsWithEvents(
fromArchive: Boolean = false,
conversationFilter: ConversationFilter = ConversationFilter.ALL
conversationFilter: ConversationFilter = ConversationFilter.All
): Flow<List<ConversationDetailsWithEvents>>

suspend fun getConversationIds(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ data class ConversationQueryConfig(
val fromArchive: Boolean = false,
val onlyInteractionEnabled: Boolean = false,
val newActivitiesOnTop: Boolean = false,
val conversationFilter: ConversationFilter = ConversationFilter.ALL,
val conversationFilter: ConversationFilter = ConversationFilter.All,
)
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.flatMap
import com.wire.kalium.logic.functional.flatMapLeft
import com.wire.kalium.logic.functional.map
import com.wire.kalium.logic.functional.mapRight
import com.wire.kalium.logic.functional.onFailure
import com.wire.kalium.logic.functional.onSuccess
import com.wire.kalium.logic.kaliumLogger
Expand All @@ -57,6 +58,7 @@ internal interface ConversationFolderRepository {
suspend fun addConversationToFolder(conversationId: QualifiedID, folderId: String): Either<CoreFailure, Unit>
suspend fun removeConversationFromFolder(conversationId: QualifiedID, folderId: String): Either<CoreFailure, Unit>
suspend fun syncConversationFoldersFromLocal(): Either<CoreFailure, Unit>
suspend fun observeUserFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>>
}

internal class ConversationFolderDataSource internal constructor(
Expand All @@ -72,7 +74,7 @@ internal class ConversationFolderDataSource internal constructor(
}

override suspend fun getFavoriteConversationFolder(): Either<CoreFailure, ConversationFolder> = wrapStorageRequest {
conversationFolderDAO.getFavoriteConversationFolder().toModel()
conversationFolderDAO.getFavoriteConversationFolder()?.toModel()
}

override suspend fun observeConversationsFromFolder(folderId: String): Flow<List<ConversationDetailsWithEvents>> =
Expand Down Expand Up @@ -152,4 +154,10 @@ internal class ConversationFolderDataSource internal constructor(
}
}
}

override suspend fun observeUserFolders(): Flow<Either<CoreFailure, List<ConversationFolder>>> {
return conversationFolderDAO.observeUserFolders()
.wrapStorageRequest()
.mapRight { folderEntities -> folderEntities.map { it.toModel() } }
}
}
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 @@ -1830,6 +1831,7 @@ class UserSessionScope internal constructor(
legalHoldHandler,
notificationTokenRepository,
this,
userStorage,
userScopedLogger,
)
}
Expand Down Expand Up @@ -2144,6 +2146,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
Expand Up @@ -55,6 +55,8 @@ import com.wire.kalium.logic.feature.conversation.folder.GetFavoriteFolderUseCas
import com.wire.kalium.logic.feature.conversation.folder.GetFavoriteFolderUseCaseImpl
import com.wire.kalium.logic.feature.conversation.folder.ObserveConversationsFromFolderUseCase
import com.wire.kalium.logic.feature.conversation.folder.ObserveConversationsFromFolderUseCaseImpl
import com.wire.kalium.logic.feature.conversation.folder.ObserveUserFoldersUseCase
import com.wire.kalium.logic.feature.conversation.folder.ObserveUserFoldersUseCaseImpl
import com.wire.kalium.logic.feature.conversation.folder.RemoveConversationFromFavoritesUseCase
import com.wire.kalium.logic.feature.conversation.folder.RemoveConversationFromFavoritesUseCaseImpl
import com.wire.kalium.logic.feature.conversation.guestroomlink.CanCreatePasswordProtectedLinksUseCase
Expand Down Expand Up @@ -361,4 +363,6 @@ class ConversationScope internal constructor(
get() = AddConversationToFavoritesUseCaseImpl(conversationFolderRepository)
val removeConversationFromFavorites: RemoveConversationFromFavoritesUseCase
get() = RemoveConversationFromFavoritesUseCaseImpl(conversationFolderRepository)
val observeUserFolders: ObserveUserFoldersUseCase
get() = ObserveUserFoldersUseCaseImpl(conversationFolderRepository)
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,26 @@ internal class ObserveConversationListDetailsWithEventsUseCaseImpl(
fromArchive: Boolean,
conversationFilter: ConversationFilter
): Flow<List<ConversationDetailsWithEvents>> {
return if (conversationFilter == ConversationFilter.FAVORITES) {
when (val result = getFavoriteFolder()) {
GetFavoriteFolderUseCase.Result.Failure -> {
flowOf(emptyList())
return when (conversationFilter) {
ConversationFilter.Favorites -> {
when (val result = getFavoriteFolder()) {
GetFavoriteFolderUseCase.Result.Failure -> {
flowOf(emptyList())
}

is GetFavoriteFolderUseCase.Result.Success ->
conversationFolderRepository.observeConversationsFromFolder(result.folder.id)
}
}

is GetFavoriteFolderUseCase.Result.Success -> conversationFolderRepository.observeConversationsFromFolder(result.folder.id)
is ConversationFilter.Folder -> {
conversationFolderRepository.observeConversationsFromFolder(conversationFilter.folderId)
}
} else {
conversationRepository.observeConversationListDetailsWithEvents(fromArchive, conversationFilter)

ConversationFilter.All,
ConversationFilter.Groups,
ConversationFilter.OneOnOne ->
conversationRepository.observeConversationListDetailsWithEvents(fromArchive, conversationFilter)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ package com.wire.kalium.logic.feature.conversation.folder

import com.wire.kalium.logic.data.conversation.ConversationDetailsWithEvents
import com.wire.kalium.logic.data.conversation.folders.ConversationFolderRepository
import com.wire.kalium.util.KaliumDispatcher
import com.wire.kalium.util.KaliumDispatcherImpl
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn

/**
* This use case will observe and return the list of conversations from given folder.
Expand All @@ -31,9 +34,10 @@ fun interface ObserveConversationsFromFolderUseCase {

internal class ObserveConversationsFromFolderUseCaseImpl(
private val conversationFolderRepository: ConversationFolderRepository,
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl
) : ObserveConversationsFromFolderUseCase {

override suspend operator fun invoke(folderId: String): Flow<List<ConversationDetailsWithEvents>> {
return conversationFolderRepository.observeConversationsFromFolder(folderId)
}
override suspend operator fun invoke(folderId: String): Flow<List<ConversationDetailsWithEvents>> =
conversationFolderRepository.observeConversationsFromFolder(folderId)
.flowOn(dispatchers.io)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.conversation.folder

import com.wire.kalium.logic.data.conversation.ConversationFolder
import com.wire.kalium.logic.data.conversation.folders.ConversationFolderRepository
import com.wire.kalium.logic.functional.mapToRightOr
import com.wire.kalium.util.KaliumDispatcher
import com.wire.kalium.util.KaliumDispatcherImpl
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn

/**
* This use case will observe and return the list of all user folders.
* @see ConversationFolder
*/
fun interface ObserveUserFoldersUseCase {
suspend operator fun invoke(): Flow<List<ConversationFolder>>
}

internal class ObserveUserFoldersUseCaseImpl(
private val conversationFolderRepository: ConversationFolderRepository,
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl
) : ObserveUserFoldersUseCase {

override suspend operator fun invoke(): Flow<List<ConversationFolder>> {
return conversationFolderRepository.observeUserFolders()
.mapToRightOr(emptyList())
.flowOn(dispatchers.io)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.debug

import com.wire.kalium.logic.di.UserStorage

class ChangeProfilingUseCase(
private val userStorage: UserStorage,
) {
/**
* Changes the profiling of the database (cipher_profile) if the profile is specified and the database is encrypted
* @param enabled true to enable profiling, false to disable
*/
operator fun invoke(enabled: Boolean) {
userStorage.database.changeProfiling(enabled)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.wire.kalium.logic.data.prekey.PreKeyRepository
import com.wire.kalium.logic.data.sync.SlowSyncRepository
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.di.UserStorage
import com.wire.kalium.logic.feature.message.MLSMessageCreator
import com.wire.kalium.logic.feature.message.MLSMessageCreatorImpl
import com.wire.kalium.logic.feature.message.MessageEnvelopeCreator
Expand Down Expand Up @@ -92,6 +93,7 @@ class DebugScope internal constructor(
private val legalHoldHandler: LegalHoldHandler,
private val notificationTokenRepository: NotificationTokenRepository,
private val scope: CoroutineScope,
userStorage: UserStorage,
logger: KaliumLogger,
internal val dispatcher: KaliumDispatcher = KaliumDispatcherImpl,
) {
Expand Down Expand Up @@ -224,4 +226,6 @@ class DebugScope internal constructor(
clientRepository,
notificationTokenRepository,
)

val changeProfiling: ChangeProfilingUseCase = ChangeProfilingUseCase(userStorage)
}
Loading

0 comments on commit 375400a

Please sign in to comment.