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

Update to a V3 only SDK #417

Merged
merged 15 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 1 addition & 73 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public final class Client {
public var hasV2Client: Bool = true

/// Access ``Conversations`` for this Client.
public lazy var conversations: Conversations = .init(client: self)
public lazy var conversations: Conversations = .init(client: self, ffiConversations: v3Client!.conversations())

/// Access ``Contacts`` for this Client.
public lazy var contacts: Contacts = .init(client: self)
Expand Down Expand Up @@ -595,78 +595,6 @@ public final class Client {
.envelopes.count > 0
}

public func importConversation(from conversationData: Data) throws
-> Conversation?
{
let jsonDecoder = JSONDecoder()

do {
let v2Export = try jsonDecoder.decode(
ConversationV2Export.self, from: conversationData)
return try importV2Conversation(export: v2Export)
} catch {
do {
let v1Export = try jsonDecoder.decode(
ConversationV1Export.self, from: conversationData)
return try importV1Conversation(export: v1Export)
} catch {
throw ConversationImportError.invalidData
}
}
}

func importV2Conversation(export: ConversationV2Export) throws
-> Conversation
{
guard
let keyMaterial = Data(base64Encoded: Data(export.keyMaterial.utf8))
else {
throw ConversationImportError.invalidData
}

var consentProof: ConsentProofPayload? = nil
if let exportConsentProof = export.consentProof {
var proof = ConsentProofPayload()
proof.signature = exportConsentProof.signature
proof.timestamp = exportConsentProof.timestamp
proof.payloadVersion =
ConsentProofPayloadVersion.consentProofPayloadVersion1
consentProof = proof
}

return .v2(
ConversationV2(
topic: export.topic,
keyMaterial: keyMaterial,
context: InvitationV1.Context(
conversationID: export.context?.conversationId ?? "",
metadata: export.context?.metadata ?? [:]
),
peerAddress: export.peerAddress,
client: self,
header: SealedInvitationHeaderV1(),
consentProof: consentProof
))
}

func importV1Conversation(export: ConversationV1Export) throws
-> Conversation
{
let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)

guard let sentAt = formatter.date(from: export.createdAt) else {
throw ConversationImportError.invalidData
}

return .v1(
ConversationV1(
client: self,
peerAddress: export.peerAddress,
sentAt: sentAt
))
}

func ensureUserContactPublished() async throws {
if let contact = try await getUserContact(peerAddress: address),
case .v2 = contact.version,
Expand Down
Loading
Loading