-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add and remove conversation favorite [WPB-11639] #3119
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9581014
feat: manage favorite folder
Garzas 1cf021a
Merge branch 'develop' into feat/manage-favorite-folder
Garzas 282d0f0
feat: add and remove favorite folder
Garzas c8eef8a
remove unused error class
Garzas 761f2bc
Merge branch 'develop' into feat/manage-favorite-folder
Garzas 963fa13
Merge branch 'develop' into feat/manage-favorite-folder
Garzas 8630eb2
review fixes
Garzas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also breaking the separation of concerns.
We can have this logic in a use case, as it's responsible for orchestrating business logic.