Skip to content

Commit

Permalink
feat: add shouldPush parameter to sendEncodedContent and prepareEncod…
Browse files Browse the repository at this point in the history
…edMessage functions
  • Loading branch information
kele-leanes committed Feb 2, 2024
1 parent f774147 commit 7450a4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions ios/Wrappers/DecodedMessageWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct DecodedMessageWrapper {
"senderAddress": model.senderAddress,
"sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000),
"fallback": model.encodedContent.fallback,
"shouldPush": model.shouldPush
]
}

Expand Down
14 changes: 10 additions & 4 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,16 @@ public class XMTPModule: Module {
).toJson()
}

AsyncFunction("sendEncodedContent") { (clientAddress: String, topic: String, encodedContentData: [UInt8]) -> String in
AsyncFunction("sendEncodedContent") { (clientAddress: String, topic: String, encodedContentData: [UInt8], shouldPush: Bool) -> String in
guard let conversation = try await findConversation(clientAddress: clientAddress, topic: topic) else {
throw Error.conversationNotFound("no conversation found for \(topic)")
}

let encodedContent = try EncodedContent(serializedData: Data(encodedContentData))

let options = SendOptions(contentType: encodedContent.type, shouldPush: shouldPush)

return try await conversation.send(encodedContent: encodedContent)
return try await conversation.send(encodedContent: encodedContent, options: options)
}

AsyncFunction("listConversations") { (clientAddress: String) -> [String] in
Expand Down Expand Up @@ -390,15 +392,19 @@ public class XMTPModule: Module {
AsyncFunction("prepareEncodedMessage") { (
clientAddress: String,
conversationTopic: String,
encodedContentData: [UInt8]
encodedContentData: [UInt8],
shouldPush: Bool
) -> String in
guard let conversation = try await findConversation(clientAddress: clientAddress, topic: conversationTopic) else {
throw Error.conversationNotFound("no conversation found for \(conversationTopic)")
}
let encodedContent = try EncodedContent(serializedData: Data(encodedContentData))

let contentType = encodedContent.type

let prepared = try await conversation.prepareMessage(
encodedContent: encodedContent
encodedContent: encodedContent,
options: SendOptions(contentType: contentType, shouldPush: shouldPush)
)
let preparedAtMillis = prepared.envelopes[0].timestampNs / 1_000_000
let preparedData = try prepared.serializedData()
Expand Down

0 comments on commit 7450a4c

Please sign in to comment.