diff --git a/Sources/XMTPiOS/Conversation.swift b/Sources/XMTPiOS/Conversation.swift index 1f003e4a..cddcc4c3 100644 --- a/Sources/XMTPiOS/Conversation.swift +++ b/Sources/XMTPiOS/Conversation.swift @@ -80,6 +80,18 @@ public enum Conversation: Identifiable, Equatable, Hashable { } } + public func prepareMessage(encodedContent: EncodedContent) async throws + -> String + { + switch self { + case let .group(group): + return try await group.prepareMessage( + encodedContent: encodedContent) + case let .dm(dm): + return try await dm.prepareMessage(encodedContent: encodedContent) + } + } + public func prepareMessage(content: T, options: SendOptions? = nil) async throws -> String { @@ -92,7 +104,7 @@ public enum Conversation: Identifiable, Equatable, Hashable { content: content, options: options) } } - + public func publishMessages() async throws { switch self { case let .group(group): @@ -132,13 +144,14 @@ public enum Conversation: Identifiable, Equatable, Hashable { } @discardableResult public func send( - encodedContent: EncodedContent) async throws -> String { + encodedContent: EncodedContent + ) async throws -> String { switch self { case let .group(group): return try await group.send( - encodedContent: encodedContent) + encodedContent: encodedContent) case let .dm(dm): - return try await dm.send(encodedContent: encodedContent) + return try await dm.send(encodedContent: encodedContent) } } diff --git a/Sources/XMTPiOS/Dm.swift b/Sources/XMTPiOS/Dm.swift index fbce9894..1ad20c8b 100644 --- a/Sources/XMTPiOS/Dm.swift +++ b/Sources/XMTPiOS/Dm.swift @@ -132,6 +132,18 @@ public struct Dm: Identifiable, Equatable, Hashable { return encoded } + public func prepareMessage(encodedContent: EncodedContent) async throws + -> String + { + if try consentState() == .unknown { + try await updateConsentState(state: .allowed) + } + + let messageId = try ffiConversation.sendOptimistic( + contentBytes: encodedContent.serializedData()) + return messageId.toHex + } + public func prepareMessage(content: T, options: SendOptions? = nil) async throws -> String { diff --git a/Sources/XMTPiOS/Group.swift b/Sources/XMTPiOS/Group.swift index 63327ec5..abff2f44 100644 --- a/Sources/XMTPiOS/Group.swift +++ b/Sources/XMTPiOS/Group.swift @@ -330,6 +330,18 @@ public struct Group: Identifiable, Equatable, Hashable { return encoded } + public func prepareMessage(encodedContent: EncodedContent) async throws + -> String + { + if try consentState() == .unknown { + try await updateConsentState(state: .allowed) + } + + let messageId = try ffiGroup.sendOptimistic( + contentBytes: encodedContent.serializedData()) + return messageId.toHex + } + public func prepareMessage(content: T, options: SendOptions? = nil) async throws -> String {