-
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
fix(mls-migration): set correct CS when Kalium start migration (WPB-9638) #2812
Closed
mchenani
wants to merge
13
commits into
release/android-cycle-4.6
from
fix/set-correct-cs-when-kalium-start-migration
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ab77a2b
feat: use case to send button action confirmations (WPB-2633) (#2393)
mythsunwind efa9e5b
chore: Add more logging when client is registered (#2542)
mythsunwind 68efca9
fix: Solved merge conflict that removed PR 2393 and 2377 (#2547)
mythsunwind d4b789f
feat: Testservice can send typing events [WPB-6841] (#2545)
mythsunwind 98a2894
feat: testservice can return message receipts [WPB-7414] (#2694)
mythsunwind 28eea95
fix: Image metadata in kalium testservice was inverted (WPB-7191) (#2…
mythsunwind 8aff175
fix(mls): respect default protocol when mls is supported on backend
mchenani 86e11e1
check if mls is enabled to run migration
mchenani 7d3b312
feat: Testservice can create MLS group conversations (WPB-9185)
mythsunwind 48ffe0d
Get latest changes from release/android-cycle-4.6
mythsunwind 8c9a70c
Always use MLS protocol and print future participants
mythsunwind 5fc6a32
fix(mls-migration): setting correct CS when Kalium start the migration
mchenani 75db67d
Merge branch 'testservice-release-cycle-4.6' into fix/set-correct-cs-…
mchenani 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
79 changes: 79 additions & 0 deletions
79
...wire/kalium/logic/feature/message/composite/SendButtonActionConfirmationMessageUseCase.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,79 @@ | ||
/* | ||
* 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.message.composite | ||
|
||
import com.benasher44.uuid.uuid4 | ||
import com.wire.kalium.logic.CoreFailure | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.message.Message | ||
import com.wire.kalium.logic.data.message.MessageContent | ||
import com.wire.kalium.logic.data.user.UserId | ||
import com.wire.kalium.logic.data.id.CurrentClientIdProvider | ||
import com.wire.kalium.logic.feature.message.MessageSender | ||
import com.wire.kalium.logic.data.message.MessageTarget | ||
import com.wire.kalium.logic.functional.flatMap | ||
import com.wire.kalium.logic.functional.fold | ||
import com.wire.kalium.logic.sync.SyncManager | ||
import com.wire.kalium.util.DateTimeUtil | ||
|
||
/** | ||
* Use case for sending a button action message. | ||
* @param conversationId The conversation id. | ||
* @param messageId The id of the message that contains the button. | ||
* @param buttonId The id of the button. | ||
* | ||
* the action message is sent only to the message original sender. | ||
*/ | ||
class SendButtonActionConfirmationMessageUseCase internal constructor( | ||
private val messageSender: MessageSender, | ||
private val syncManager: SyncManager, | ||
private val currentClientIdProvider: CurrentClientIdProvider, | ||
private val selfUserId: UserId | ||
) { | ||
suspend operator fun invoke( | ||
conversationId: ConversationId, | ||
messageId: String, | ||
buttonId: String, | ||
userIds: List<UserId> | ||
): Result = syncManager.waitUntilLiveOrFailure().flatMap { | ||
currentClientIdProvider().flatMap { currentClientId -> | ||
val regularMessage = Message.Signaling( | ||
id = uuid4().toString(), | ||
content = MessageContent.ButtonActionConfirmation( | ||
referencedMessageId = messageId, | ||
buttonId = buttonId | ||
), | ||
conversationId = conversationId, | ||
date = DateTimeUtil.currentIsoDateTimeString(), | ||
senderUserId = selfUserId, | ||
senderClientId = currentClientId, | ||
status = Message.Status.Pending, | ||
isSelfMessage = true, | ||
expirationData = null | ||
) | ||
messageSender.sendMessage(regularMessage, messageTarget = MessageTarget.Users(userIds)) | ||
} | ||
}.fold(Result::Failure, { Result.Success }) | ||
|
||
sealed interface Result { | ||
data object Success : Result | ||
data class Failure( | ||
val error: CoreFailure | ||
) : Result | ||
} | ||
} |
122 changes: 122 additions & 0 deletions
122
...onMain/kotlin/com/wire/kalium/logic/feature/message/composite/SendButtonMessageUseCase.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,122 @@ | ||
/* | ||
* 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.message.composite | ||
|
||
import com.benasher44.uuid.uuid4 | ||
import com.wire.kalium.logic.CoreFailure | ||
import com.wire.kalium.logic.data.id.ConversationId | ||
import com.wire.kalium.logic.data.id.CurrentClientIdProvider | ||
import com.wire.kalium.logic.data.id.QualifiedID | ||
import com.wire.kalium.logic.data.message.Message | ||
import com.wire.kalium.logic.data.message.MessageContent | ||
import com.wire.kalium.logic.data.message.PersistMessageUseCase | ||
import com.wire.kalium.logic.data.message.mention.MessageMention | ||
import com.wire.kalium.logic.data.properties.UserPropertyRepository | ||
import com.wire.kalium.logic.data.sync.SlowSyncRepository | ||
import com.wire.kalium.logic.data.sync.SlowSyncStatus | ||
import com.wire.kalium.logic.feature.message.MessageSendFailureHandler | ||
import com.wire.kalium.logic.feature.message.MessageSender | ||
import com.wire.kalium.logic.functional.Either | ||
import com.wire.kalium.logic.functional.flatMap | ||
import com.wire.kalium.logic.functional.onFailure | ||
import com.wire.kalium.util.DateTimeUtil | ||
import com.wire.kalium.util.KaliumDispatcher | ||
import com.wire.kalium.util.KaliumDispatcherImpl | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.flow.first | ||
|
||
@Suppress("LongParameterList") | ||
/** | ||
* @sample samples.logic.MessageUseCases.sendingBasicTextMessage | ||
* @sample samples.logic.MessageUseCases.sendingTextMessageWithMentions | ||
*/ | ||
class SendButtonMessageUseCase internal constructor( | ||
private val persistMessage: PersistMessageUseCase, | ||
private val selfUserId: QualifiedID, | ||
private val provideClientId: CurrentClientIdProvider, | ||
private val slowSyncRepository: SlowSyncRepository, | ||
private val messageSender: MessageSender, | ||
private val messageSendFailureHandler: MessageSendFailureHandler, | ||
private val userPropertyRepository: UserPropertyRepository, | ||
private val dispatchers: KaliumDispatcher = KaliumDispatcherImpl, | ||
private val scope: CoroutineScope | ||
) { | ||
|
||
suspend operator fun invoke( | ||
conversationId: ConversationId, | ||
text: String, | ||
mentions: List<MessageMention> = emptyList(), | ||
quotedMessageId: String? = null, | ||
buttons: List<String> = listOf() | ||
): Either<CoreFailure, Unit> = scope.async(dispatchers.io) { | ||
slowSyncRepository.slowSyncStatus.first { | ||
it is SlowSyncStatus.Complete | ||
} | ||
|
||
val generatedMessageUuid = uuid4().toString() | ||
val expectsReadConfirmation = userPropertyRepository.getReadReceiptsStatus() | ||
|
||
provideClientId().flatMap { clientId -> | ||
val textContent = MessageContent.Text( | ||
value = text, | ||
mentions = mentions, | ||
quotedMessageReference = quotedMessageId?.let { quotedMessageId -> | ||
MessageContent.QuoteReference( | ||
quotedMessageId = quotedMessageId, | ||
quotedMessageSha256 = null, | ||
isVerified = true | ||
) | ||
} | ||
) | ||
|
||
val transform: (String) -> MessageContent.Composite.Button = { MessageContent.Composite.Button(it, it, false) } | ||
val buttonContent = buttons.map(transform) | ||
val content = MessageContent.Composite(textContent, buttonContent) | ||
|
||
val message = Message.Regular( | ||
id = generatedMessageUuid, | ||
content = content, | ||
expectsReadConfirmation = expectsReadConfirmation, | ||
conversationId = conversationId, | ||
date = DateTimeUtil.currentIsoDateTimeString(), | ||
senderUserId = selfUserId, | ||
senderClientId = clientId, | ||
status = Message.Status.Pending, | ||
editStatus = Message.EditStatus.NotEdited, | ||
// According to proto Ephemeral it is not possible to send a Composite message with timer | ||
expirationData = null, | ||
isSelfMessage = true | ||
) | ||
persistMessage(message).flatMap { | ||
messageSender.sendMessage(message) | ||
} | ||
}.onFailure { | ||
messageSendFailureHandler.handleFailureAndUpdateMessageStatus( | ||
failure = it, | ||
conversationId = conversationId, | ||
messageId = generatedMessageUuid, | ||
messageType = TYPE | ||
) | ||
} | ||
}.await() | ||
|
||
companion object { | ||
const val TYPE = "Text" | ||
} | ||
} |
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.
is it fine to log the full group id here ?
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.
yes. there is no harm in it. hmm, but I can remove it if we want.