Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prepare for encoded content #447

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = "XMTP"
spec.version = "3.0.15"
spec.version = "3.0.16"
spec.summary = "XMTP SDK Cocoapod"

spec.description = <<-DESC
Expand Down
Loading