Skip to content
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

refactor: process conversation MLS message add event - WPB-10172 #2120

Closed

Conversation

jullianm
Copy link
Contributor

@jullianm jullianm commented Nov 4, 2024

WPB-10172

Key points

This PR is part of the quick sync refactoring plan and is related to processing the multiple events we receive from the backend or the push channel.

Specifically, this PR is about porting the existing implementation of the ConversationMLSMessageAdd event.

Testing

UTs cover the following use cases, ensuring that

  • the event is correctly processed
  • the MLS message is correctly decrypted and added to a conversation

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

@echoes-hq echoes-hq bot added the echoes: technical-roadmap/technical-debt More specific category, to highlight Technical Debt being tackled. label Nov 4, 2024
senderDomain: senderDomain,
date: date
)

Copy link
Contributor Author

@jullianm jullianm Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In legacy code, we were handling MLS message decryption and decrypted message processing in two different places :

EventDecoder+MLS would first decode the MLS message add event payload and decrypt the MLS message.

Then, new events with the decrypted message would be manually created and propagated so the ClientMessageRequestStrategy would consume them.

managedObjectContext: context
)

} else if messageClass is ZMAssetClientMessage.Type {
Copy link
Contributor Author

@jullianm jullianm Nov 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is quite big because the same code is used to handle multiple events, typically here I assume this line is meant to handle the "conversation.otr-asset-add" . I kept it although we don't seem to handle that event currently.

Note: We'll reuse many methods (including this one) to handle a proteus message.

/// Adds a message to a given conversation.
/// - parameter messageType: The type of message to add (MLS or Proteus)
// TODO: [WPB-11839] move to MessageRepository
func addMessage(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will all be moved to MessageRepository when the related PR is merged.

@@ -22,7 +22,7 @@ import Foundation
@objc public enum MessageConfirmationType: Int16 {
case delivered, read

static func convert(_ zmConfirmationType: Confirmation.TypeEnum) -> MessageConfirmationType {
public static func convert(_ zmConfirmationType: Confirmation.TypeEnum) -> MessageConfirmationType {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many legacy methods were made public to facilitate the work in this PR (not ideal but could be adjusted later on). Conversely, a lot of existing logic was factored out when we had no other option (e.g some legacy methods would take a ZMUpdatedEvent as parameter).

Copy link
Collaborator

@netbe netbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to split up the ConversationLocalStore+MLS somehow, happy to discuss it further

genericMessage: GenericMessage,
senderID: UUID,
date: Date
) -> Bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for not having this method throw instead of relying on Bool?

Comment on lines 360 to 396
private func getGenericMessage(
from base64Message: String,
senderID: UUID,
senderDomain: String,
date: Date?,
conversation: ZMConversation,
logAttributes: LogAttributes
) async -> (GenericMessage, GenericMessage.OneOf_Content)? {
guard let genericMessage = GenericMessage(withBase64String: base64Message),
let content = genericMessage.content else {

if let sender = try? await userLocalStore.fetchUser(
with: senderID,
domain: senderDomain
) {
let systemMessage = SystemMessage(
type: .invalid,
sender: sender,
timestamp: date ?? .now
)

await addSystemMessage(
systemMessage,
to: conversation
)
}

WireLogger.eventProcessing.warn(
"Can't read protobuf, abort processing",
attributes: logAttributes
)

return nil
}

return (genericMessage, content)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method is doing two things extracting the message and adding a systemmessage, it would be great to separate the two

Copy link
Contributor

Test Results

2 196 tests   2 196 ✅  6m 10s ⏱️
  297 suites      0 💤
    3 files        0 ❌

Results for commit 0bc3353.

@jullianm
Copy link
Contributor Author

closed, a single PR was opened for both MLS/Proteus add message events.

@jullianm jullianm closed this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: technical-roadmap/technical-debt More specific category, to highlight Technical Debt being tackled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants