From bb9e02441d3c9209f4e94a7a44178dd9527f6e83 Mon Sep 17 00:00:00 2001 From: Ezequiel Leanes Date: Tue, 20 Feb 2024 15:54:27 -0300 Subject: [PATCH] feat: integrate `shouldPush` for React Native (#231) * update Package.resolved * feat: add shouldPush property to DecryptedMessage struct * feat: add shouldPush property to SendOptions struct * feat: add shouldPush parameter to MessageV2.encode() method * feat: add shouldPush option to ConversationV2 initialization * fix: update SendOptions initializer parameter name * Fix Sample App WalletConnect.configure Signature --------- Co-authored-by: Ethan Mateja --- Package.resolved | 4 ++-- Sources/XMTPiOS/ConversationV2.swift | 3 ++- Sources/XMTPiOS/Messages/DecryptedMessage.swift | 1 + Sources/XMTPiOS/Messages/MessageV2.swift | 10 +++++----- Sources/XMTPiOS/SendOptions.swift | 4 +++- XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift | 6 +++++- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Package.resolved b/Package.resolved index 074675b4..8543b319 100644 --- a/Package.resolved +++ b/Package.resolved @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/xmtp/libxmtp-swift", "state" : { - "branch" : "92274fe", - "revision" : "92274fe0dde1fc7f8f716ebcffa3d252813be56d" + "revision" : "db13df1fef0e4a11880a889640a3df2998e4abac", + "version" : "0.4.2-beta1" } }, { diff --git a/Sources/XMTPiOS/ConversationV2.swift b/Sources/XMTPiOS/ConversationV2.swift index 6274dd78..947a64f6 100644 --- a/Sources/XMTPiOS/ConversationV2.swift +++ b/Sources/XMTPiOS/ConversationV2.swift @@ -85,7 +85,8 @@ public struct ConversationV2 { content: encodedContent, topic: topic, keyMaterial: keyMaterial, - codec: codec + codec: codec, + shouldPush: options?.shouldPush ) let topic = options?.ephemeral == true ? ephemeralTopic : topic diff --git a/Sources/XMTPiOS/Messages/DecryptedMessage.swift b/Sources/XMTPiOS/Messages/DecryptedMessage.swift index 2109b5b0..481cf849 100644 --- a/Sources/XMTPiOS/Messages/DecryptedMessage.swift +++ b/Sources/XMTPiOS/Messages/DecryptedMessage.swift @@ -13,4 +13,5 @@ public struct DecryptedMessage { public var senderAddress: String public var sentAt: Date public var topic: String = "" + public var shouldPush: Bool? } diff --git a/Sources/XMTPiOS/Messages/MessageV2.swift b/Sources/XMTPiOS/Messages/MessageV2.swift index 5978caf9..c49114bd 100644 --- a/Sources/XMTPiOS/Messages/MessageV2.swift +++ b/Sources/XMTPiOS/Messages/MessageV2.swift @@ -58,7 +58,8 @@ extension MessageV2 { encodedContent: encodedMessage, senderAddress: try signed.sender.walletAddress, sentAt: Date(timeIntervalSince1970: Double(header.createdNs / 1_000_000) / 1000), - topic: topic + topic: topic, + shouldPush: message.shouldPush ) } @@ -80,7 +81,7 @@ extension MessageV2 { } } - static func encode(client: Client, content encodedContent: EncodedContent, topic: String, keyMaterial: Data, codec: Codec) async throws -> MessageV2 { + static func encode(client: Client, content encodedContent: EncodedContent, topic: String, keyMaterial: Data, codec: Codec, shouldPush: Bool? = nil) async throws -> MessageV2 { let payload = try encodedContent.serializedData() let date = Date() @@ -107,14 +108,13 @@ extension MessageV2 { let senderHmac = try Crypto.generateHmacSignature(secret: keyMaterial, info: infoEncoded, message: headerBytes) let decoded = try codec.decode(content: encodedContent, client: client) - let shouldPush = try codec.shouldPush(content: decoded) - + let calculatedShouldPush = try codec.shouldPush(content: decoded) return MessageV2( headerBytes: headerBytes, ciphertext: ciphertext, senderHmac: senderHmac, - shouldPush: shouldPush + shouldPush: shouldPush ?? calculatedShouldPush ) } } diff --git a/Sources/XMTPiOS/SendOptions.swift b/Sources/XMTPiOS/SendOptions.swift index 15b09c0d..50c6ece6 100644 --- a/Sources/XMTPiOS/SendOptions.swift +++ b/Sources/XMTPiOS/SendOptions.swift @@ -11,10 +11,12 @@ public struct SendOptions { public var compression: EncodedContentCompression? public var contentType: ContentTypeID? public var ephemeral: Bool = false + public var shouldPush: Bool? - public init(compression: EncodedContentCompression? = nil, contentType: ContentTypeID? = nil, ephemeral: Bool = false) { + public init(compression: EncodedContentCompression? = nil, contentType: ContentTypeID? = nil, ephemeral: Bool = false, __shouldPush: Bool? = nil) { self.compression = compression self.contentType = contentType self.ephemeral = ephemeral + self.shouldPush = __shouldPush } } diff --git a/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift b/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift index 38f46ad0..9a779009 100644 --- a/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift +++ b/XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift @@ -128,7 +128,11 @@ struct LoginView: View { name: "XMTP Chat", description: "It's a chat app.", url: "https://localhost:4567", - icons: [] + icons: [], + redirect: AppMetadata.Redirect( + native: "", + universal: nil + ) ) )