Skip to content

Commit

Permalink
fix: Improve performance list method (#214)
Browse files Browse the repository at this point in the history
* fix: update ConversationV2 createdAt property

* fix: ConversationV2 initialization order

* remove test

* resolve comments

* Update XMTP.podspec version

* Update ConversationV2 struct to use createdAtNs instead of createdAt
  • Loading branch information
Ezequiel Leanes authored Jan 18, 2024
1 parent af277a0 commit f4f24aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
15 changes: 10 additions & 5 deletions Sources/XMTP/ConversationV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ public struct ConversationV2Container: Codable {
var conversationID: String?
var metadata: [String: String] = [:]
var peerAddress: String
var createdAtNs: UInt64?
var header: SealedInvitationHeaderV1

public func decode(with client: Client) -> ConversationV2 {
let context = InvitationV1.Context(conversationID: conversationID ?? "", metadata: metadata)
return ConversationV2(topic: topic, keyMaterial: keyMaterial, context: context, peerAddress: peerAddress, client: client, header: header)
return ConversationV2(topic: topic, keyMaterial: keyMaterial, context: context, peerAddress: peerAddress, client: client, createdAtNs: createdAtNs, header: header)
}
}

Expand All @@ -30,6 +31,7 @@ public struct ConversationV2 {
public var context: InvitationV1.Context
public var peerAddress: String
public var client: Client
var createdAtNs: UInt64?
private var header: SealedInvitationHeaderV1

static func create(client: Client, invitation: InvitationV1, header: SealedInvitationHeaderV1) throws -> ConversationV2 {
Expand All @@ -46,30 +48,33 @@ public struct ConversationV2 {
context: invitation.context,
peerAddress: peerAddress,
client: client,
createdAtNs: header.createdNs,
header: header
)
}

public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client) {
public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client, createdAtNs: UInt64? = nil) {
self.topic = topic
self.keyMaterial = keyMaterial
self.context = context
self.peerAddress = peerAddress
self.client = client
self.createdAtNs = createdAtNs
header = SealedInvitationHeaderV1()
}

public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client, header: SealedInvitationHeaderV1) {
public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client, createdAtNs: UInt64? = nil, header: SealedInvitationHeaderV1) {
self.topic = topic
self.keyMaterial = keyMaterial
self.context = context
self.peerAddress = peerAddress
self.client = client
self.createdAtNs = createdAtNs
self.header = header
}

public var encodedContainer: ConversationV2Container {
ConversationV2Container(topic: topic, keyMaterial: keyMaterial, conversationID: context.conversationID, metadata: context.metadata, peerAddress: peerAddress, header: header)
ConversationV2Container(topic: topic, keyMaterial: keyMaterial, conversationID: context.conversationID, metadata: context.metadata, peerAddress: peerAddress, createdAtNs: createdAtNs, header: header)
}

func prepareMessage(encodedContent: EncodedContent, options: SendOptions?) async throws -> PreparedMessage {
Expand Down Expand Up @@ -189,7 +194,7 @@ public struct ConversationV2 {
}

public var createdAt: Date {
Date(timeIntervalSince1970: Double(header.createdNs / 1_000_000) / 1000)
Date(timeIntervalSince1970: Double((createdAtNs ?? header.createdNs) / 1_000_000) / 1000)
}

public func decode(envelope: Envelope) throws -> DecodedMessage {
Expand Down
3 changes: 2 additions & 1 deletion Sources/XMTP/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public actor Conversations {
keyMaterial: data.invitation.aes256GcmHkdfSha256.keyMaterial,
context: data.invitation.context,
peerAddress: data.peerAddress,
client: client
client: client,
createdAtNs: data.createdNs
))
}
conversationsByTopic[conversation.topic] = conversation
Expand Down
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.7.5-alpha0"
spec.version = "0.7.6-alpha0"
spec.summary = "XMTP SDK Cocoapod"

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

0 comments on commit f4f24aa

Please sign in to comment.