Skip to content

Commit

Permalink
update to the latest libxmtp functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Oct 18, 2024
1 parent abe6af8 commit 2cd20ce
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public final class Client {
)
}

public static func buildV3(address: String, scwChainId: Int64?, options: ClientOptions) async throws -> Client {
public static func buildV3(address: String, scwChainId: Int64? = nil, options: ClientOptions) async throws -> Client {
let accountAddress = if(scwChainId != nil) { "eip155:\(String(describing: scwChainId)):\(address.lowercased())" } else { address }
let inboxId = try await getOrCreateInboxId(options: options, address: accountAddress)

Expand Down Expand Up @@ -688,7 +688,7 @@ public final class Client {
throw ClientError.noV3Client("Error no V3 client initialized")
}
do {
return Group(ffiGroup: try client.group(groupId: groupId.hexToData), client: self)
return Group(ffiGroup: try client.conversation(conversationId: groupId.hexToData), client: self)
} catch {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public class ConsentList {
func groupState(groupId: String) async throws -> ConsentState {
if let client = client.v3Client {
return try await client.getConsentState(
entityType: .groupId,
entityType: .conversationId,
entity: groupId
).fromFFI
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final class GroupStreamCallback: FfiConversationCallback {
self.callback = callback
}

func onConversation(conversation: FfiGroup) {
func onConversation(conversation: FfiConversation) {
self.callback(conversation.fromFFI(client: client))
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public actor Conversations {
guard let v3Client = client.v3Client else {
return 0
}
return try await v3Client.conversations().syncAllGroups()
return try await v3Client.conversations().syncAllConversations()
}

public func groups(createdAfter: Date? = nil, createdBefore: Date? = nil, limit: Int? = nil) async throws -> [Group] {
Expand All @@ -136,7 +136,7 @@ public actor Conversations {
if let limit {
options.limit = Int64(limit)
}
return try await v3Client.conversations().list(opts: options).map { $0.fromFFI(client: client) }
return try await v3Client.conversations().listGroups(opts: options).map { $0.fromFFI(client: client) }
}

public func streamGroups() async throws -> AsyncThrowingStream<Group, Error> {
Expand All @@ -150,7 +150,7 @@ public actor Conversations {
}
continuation.yield(group)
}
guard let stream = await self.client.v3Client?.conversations().stream(callback: groupCallback) else {
guard let stream = await self.client.v3Client?.conversations().streamGroups(callback: groupCallback) else {
continuation.finish(throwing: GroupError.streamingFailure)
return
}
Expand All @@ -175,7 +175,7 @@ public actor Conversations {
AsyncThrowingStream { continuation in
let ffiStreamActor = FfiStreamActor()
let task = Task {
let stream = await self.client.v3Client?.conversations().stream(
let stream = await self.client.v3Client?.conversations().streamGroups(
callback: GroupStreamCallback(client: self.client) { group in
guard !Task.isCancelled else {
continuation.finish()
Expand Down Expand Up @@ -435,7 +435,7 @@ public actor Conversations {
AsyncThrowingStream { continuation in
let ffiStreamActor = FfiStreamActor()
let task = Task {
let stream = await self.client.v3Client?.conversations().streamAllMessages(
let stream = await self.client.v3Client?.conversations().streamAllGroupMessages(
messageCallback: MessageCallback(client: self.client) { message in
guard !Task.isCancelled else {
continuation.finish()
Expand Down Expand Up @@ -500,7 +500,7 @@ public actor Conversations {
AsyncThrowingStream { continuation in
let ffiStreamActor = FfiStreamActor()
let task = Task {
let stream = await self.client.v3Client?.conversations().streamAllMessages(
let stream = await self.client.v3Client?.conversations().streamAllGroupMessages(
messageCallback: MessageCallback(client: self.client) { message in
guard !Task.isCancelled else {
continuation.finish()
Expand Down
6 changes: 3 additions & 3 deletions Sources/XMTPiOS/Extensions/Ffi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ extension FfiV2SubscribeRequest {

// MARK: Group

extension FfiGroup {
extension FfiConversation {
func fromFFI(client: Client) -> Group {
Group(ffiGroup: self, client: client)
}
}

extension FfiGroupMember {
extension FfiConversationMember {
var fromFFI: Member {
Member(ffiGroupMember: self)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ extension FfiConsentState {
extension EntryType {
var toFFI: FfiConsentEntityType{
switch (self) {
case .group_id: return FfiConsentEntityType.groupId
case .group_id: return FfiConsentEntityType.conversationId
case .inbox_id: return FfiConsentEntityType.inboxId
case .address: return FfiConsentEntityType.address
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class StreamHolder {
}

public struct Group: Identifiable, Equatable, Hashable {
var ffiGroup: FfiGroup
var ffiGroup: FfiConversation
var client: Client
let streamHolder = StreamHolder()

Expand All @@ -39,7 +39,7 @@ public struct Group: Identifiable, Equatable, Hashable {
Topic.groupMessage(id).description
}

func metadata() throws -> FfiGroupMetadata {
func metadata() throws -> FfiConversationMetadata {
return try ffiGroup.groupMetadata()
}

Expand Down Expand Up @@ -230,12 +230,12 @@ public struct Group: Identifiable, Equatable, Hashable {
}

public func processMessage(envelopeBytes: Data) async throws -> DecodedMessage {
let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes)
let message = try await ffiGroup.processStreamedConversationMessage(envelopeBytes: envelopeBytes)
return try MessageV3(client: client, ffiMessage: message).decode()
}

public func processMessageDecrypted(envelopeBytes: Data) async throws -> DecryptedMessage {
let message = try await ffiGroup.processStreamedGroupMessage(envelopeBytes: envelopeBytes)
let message = try await ffiGroup.processStreamedConversationMessage(envelopeBytes: envelopeBytes)
return try MessageV3(client: client, ffiMessage: message).decrypt()
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/XMTPiOS/Mls/Member.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public enum PermissionLevel {
}

public struct Member {
var ffiGroupMember: FfiGroupMember
var ffiGroupMember: FfiConversationMember

init(ffiGroupMember: FfiGroupMember) {
init(ffiGroupMember: FfiConversationMember) {
self.ffiGroupMember = ffiGroupMember
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/XMTPiOS/SigningKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ extension SigningKey {

return AuthorizedIdentity(address: address, authorized: authorized, identity: identity)
}

public func sign(_ data: Data) async throws -> Signature {
throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "sign(Data) not implemented."])
}

public func sign(message: String) async throws -> Signature {
throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "sign(String) not implemented."])
}

public func signSCW(message: String) async throws -> Data {
throw NSError(domain: "NotImplemented", code: 1, userInfo: [NSLocalizedDescriptionKey: "signSCW(String) not implemented."])
}
}
22 changes: 8 additions & 14 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,19 @@ class ClientTests: XCTestCase {


let inboxId = try await Client.getOrCreateInboxId(options: options, address: alix.address)
let alixClient = try await Client.createOrBuild(
let alixClient = try await Client.createV3(
account: alix,
options: options
)

XCTAssertEqual(inboxId, alixClient.inboxID)

let alixClient2 = try await Client.buildV3(
address: alix.address,
options: options
)

XCTAssertEqual(alixClient2.inboxID, alixClient.inboxID)
}

func testRevokesAllOtherInstallations() async throws {
Expand Down Expand Up @@ -514,17 +521,4 @@ class ClientTests: XCTestCase {
let newState = try await alixClient3.inboxState(refreshFromNetwork: true)
XCTAssertEqual(newState.installations.count, 1)
}

func testCanCreateASCW() async throws {
let key = try Crypto.secureRandomBytes(count: 32)
let davonSCW = try FakeSCWWallet.generate()
let davonSCWClient = try await Client.createOrBuild(
account: davonSCW,
options: .init(
api: .init(env: .local, isSecure: false),
enableV3: true,
encryptionKey: key
)
)
}
}
12 changes: 1 addition & 11 deletions Tests/XMTPTests/V3ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class V3ClientTests: XCTestCase {
)
)
let boV3 = try PrivateKey.generate()
let boV3Client = try await Client.createOrBuild(
let boV3Client = try await Client.createV3(
account: boV3,
options: .init(
api: .init(env: .local, isSecure: false),
Expand All @@ -52,16 +52,6 @@ class V3ClientTests: XCTestCase {
)
)

let davonSCW = try FakeSCWWallet.generate()
let davonSCWClient = try await Client.createOrBuild(
account: davonSCW,
options: .init(
api: .init(env: .local, isSecure: false),
enableV3: true,
encryptionKey: key
)
)


return .init(
alixV2: alixV2,
Expand Down

0 comments on commit 2cd20ce

Please sign in to comment.