Skip to content

Commit

Permalink
rename to deny and implicit consent
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 1, 2023
1 parent 8c13c4c commit 39aedac
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
20 changes: 10 additions & 10 deletions Sources/XMTP/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import XMTPRust
public typealias PrivatePreferencesAction = Xmtp_MessageContents_PrivatePreferencesAction

public enum ConsentState: String, Codable {
case allowed, blocked, unknown
case allowed, denied, unknown
}

struct ConsentListEntry: Codable, Hashable {
Expand Down Expand Up @@ -82,7 +82,7 @@ class ConsentList {
consentList.allow(address: address)
}
preference.block.walletAddresses.forEach { address in
consentList.block(address: address)
consentList.deny(address: address)
}
}

Expand All @@ -98,7 +98,7 @@ class ConsentList {
switch entry.consentType {
case .allowed:
payload.allow.walletAddresses = [entry.value]
case .blocked:
case .denied:
payload.block.walletAddresses = [entry.value]
case .unknown:
payload.messageType = nil
Expand All @@ -125,10 +125,10 @@ class ConsentList {
return .address(address, type: .allowed)
}

func block(address: String) -> ConsentListEntry {
entries[ConsentListEntry.address(address).key] = .blocked
func deny(address: String) -> ConsentListEntry {
entries[ConsentListEntry.address(address).key] = .denied

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

func state(address: String) -> ConsentState {
Expand Down Expand Up @@ -163,8 +163,8 @@ public actor Contacts {
return consentList.state(address: address) == .allowed
}

public func isBlocked(_ address: String) -> Bool {
return consentList.state(address: address) == .blocked
public func isDenied(_ address: String) -> Bool {
return consentList.state(address: address) == .denied
}

public func allow(addresses: [String]) async throws {
Expand All @@ -173,9 +173,9 @@ public actor Contacts {
}
}

public func block(addresses: [String]) async throws {
public func deny(addresses: [String]) async throws {
for address in addresses {
try await ConsentList(client: client).publish(entry: consentList.block(address: address))
try await ConsentList(client: client).publish(entry: consentList.deny(address: address))
}
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/XMTP/ConversationV1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public struct ConversationV1 {

@discardableResult func send(prepared: PreparedMessage) async throws -> String {
try await client.publish(envelopes: prepared.envelopes)
if((await client.contacts.consentList.state(address: peerAddress)) == .unknown) {
try await client.contacts.allow(addresses: [peerAddress])
}
return prepared.messageID
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/XMTP/ConversationV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public struct ConversationV2 {

@discardableResult func send(prepared: PreparedMessage) async throws -> String {
try await client.publish(envelopes: prepared.envelopes)
if((await client.contacts.consentList.state(address: peerAddress)) == .unknown) {
try await client.contacts.allow(addresses: [peerAddress])
}
return prepared.messageID
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct Xmtp_MessageContents_PrivatePreferencesAction {
guard case .allow(let l) = lhs, case .allow(let r) = rhs else { preconditionFailure() }
return l == r
}()
case (.block, .block): return {
case (.deny, .deny): return {
guard case .block(let l) = lhs, case .block(let r) = rhs else { preconditionFailure() }
return l == r
}()
Expand Down
4 changes: 2 additions & 2 deletions Tests/XMTPTests/ContactsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class ContactsTests: XCTestCase {

XCTAssertFalse(result)

try await contacts.block(addresses: [fixtures.alice.address])
try await contacts.deny(addresses: [fixtures.alice.address])

result = await contacts.isBlocked(fixtures.alice.address)
result = await contacts.isDenied(fixtures.alice.address)
XCTAssertTrue(result)
}
}
4 changes: 2 additions & 2 deletions Tests/XMTPTests/ConversationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,10 @@ class ConversationTests: XCTestCase {
// Conversations you start should start as allowed
XCTAssertTrue(isAllowed)

try await bobClient.contacts.block(addresses: [alice.address])
try await bobClient.contacts.deny(addresses: [alice.address])
try await bobClient.contacts.refreshConsentList()

let isBlocked = (await bobConversation.consentState()) == .blocked
let isBlocked = (await bobConversation.consentState()) == .denied

XCTAssertTrue(isBlocked)

Expand Down

0 comments on commit 39aedac

Please sign in to comment.