Skip to content

Commit

Permalink
Update ConversationV2 struct to use createdAtNs instead of createdAt
Browse files Browse the repository at this point in the history
  • Loading branch information
kele-leanes committed Jan 17, 2024
1 parent d73d88b commit 27102d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions Sources/XMTP/ConversationV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public struct ConversationV2Container: Codable {
var conversationID: String?
var metadata: [String: String] = [:]
var peerAddress: String
var createdAt: UInt64?
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, createdAt: createdAt, header: header)
return ConversationV2(topic: topic, keyMaterial: keyMaterial, context: context, peerAddress: peerAddress, client: client, createdAtNs: createdAtNs, header: header)
}
}

Expand Down Expand Up @@ -48,33 +48,33 @@ public struct ConversationV2 {
context: invitation.context,
peerAddress: peerAddress,
client: client,
createdAt: header.createdNs,
createdAtNs: header.createdNs,
header: header
)
}

public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client, createdAt: UInt64? = nil) {
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 = createdAt
self.createdAtNs = createdAtNs
header = SealedInvitationHeaderV1()
}

public init(topic: String, keyMaterial: Data, context: InvitationV1.Context, peerAddress: String, client: Client, createdAt: UInt64? = nil, 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 = createdAt
self.createdAtNs = createdAtNs
self.header = header
}

public var encodedContainer: ConversationV2Container {
ConversationV2Container(topic: topic, keyMaterial: keyMaterial, conversationID: context.conversationID, metadata: context.metadata, peerAddress: peerAddress, createdAt: createdAtNs, 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
2 changes: 1 addition & 1 deletion Sources/XMTP/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public actor Conversations {
context: data.invitation.context,
peerAddress: data.peerAddress,
client: client,
createdAt: data.createdNs
createdAtNs: data.createdNs
))
}
conversationsByTopic[conversation.topic] = conversation
Expand Down
2 changes: 1 addition & 1 deletion Tests/XMTPTests/MessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class MessageTests: XCTestCase {
return
}

let conversation = ConversationV2(topic: decodedConversation.topic, keyMaterial: decodedConversation.keyMaterial, context: InvitationV1.Context(), peerAddress: decodedConversation.peerAddress, client: client, createdAt: decodedConversation.createdAt, header: SealedInvitationHeaderV1())
let conversation = ConversationV2(topic: decodedConversation.topic, keyMaterial: decodedConversation.keyMaterial, context: InvitationV1.Context(), peerAddress: decodedConversation.peerAddress, client: client, header: SealedInvitationHeaderV1())

let decodedMessage = try conversation.decode(envelope: envelope)
XCTAssertEqual(decodedMessage.id, "e42a7dd44d0e1214824eab093cb89cfe6f666298d0af2d54fe0c914c8b72eff3")
Expand Down

0 comments on commit 27102d5

Please sign in to comment.