diff --git a/Sources/XMTP/ConversationV2.swift b/Sources/XMTP/ConversationV2.swift index 05847157..cd345d9b 100644 --- a/Sources/XMTP/ConversationV2.swift +++ b/Sources/XMTP/ConversationV2.swift @@ -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) } } @@ -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 { @@ -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 { @@ -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 { diff --git a/Sources/XMTP/Conversations.swift b/Sources/XMTP/Conversations.swift index d26b5b49..b6e2072a 100644 --- a/Sources/XMTP/Conversations.swift +++ b/Sources/XMTP/Conversations.swift @@ -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 diff --git a/XMTP.podspec b/XMTP.podspec index 8b4ec473..547b4645 100644 --- a/XMTP.podspec +++ b/XMTP.podspec @@ -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.