Skip to content

Commit

Permalink
refactor: process user events - WPB-9904 (#1953)
Browse files Browse the repository at this point in the history
Co-authored-by: François Benaiteau <[email protected]>
  • Loading branch information
jullianm and netbe authored Oct 4, 2024
1 parent 08a8467 commit 165e75b
Show file tree
Hide file tree
Showing 62 changed files with 2,231 additions and 1,065 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ public protocol ConversationsAPI {
/// Fetch conversation list with qualified identifiers.
func getConversations(for identifiers: [QualifiedID]) async throws -> ConversationList

/// Fetches a user MLS one to one conversation.
/// - parameters:
/// - userID: The user ID to fetch the MLS one to one conversation for.
/// - domain: The domain of the one to one conversation.

func getMLSOneToOneConversation(
userID: String,
in domain: String
) async throws -> Conversation

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ public enum ConversationsAPIError: Error {
/// Failure if http body is invalid.
case invalidBody

/// Unsupported endpoint for API version
case unsupportedEndpointForAPIVersion

/// MLS not enabled
case mlsNotEnabled

/// Users not connected
case usersNotConnected

/// Failure if user and domain are empty
case userAndDomainShouldNotBeEmpty

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ class ConversationsAPIV0: ConversationsAPI, VersionedAPI {
.failure(code: .badRequest, error: ConversationsAPIError.invalidBody)
.parse(response)
}

func getMLSOneToOneConversation(
userID: String,
in domain: String
) async throws -> Conversation {
throw ConversationsAPIError.unsupportedEndpointForAPIVersion
}
}

// MARK: Encodables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ class ConversationsAPIV5: ConversationsAPIV4 {
.success(code: .ok, type: QualifiedConversationListV5.self) // Change in v5
.parse(response)
}

override func getMLSOneToOneConversation(
userID: String,
in domain: String
) async throws -> Conversation {
guard !userID.isEmpty, !domain.isEmpty else {
throw ConversationsAPIError.userAndDomainShouldNotBeEmpty
}

let resourcePath = "\(pathPrefix)/conversations/one2one/\(domain)/\(userID)"

let request = HTTPRequest(
path: resourcePath,
method: .get
)

let response = try await httpClient.executeRequest(request)

return try ResponseParser()
.success(code: .ok, type: ConversationV5.self)
.failure(code: .badRequest, label: "mls-not-enabled", error: ConversationsAPIError.mlsNotEnabled)
.failure(code: .forbidden, label: "not-connected", error: ConversationsAPIError.usersNotConnected)
.parse(response)
}
}

// MARK: Decodables
Expand Down
20 changes: 19 additions & 1 deletion WireAPI/Sources/WireAPI/Models/Connection/Connection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import Foundation

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

/// Remote identifier of the sender

Expand Down Expand Up @@ -48,4 +48,22 @@ public struct Connection: Equatable, Codable {

public let status: ConnectionStatus

public init(
senderID: UUID?,
receiverID: UUID?,
receiverQualifiedID: QualifiedID?,
conversationID: UUID?,
qualifiedConversationID: QualifiedID?,
lastUpdate: Date,
status: ConnectionStatus
) {
self.senderID = senderID
self.receiverID = receiverID
self.receiverQualifiedID = receiverQualifiedID
self.conversationID = conversationID
self.qualifiedConversationID = qualifiedConversationID
self.lastUpdate = lastUpdate
self.status = status
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import Foundation

public enum ConnectionStatus: String, Codable, Equatable {
public enum ConnectionStatus: String, Codable, Equatable, Sendable {

/// The connection is complete and the conversation is in its normal state

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
//

/// A list of conversations categorized by status.
public struct ConversationList {
public struct ConversationList: Sendable {

/// Representing objects of resolved conversations.
public let found: [Conversation]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// A configuration for the *App Lock* feature.

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

/// The feature's status.

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

/// A configuration for the *Classified Domains* feature.

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

/// The feature's status.

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

/// A configuration for the *Conference Calling* feature.

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

/// The feature's status.

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

/// A configuration for the *Conversation Guest Links* feature.

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

/// The feature's status.

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

/// A configuration for the *Digital Signature* feature.

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

/// The feature's status.

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

/// A configuration for the *End To End Identity* feature.

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

/// The feature's status.

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

/// Configurations for various app features.

public enum FeatureConfig: Equatable, Codable {
public enum FeatureConfig: Equatable, Codable, Sendable {

/// Config for the *App Lock* feature.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Foundation
/// In other cases, `enabled` may mean that the feature
/// is turned on, because it is always available.

public enum FeatureConfigStatus: String, Codable {
public enum FeatureConfigStatus: String, Codable, Sendable {

case enabled
case disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// A configuration for the *File Sharing* feature.

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

/// The feature's status.

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

/// A configuration for the *MLS* feature.

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

/// The feature's status.

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

/// A configuration for the *MLS Migration* feature.

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

/// The feature's status.

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

/// A configuration for the *Self Deleting Messages* feature.

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

/// The feature's status.

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

/// An event where a feature config was updated.

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

/// The updated feature config.

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

/// An event where a team member left the team.

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

/// The team id.

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

/// An event where a user's team membership metadata was updated.

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

/// The team id.

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

/// An event where a new self user client was added.

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

/// The new user client.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
/// An event where a connection between the self user and
/// another user was updated.

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

/// The name of the other user.

Expand All @@ -31,4 +31,12 @@ public struct UserConnectionEvent: Equatable, Codable {

public let connection: Connection

public init(
userName: String,
connection: Connection
) {
self.userName = userName
self.connection = connection
}

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

/// An event where legalhold was disabled for a user.

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

/// The user id for whom legalhold was disabled.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
/// An event where a user was requested to become a
/// legalhold subject.

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

/// The user id of the target legalhold subject.

Expand Down
2 changes: 1 addition & 1 deletion WireAPI/Sources/WireAPI/Models/UserClient/Prekey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation

/// A Proteus client prekey used to establish a Proteus session.

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

/// The prekey id.

Expand Down
Loading

0 comments on commit 165e75b

Please sign in to comment.