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 proteus/MLS message add event - WPB-10174 #2164

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,18 @@ struct ConversationMLSMessageAddEventDecoder {
Payload.self,
forKey: .payload
)

let timestamp = try container.decodeIfPresent(
UTCTimeMillis.self,
forKey: .timestamp
)

return ConversationMLSMessageAddEvent(
conversationID: conversationID,
senderID: senderID,
subconversation: subconversation,
message: payload.text
message: payload.text,
timestamp: timestamp?.date
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ struct ConversationProteusMessageAddEventDecoder {
conversationID: conversationID,
senderID: senderID,
timestamp: timestamp.date,
message: .ciphertext(payload.text),
externalData: payload.data.map { .ciphertext($0) },
message: .init(encryptedMessage: payload.text),
externalData: payload.data.map { .init(encryptedMessage: $0) },
messageSenderClientID: payload.sender,
messageRecipientClientID: payload.recipient
)
Expand Down
6 changes: 3 additions & 3 deletions WireAPI/Sources/WireAPI/Models/Messaging/MessageContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import Foundation
/// The contents of a message, typically as a base-64 encoded
/// Protobuf string.

public enum MessageContent: Equatable, Codable {
public struct MessageContent: Equatable, Codable, Sendable {

/// Encrypted message content.

case ciphertext(String)
public let encryptedMessage: String

/// Unencrypted message content.

case plaintext(String)
public var decryptedMessage: String?

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@ import Foundation

/// An event where an mls message was received in a conversation.

public struct ConversationMLSMessageAddEvent: Equatable, Codable {
public struct ConversationMLSMessageAddEvent: Equatable, Codable, Sendable {

public struct DecryptedMessage: Equatable, Codable, Sendable {

public let message: String

public let senderClientID: String?

public init(
message: String,
senderClientID: String?
) {
self.message = message
self.senderClientID = senderClientID
}
}

/// The id of the conversation.

Expand All @@ -41,5 +56,14 @@ public struct ConversationMLSMessageAddEvent: Equatable, Codable {
/// The base 64 encoded message.

public let message: String

/// The date the message was received.

public let timestamp: Date?

/// The decrypted current message + decrypted buffered messages
/// along with the related sender client ID for each message.

public var decryptedMessages: [DecryptedMessage] = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

similar to the Proteus add event with the message content property, this property will be filled in the decryptor when the message + buffered messages are decrypted


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// An event where a proteus message was received in a conversation.

public struct ConversationProteusMessageAddEvent: Equatable, Codable {
public struct ConversationProteusMessageAddEvent: Equatable, Codable, Sendable {

/// The id of the conversation.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ private enum Scaffolding {
conversationID: conversationID,
senderID: senderID,
timestamp: timestamp,
message: .ciphertext("foo"),
externalData: .ciphertext("bar"),
message: .init(encryptedMessage: "foo"),
externalData: .init(encryptedMessage: "bar"),
messageSenderClientID: "abc123",
messageRecipientClientID: "def456"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ final class ConversationEventDecodingTests: XCTestCase {
conversationID: conversationID,
senderID: senderID,
subconversation: "subconversation",
message: "message"
message: "message",
timestamp: fractionalDate(from: "2024-06-04T15:03:07.598Z")
)

static let mlsWelcomeEvent = ConversationMLSWelcomeEvent(
Expand All @@ -471,8 +472,8 @@ final class ConversationEventDecodingTests: XCTestCase {
conversationID: conversationID,
senderID: senderID,
timestamp: timestamp,
message: .ciphertext("foo"),
externalData: .ciphertext("bar"),
message: .init(encryptedMessage: "foo"),
externalData: .init(encryptedMessage: "bar"),
messageSenderClientID: "abc123",
messageRecipientClientID: "def456"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"subconv": "subconversation",
"data": {
"text": "message"
}
},
"time": "2024-06-04T15:03:07.598Z"
}
Loading
Loading