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

List of inbox states for inbox ids #426

Merged
merged 20 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ede8122
update package
nplasterer Sep 13, 2024
70c3a41
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 13, 2024
c72c33c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 20, 2024
bc9fb62
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 22, 2024
3e6c8e2
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
558729b
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
709cd72
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Sep 26, 2024
6af3b08
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 1, 2024
e499905
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 9, 2024
c18f087
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 24, 2024
380f36c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Oct 25, 2024
8128559
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 1, 2024
2a93ced
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 4, 2024
c2da259
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 8, 2024
21cfe68
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 8, 2024
cce1b4c
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 10, 2024
ef869d2
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 11, 2024
8b85235
Merge branch 'main' of https://github.com/xmtp/xmtp-ios
nplasterer Nov 12, 2024
12820bd
add ability to fetch inbox state for inbox ids
nplasterer Nov 13, 2024
6e39b67
bump the pod
nplasterer Nov 13, 2024
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
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
Loading