diff --git a/Sources/XMTP/Contacts.swift b/Sources/XMTP/Contacts.swift index c5ab8a12..16659545 100644 --- a/Sources/XMTP/Contacts.swift +++ b/Sources/XMTP/Contacts.swift @@ -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 { @@ -82,7 +82,7 @@ class ConsentList { consentList.allow(address: address) } preference.block.walletAddresses.forEach { address in - consentList.block(address: address) + consentList.deny(address: address) } } @@ -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 @@ -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 { @@ -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 { @@ -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)) } } diff --git a/Sources/XMTP/ConversationV1.swift b/Sources/XMTP/ConversationV1.swift index cd503226..3b0b6c82 100644 --- a/Sources/XMTP/ConversationV1.swift +++ b/Sources/XMTP/ConversationV1.swift @@ -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 } diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTP/ConversationV2.swift index 263897d1..f6e09c71 100644 --- a/Sources/XMTP/ConversationV2.swift +++ b/Sources/XMTP/ConversationV2.swift @@ -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 } diff --git a/Sources/XMTP/Proto/message_contents/private_preferences.pb.swift b/Sources/XMTP/Proto/message_contents/private_preferences.pb.swift index 0e969de9..d85b7eab 100644 --- a/Sources/XMTP/Proto/message_contents/private_preferences.pb.swift +++ b/Sources/XMTP/Proto/message_contents/private_preferences.pb.swift @@ -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 }() diff --git a/Tests/XMTPTests/ContactsTests.swift b/Tests/XMTPTests/ContactsTests.swift index d17423c8..8168af94 100644 --- a/Tests/XMTPTests/ContactsTests.swift +++ b/Tests/XMTPTests/ContactsTests.swift @@ -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) } } diff --git a/Tests/XMTPTests/ConversationTests.swift b/Tests/XMTPTests/ConversationTests.swift index 3c122147..8c05bd74 100644 --- a/Tests/XMTPTests/ConversationTests.swift +++ b/Tests/XMTPTests/ConversationTests.swift @@ -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)