Skip to content

Commit

Permalink
Decrypted Group Messages (#245)
Browse files Browse the repository at this point in the history
* add decrypted messages for react native

* bump the pod spec
  • Loading branch information
nplasterer authored Feb 9, 2024
1 parent 64f9e97 commit 5643e41
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Sources/XMTPiOS/Extensions/Ffi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ extension FfiMessage {
sent: Date(timeIntervalSince1970: TimeInterval(sentAtNs / 1_000_000_000))
)
}

func fromFFIDecrypted(client: Client) throws -> DecryptedMessage {
let encodedContent = try EncodedContent(serializedData: content)

return DecryptedMessage(
id: id.toHex,
encodedContent: encodedContent,
senderAddress: addrFrom,
sentAt: Date(timeIntervalSince1970: TimeInterval(sentAtNs / 1_000_000_000)),
topic: convoId.toHex
)
}
}

// MARK: Group
Expand Down
22 changes: 22 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,26 @@ public struct Group: Identifiable, Equatable, Hashable {
try ffiMessage.fromFFI(client: client)
}
}

public func decryptedMessages(before: Date? = nil, after: Date? = nil, limit: Int? = nil) async throws -> [DecryptedMessage] {
var options = FfiListMessagesOptions(sentBeforeNs: nil, sentAfterNs: nil, limit: nil)

if let before {
options.sentBeforeNs = Int64(before.millisecondsSinceEpoch)
}

if let after {
options.sentAfterNs = Int64(after.millisecondsSinceEpoch)
}

if let limit {
options.limit = Int64(limit)
}

let messages = try ffiGroup.findMessages(opts: options)

return try messages.map { ffiMessage in
try ffiMessage.fromFFIDecrypted(client: client)
}
}
}
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#

spec.name = "XMTP"
spec.version = "0.8.2"
spec.version = "0.8.3"
spec.summary = "XMTP SDK Cocoapod"

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit 5643e41

Please sign in to comment.