Skip to content

Commit

Permalink
Add entry to the consent list entries (#209)
Browse files Browse the repository at this point in the history
* update contacts to return actual entries

* make consent list retrun

* fix lint
  • Loading branch information
nplasterer authored Dec 7, 2023
1 parent 47b8ffb commit d2c65a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions Sources/XMTP/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public enum ConsentState: String, Codable {
case allowed, denied, unknown
}

struct ConsentListEntry: Codable, Hashable {
enum EntryType: String, Codable {
public struct ConsentListEntry: Codable, Hashable {
public enum EntryType: String, Codable {
case address
}

static func address(_ address: String, type: ConsentState = .unknown) -> ConsentListEntry {
ConsentListEntry(value: address, entryType: .address, consentType: type)
}

var value: String
var entryType: EntryType
var consentType: ConsentState
public var value: String
public var entryType: EntryType
public var consentType: ConsentState

var key: String {
"\(entryType)-\(value)"
Expand All @@ -38,7 +38,7 @@ public enum ContactError: Error {
}

public class ConsentList {
public var entries: [String: ConsentState] = [:]
public var entries: [String: ConsentListEntry] = [:]
var publicKey: Data
var privateKey: Data
var identifier: String?
Expand Down Expand Up @@ -120,21 +120,25 @@ public class ConsentList {
}

func allow(address: String) -> ConsentListEntry {
entries[ConsentListEntry.address(address).key] = .allowed
let entry = ConsentListEntry.address(address, type: ConsentState.allowed)
entries[ConsentListEntry.address(address).key] = entry

return .address(address, type: .allowed)
return entry
}

func deny(address: String) -> ConsentListEntry {
entries[ConsentListEntry.address(address).key] = .denied
let entry = ConsentListEntry.address(address, type: ConsentState.denied)
entries[ConsentListEntry.address(address).key] = entry

return .address(address, type: .denied)
return entry
}

func state(address: String) -> ConsentState {
let state = entries[ConsentListEntry.address(address).key]

return state ?? .unknown
let entry = entries[ConsentListEntry.address(address).key]

// swiftlint:disable no_optional_try
return entry?.consentType ?? .unknown
// swiftlint:enable no_optional_try
}
}

Expand All @@ -155,8 +159,9 @@ public actor Contacts {
self.consentList = ConsentList(client: client)
}

public func refreshConsentList() async throws {
self.consentList = try await ConsentList(client: client).load()
public func refreshConsentList() async throws -> ConsentList {
consentList = try await ConsentList(client: client).load()
return consentList
}

public func isAllowed(_ address: String) -> Bool {
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 = "0.7.1-alpha0"
spec.version = "0.7.2-alpha0"
spec.summary = "XMTP SDK Cocoapod"

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

0 comments on commit d2c65a8

Please sign in to comment.