Skip to content

Commit

Permalink
List of inbox states for inbox ids (#426)
Browse files Browse the repository at this point in the history
* update package

* add ability to fetch inbox state for inbox ids

* bump the pod
  • Loading branch information
nplasterer authored Nov 13, 2024
1 parent 1d863c7 commit cb6bb37
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
22 changes: 17 additions & 5 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,7 @@ public final class Client {
return nil
}

public func findDm(address: String) async throws -> Dm? {
guard let inboxId = try await inboxIdFromAddress(address: address)
else {
throw ClientError.creationError("No inboxId present")
}
public func findDmByInboxId(inboxId: String) throws -> Dm? {
do {
let conversation = try ffiClient.dmConversation(
targetInboxId: inboxId)
Expand All @@ -375,6 +371,14 @@ public final class Client {
}
}

public func findDmByAddress(address: String) async throws -> Dm? {
guard let inboxId = try await inboxIdFromAddress(address: address)
else {
throw ClientError.creationError("No inboxId present")
}
return try findDmByInboxId(inboxId: inboxId)
}

public func findMessage(messageId: String) throws -> Message? {
do {
return Message(
Expand Down Expand Up @@ -416,4 +420,12 @@ public final class Client {
ffiInboxState: try await ffiClient.inboxState(
refreshFromNetwork: refreshFromNetwork))
}

public func inboxStatesForInboxIds(
refreshFromNetwork: Bool, inboxIds: [String]
) async throws -> [InboxState] {
return try await ffiClient.addressesFromInboxId(
refreshFromNetwork: refreshFromNetwork, inboxIds: inboxIds
).map { InboxState(ffiInboxState: $0) }
}
}
2 changes: 1 addition & 1 deletion Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public actor Conversations {
if !canMessage {
throw ConversationError.memberNotRegistered([peerAddress])
}
if let existingDm = try await client.findDm(address: peerAddress) {
if let existingDm = try await client.findDmByAddress(address: peerAddress) {
return existingDm
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/XMTPTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,18 @@ class ClientTests: XCTestCase {
refreshFromNetwork: true)
XCTAssertEqual(newState.installations.count, 1)
}

func testsCanFindOthersInboxStates() async throws {
let fixtures = try await fixtures()
let states = try await fixtures.alixClient.inboxStatesForInboxIds(
refreshFromNetwork: true,
inboxIds: [fixtures.boClient.inboxID, fixtures.caroClient.inboxID]
)
XCTAssertEqual(
states.first!.recoveryAddress.lowercased(),
fixtures.bo.walletAddress.lowercased())
XCTAssertEqual(
states.last!.recoveryAddress.lowercased(),
fixtures.caro.walletAddress.lowercased())
}
}
24 changes: 24 additions & 0 deletions Tests/XMTPTests/DmTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ import XMTPTestHelpers

@available(iOS 16, *)
class DmTests: XCTestCase {

func testCanFindDmByInboxId() async throws {
let fixtures = try await fixtures()

let dm = try await fixtures.boClient.conversations.findOrCreateDm(with: fixtures.caro.walletAddress)

let caroDm = try fixtures.boClient.findDmByInboxId(inboxId: fixtures.caroClient.inboxID)
let alixDm = try fixtures.boClient.findDmByInboxId(inboxId: fixtures.alixClient.inboxID)

XCTAssertNil(alixDm)
XCTAssertEqual(caroDm?.id, dm.id)
}

func testCanFindDmByAddress() async throws {
let fixtures = try await fixtures()

let dm = try await fixtures.boClient.conversations.findOrCreateDm(with: fixtures.caro.walletAddress)

let caroDm = try await fixtures.boClient.findDmByAddress(address: fixtures.caroClient.address)
let alixDm = try await fixtures.boClient.findDmByAddress(address: fixtures.alixClient.address)

XCTAssertNil(alixDm)
XCTAssertEqual(caroDm?.id, dm.id)
}

func testCanCreateADm() async throws {
let fixtures = try await fixtures()
Expand Down
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "XMTP"
spec.version = "3.0.3"
spec.version = "3.0.4"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit cb6bb37

Please sign in to comment.