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

feat: integrate shouldPush for React Native #231

Merged
merged 7 commits into from
Feb 20, 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
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
Loading