Skip to content

Commit

Permalink
get the tests compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed May 28, 2024
1 parent be752df commit 8f8c06d
Show file tree
Hide file tree
Showing 19 changed files with 240 additions and 4,161 deletions.
7 changes: 4 additions & 3 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ extension GenericErrorDescribing {
let .GroupError(message),
let .Signature(message),
let .GroupMetadata(message),
let .Generic(message):
return message
case .GroupMutablePermissions(message: let message):
let .Generic(message),
let .GroupMutablePermissions(message),
let .SignatureRequestError(message),
let .Erc1271SignatureError(message):
return message
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public final class Client {
signingKey: account
)

let client = try Client(address: account.address, privateKeyBundleV1: privateKeyBundleV1, apiClient: apiClient, v3Client: v3Client, dbPath: dbPath, installationID: v3Client?.installationId().toHex ?? "", v3Client?.inboxId() ?? "")
let client = try Client(address: account.address, privateKeyBundleV1: privateKeyBundleV1, apiClient: apiClient, v3Client: v3Client, dbPath: dbPath, installationID: v3Client?.installationId().toHex ?? "", inboxID: v3Client?.inboxId() ?? "")
let conversations = client.conversations
let contacts = client.contacts
try await client.ensureUserContactPublished()
Expand Down
44 changes: 24 additions & 20 deletions Sources/XMTPiOS/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public enum Conversation: Sendable {
case v1, v2, group
}

public func consentState() async -> ConsentState {
public func consentState() async throws -> ConsentState {
switch self {
case .v1(let conversationV1):
return await conversationV1.client.contacts.consentList.state(address: peerAddress)
return try await conversationV1.client.contacts.consentList.state(address: peerAddress)
case .v2(let conversationV2):
return await conversationV2.client.contacts.consentList.state(address: peerAddress)
return try await conversationV2.client.contacts.consentList.state(address: peerAddress)
case let .group(group):
return await group.client.contacts.consentList.groupState(groupId: group.id)
}
Expand Down Expand Up @@ -76,24 +76,28 @@ public enum Conversation: Sendable {

/// The wallet address of the other person in this conversation.
public var peerAddress: String {
switch self {
case let .v1(conversationV1):
return conversationV1.peerAddress
case let .v2(conversationV2):
return conversationV2.peerAddress
case let .group(group):
return group.peerAddresses.joined(separator: ",")
get throws {
switch self {
case let .v1(conversationV1):
return conversationV1.peerAddress
case let .v2(conversationV2):
return conversationV2.peerAddress
case let .group(group):
return try group.peerInboxIds.joined(separator: ",")
}
}
}

public var peerAddresses: [String] {
switch self {
case let .v1(conversationV1):
return [conversationV1.peerAddress]
case let .v2(conversationV2):
return [conversationV2.peerAddress]
case let .group(group):
return group.peerAddresses
get throws {
switch self {
case let .v1(conversationV1):
return [conversationV1.peerAddress]
case let .v2(conversationV2):
return [conversationV2.peerAddress]
case let .group(group):
return try group.peerInboxIds
}
}
}

Expand Down Expand Up @@ -124,10 +128,10 @@ public enum Conversation: Sendable {

/// Exports the serializable topic data required for later import.
/// See Conversations.importTopicData()
public func toTopicData() -> Xmtp_KeystoreApi_V1_TopicMap.TopicData {
Xmtp_KeystoreApi_V1_TopicMap.TopicData.with {
public func toTopicData() throws -> Xmtp_KeystoreApi_V1_TopicMap.TopicData {
try Xmtp_KeystoreApi_V1_TopicMap.TopicData.with {
$0.createdNs = UInt64(createdAt.timeIntervalSince1970 * 1000) * 1_000_000
$0.peerAddress = peerAddress
$0.peerAddress = try peerAddress
if case let .v2(cv2) = self {
$0.invitation = Xmtp_MessageContents_InvitationV1.with {
$0.topic = cv2.topic
Expand Down
12 changes: 6 additions & 6 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ public actor Conversations {
return .v1(conversationV1)
}

private func findExistingConversation(with peerAddress: String, conversationID: String?) -> Conversation? {
return conversationsByTopic.first(where: { $0.value.peerAddress == peerAddress &&
private func findExistingConversation(with peerAddress: String, conversationID: String?) throws -> Conversation? {
return try conversationsByTopic.first(where: { try $0.value.peerAddress == peerAddress &&
(($0.value.conversationID ?? "") == (conversationID ?? ""))
})?.value
}
Expand All @@ -447,7 +447,7 @@ public actor Conversations {
throw ConversationError.recipientIsSender
}
print("\(client.address) starting conversation with \(peerAddress)")
if let existing = findExistingConversation(with: peerAddress, conversationID: context?.conversationID) {
if let existing = try findExistingConversation(with: peerAddress, conversationID: context?.conversationID) {
return existing
}

Expand All @@ -456,7 +456,7 @@ public actor Conversations {
}

_ = try await list() // cache old conversations and check again
if let existing = findExistingConversation(with: peerAddress, conversationID: context?.conversationID) {
if let existing = try findExistingConversation(with: peerAddress, conversationID: context?.conversationID) {
return existing
}

Expand Down Expand Up @@ -633,8 +633,8 @@ public actor Conversations {
}
}

newConversations
.filter { $0.peerAddress != client.address && Topic.isValidTopic(topic: $0.topic) }
try newConversations
.filter { try $0.peerAddress != client.address && Topic.isValidTopic(topic: $0.topic) }
.forEach { conversationsByTopic[$0.topic] = $0 }

// TODO(perf): use DB to persist + sort
Expand Down
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/Extensions/Ffi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ extension FfiGroup {
}

extension FfiGroupMember {
var fromFFI: Group.Member {
Group.Member(ffiGroupMember: self)
var fromFFI: Member {
Member(ffiGroupMember: self)
}
}
12 changes: 6 additions & 6 deletions Sources/XMTPiOS/Mls/MessageV3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public struct MessageV3: Identifiable {
return ffiMessage.convoId
}

var senderAddress: String {
return ffiMessage.addrFrom
var senderInboxId: String {
return ffiMessage.senderInboxId
}

var sentAt: Date {
Expand All @@ -57,12 +57,12 @@ public struct MessageV3: Identifiable {
client: client,
topic: Topic.groupMessage(convoId.toHex).description,
encodedContent: encodedContent,
senderAddress: senderAddress,
senderAddress: senderInboxId,
sent: sentAt,
deliveryStatus: deliveryStatus
)

if decodedMessage.encodedContent.type == ContentTypeGroupMembershipChanged && ffiMessage.kind != .membershipChange {
if decodedMessage.encodedContent.type == ContentTypeGroupUpdated && ffiMessage.kind != .membershipChange {
throw MessageV3Error.decodeError("Error decoding group membership change")
}

Expand Down Expand Up @@ -96,13 +96,13 @@ public struct MessageV3: Identifiable {
let decrytedMessage = DecryptedMessage(
id: id.toHex,
encodedContent: encodedContent,
senderAddress: senderAddress,
senderAddress: senderInboxId,
sentAt: Date(),
topic: Topic.groupMessage(convoId.toHex).description,
deliveryStatus: deliveryStatus
)

if decrytedMessage.encodedContent.type == ContentTypeGroupMembershipChanged && ffiMessage.kind != .membershipChange {
if decrytedMessage.encodedContent.type == ContentTypeGroupUpdated && ffiMessage.kind != .membershipChange {
throw MessageV3Error.decodeError("Error decoding group membership change")
}

Expand Down
Loading

0 comments on commit 8f8c06d

Please sign in to comment.