Skip to content

Commit

Permalink
add ability to prepare encoded content
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 16, 2024
1 parent ff8349c commit 1db89c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Sources/XMTPiOS/Conversation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(content: T, options: SendOptions? = nil)
async throws -> String
{
Expand All @@ -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):
Expand Down Expand Up @@ -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)
}
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/XMTPiOS/Dm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(content: T, options: SendOptions? = nil)
async throws -> String
{
Expand Down
12 changes: 12 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(content: T, options: SendOptions? = nil)
async throws -> String
{
Expand Down

0 comments on commit 1db89c2

Please sign in to comment.