-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add and remove conversation favorite [WPB-11639] (#3119)
* feat: manage favorite folder * feat: add and remove favorite folder * remove unused error class * review fixes
- Loading branch information
Showing
28 changed files
with
1,092 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...in/com/wire/kalium/logic/feature/conversation/folder/AddConversationToFavoritesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* 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.CoreFailure | ||
import com.wire.kalium.logic.data.conversation.folders.ConversationFolderRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.functional.flatMap | ||
import com.wire.kalium.logic.functional.fold | ||
import com.wire.kalium.util.KaliumDispatcher | ||
import com.wire.kalium.util.KaliumDispatcherImpl | ||
import kotlinx.coroutines.withContext | ||
|
||
/** | ||
* This use case will add a conversation to the favorites folder. | ||
*/ | ||
interface AddConversationToFavoritesUseCase { | ||
/** | ||
* @param conversationId the id of the conversation | ||
* @return the [Result] indicating a successful operation, otherwise a [CoreFailure] | ||
*/ | ||
suspend operator fun invoke(conversationId: ConversationId): Result | ||
|
||
sealed interface Result { | ||
data object Success : Result | ||
data class Failure(val cause: CoreFailure) : Result | ||
} | ||
} | ||
|
||
internal class AddConversationToFavoritesUseCaseImpl( | ||
private val conversationFolderRepository: ConversationFolderRepository, | ||
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl | ||
) : AddConversationToFavoritesUseCase { | ||
override suspend fun invoke( | ||
conversationId: ConversationId | ||
): AddConversationToFavoritesUseCase.Result = withContext(dispatchers.io) { | ||
conversationFolderRepository.getFavoriteConversationFolder().fold( | ||
{ AddConversationToFavoritesUseCase.Result.Failure(it) }, | ||
{ folder -> | ||
conversationFolderRepository.addConversationToFolder( | ||
conversationId, | ||
folder.id | ||
) | ||
.flatMap { | ||
conversationFolderRepository.syncConversationFoldersFromLocal() | ||
} | ||
.fold({ | ||
AddConversationToFavoritesUseCase.Result.Failure(it) | ||
}, { | ||
AddConversationToFavoritesUseCase.Result.Success | ||
}) | ||
} | ||
) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...m/wire/kalium/logic/feature/conversation/folder/RemoveConversationFromFavoritesUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.CoreFailure | ||
import com.wire.kalium.logic.data.conversation.folders.ConversationFolderRepository | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.functional.flatMap | ||
import com.wire.kalium.logic.functional.fold | ||
import com.wire.kalium.util.KaliumDispatcher | ||
import com.wire.kalium.util.KaliumDispatcherImpl | ||
import kotlinx.coroutines.withContext | ||
|
||
/** | ||
* This use case will remove a conversation from the favorites folder. | ||
*/ | ||
interface RemoveConversationFromFavoritesUseCase { | ||
/** | ||
* @param conversationId the id of the conversation | ||
* @return the [Result] indicating a successful operation, otherwise a [CoreFailure] | ||
*/ | ||
suspend operator fun invoke(conversationId: ConversationId): Result | ||
|
||
sealed interface Result { | ||
data object Success : Result | ||
data class Failure(val cause: CoreFailure) : Result | ||
} | ||
} | ||
|
||
internal class RemoveConversationFromFavoritesUseCaseImpl( | ||
private val conversationFolderRepository: ConversationFolderRepository, | ||
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl | ||
) : RemoveConversationFromFavoritesUseCase { | ||
override suspend fun invoke( | ||
conversationId: ConversationId | ||
): RemoveConversationFromFavoritesUseCase.Result = withContext(dispatchers.io) { | ||
conversationFolderRepository.getFavoriteConversationFolder().fold( | ||
{ RemoveConversationFromFavoritesUseCase.Result.Failure(it) }, | ||
{ folder -> | ||
conversationFolderRepository.removeConversationFromFolder(conversationId, folder.id) | ||
.flatMap { | ||
conversationFolderRepository.syncConversationFoldersFromLocal() | ||
} | ||
.fold({ | ||
RemoveConversationFromFavoritesUseCase.Result.Failure(it) | ||
}, { | ||
RemoveConversationFromFavoritesUseCase.Result.Success | ||
}) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.