Skip to content

Commit

Permalink
feat: Consent Refresh Pagination
Browse files Browse the repository at this point in the history
Added pagination to consent refresh call
  • Loading branch information
Alex Risch authored and Alex Risch committed Apr 5, 2024
1 parent 0a625c9 commit 9efc8eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/XMTPiOS/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ public class ConsentList {
identifier = try? LibXMTP.generatePrivatePreferencesTopicIdentifier(privateKey: privateKey)
}

func load() async throws -> ConsentList {
func load(pagination: Pagination? = nil) async throws -> ConsentList {
guard let identifier = identifier else {
throw ContactError.invalidIdentifier
}

let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: Pagination(direction: .ascending))
let pagination = pagination ?? Pagination(direction: .ascending)
let envelopes = try await client.apiClient.envelopes(topic: Topic.preferenceList(identifier).description, pagination: pagination)
let consentList = ConsentList(client: client)

var preferences: [PrivatePreferencesAction] = []
Expand Down
15 changes: 15 additions & 0 deletions Tests/XMTPTests/ContactsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ class ContactsTests: XCTestCase {
result = await contacts.isDenied(fixtures.alice.address)
XCTAssertTrue(result)
}

func testRefreshConsentListPagination() async throws {
let fixtures = await fixtures()
let contacts = fixtures.bobClient.contacts
let aliceAddress = fixtures.alice.address
try await contacts.deny(addresses: [aliceAddress])
let date = Date()
try await contacts.allow(addresses: [aliceAddress])

let result = try await contacts.consentList.load(pagination: Pagination(before: date, direction: .ascending))
XCTAssertTrue(result.entries[ConsentListEntry.address(aliceAddress).key]?.consentType == .denied)

let afterResult = try await contacts.consentList.load(pagination: Pagination(after: date, direction: .ascending))
XCTAssertTrue(afterResult.entries[ConsentListEntry.address(aliceAddress).key]?.consentType == .allowed)
}
}

0 comments on commit 9efc8eb

Please sign in to comment.