Skip to content

Commit

Permalink
feat: integrate shouldPush for React Native (#231)
Browse files Browse the repository at this point in the history
* 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 <zombieobject@users.noreply.github.com>
  • Loading branch information
Ezequiel Leanes and zombieobject authored Feb 20, 2024
1 parent c0eacb2 commit bb9e024
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/XMTPiOS/ConversationV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/XMTPiOS/Messages/DecryptedMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public struct DecryptedMessage {
public var senderAddress: String
public var sentAt: Date
public var topic: String = ""
public var shouldPush: Bool?
}
10 changes: 5 additions & 5 deletions Sources/XMTPiOS/Messages/MessageV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand All @@ -80,7 +81,7 @@ extension MessageV2 {
}
}

static func encode<Codec: ContentCodec>(client: Client, content encodedContent: EncodedContent, topic: String, keyMaterial: Data, codec: Codec) async throws -> MessageV2 {
static func encode<Codec: ContentCodec>(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()
Expand All @@ -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
)
}
}
4 changes: 3 additions & 1 deletion Sources/XMTPiOS/SendOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 5 additions & 1 deletion XMTPiOSExample/XMTPiOSExample/Views/LoginView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)

Expand Down

0 comments on commit bb9e024

Please sign in to comment.