Skip to content

Commit

Permalink
remove decrypted message
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 7, 2024
1 parent 7c14fc0 commit 7b1f5f2
Show file tree
Hide file tree
Showing 14 changed files with 4 additions and 620 deletions.
39 changes: 0 additions & 39 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,45 +423,6 @@ public actor Conversations {
}
}

public func streamAllDecryptedConversationMessages() -> AsyncThrowingStream<
DecryptedMessage, Error
> {
AsyncThrowingStream { continuation in
let ffiStreamActor = FfiStreamActor()
let task = Task {
let stream = await self.client.v3Client?.conversations()
.streamAllMessages(
messageCallback: MessageCallback(client: self.client) {
message in
guard !Task.isCancelled else {
continuation.finish()
Task {
await ffiStreamActor.endStream() // End the stream upon cancellation
}
return
}
do {
continuation.yield(
try MessageV3(
client: self.client, ffiMessage: message
).decrypt())
} catch {
print("Error onMessage \(error)")
}
}
)
await ffiStreamActor.setFfiStream(stream)
}

continuation.onTermination = { _ in
task.cancel()
Task {
await ffiStreamActor.endStream()
}
}
}
}

public func fromWelcome(envelopeBytes: Data) async throws
-> Conversation?
{
Expand Down
98 changes: 0 additions & 98 deletions Sources/XMTPiOS/Dm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,42 +203,6 @@ public struct Dm: Identifiable, Equatable, Hashable {
}
}

public func streamDecryptedMessages() -> AsyncThrowingStream<
DecryptedMessage, Error
> {
AsyncThrowingStream { continuation in
let task = Task.detached {
self.streamHolder.stream = await self.ffiConversation.stream(
messageCallback: MessageCallback(client: self.client) {
message in
guard !Task.isCancelled else {
continuation.finish()
return
}
do {
continuation.yield(
try MessageV3(
client: self.client, ffiMessage: message
).decrypt())
} catch {
print("Error onMessage \(error)")
continuation.finish(throwing: error)
}
}
)

continuation.onTermination = { @Sendable reason in
self.streamHolder.stream?.end()
}
}

continuation.onTermination = { @Sendable reason in
task.cancel()
self.streamHolder.stream?.end()
}
}
}

public func messages(
before: Date? = nil,
after: Date? = nil,
Expand Down Expand Up @@ -300,66 +264,4 @@ public struct Dm: Identifiable, Equatable, Hashable {
.decodeOrNull()
}
}

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

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

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

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

let status: FfiDeliveryStatus? = {
switch deliveryStatus {
case .published:
return FfiDeliveryStatus.published
case .unpublished:
return FfiDeliveryStatus.unpublished
case .failed:
return FfiDeliveryStatus.failed
default:
return nil
}
}()

options.deliveryStatus = status

let direction: FfiDirection? = {
switch direction {
case .ascending:
return FfiDirection.ascending
default:
return FfiDirection.descending
}
}()

options.direction = direction

return try ffiConversation.findMessages(opts: options).compactMap {
ffiMessage in
return MessageV3(client: self.client, ffiMessage: ffiMessage)
.decryptOrNull()
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import Foundation
import LibXMTP

enum MessageV3Error: Error {
enum MessageError: Error {
case decodeError(String)
}

public struct MessageV3: Identifiable {
public struct Message: Identifiable {
let client: Client
let ffiMessage: FfiMessage

Expand Down Expand Up @@ -54,7 +54,6 @@ public struct MessageV3: Identifiable {

let decodedMessage = DecodedMessage(
id: id,
client: client,
topic: Topic.groupMessage(convoId).description,
encodedContent: encodedContent,
senderAddress: senderInboxId,
Expand All @@ -63,12 +62,12 @@ public struct MessageV3: Identifiable {
)

if decodedMessage.encodedContent.type == ContentTypeGroupUpdated && ffiMessage.kind != .membershipChange {
throw MessageV3Error.decodeError("Error decoding group membership change")
throw MessageError.decodeError("Error decoding group membership change")
}

return decodedMessage
} catch {
throw MessageV3Error.decodeError("Error decoding message: \(error.localizedDescription)")
throw MessageError.decodeError("Error decoding message: \(error.localizedDescription)")
}
}

Expand All @@ -80,32 +79,4 @@ public struct MessageV3: Identifiable {
return nil
}
}

public func decryptOrNull() -> DecryptedMessage? {
do {
return try decrypt()
} catch {
print("MESSAGE_V3: discarding message that failed to decrypt", error)
return nil
}
}

public func decrypt() throws -> DecryptedMessage {
let encodedContent = try EncodedContent(serializedData: ffiMessage.content)

let decrytedMessage = DecryptedMessage(
id: id,
encodedContent: encodedContent,
senderAddress: senderInboxId,
sentAt: sentAt,
topic: Topic.groupMessage(convoId).description,
deliveryStatus: deliveryStatus
)

if decrytedMessage.encodedContent.type == ContentTypeGroupUpdated && ffiMessage.kind != .membershipChange {
throw MessageV3Error.decodeError("Error decoding group membership change")
}

return decrytedMessage
}
}
17 changes: 0 additions & 17 deletions Sources/XMTPiOS/Messages/DecryptedMessage.swift

This file was deleted.

33 changes: 0 additions & 33 deletions Sources/XMTPiOS/Messages/Message.swift

This file was deleted.

19 changes: 0 additions & 19 deletions Sources/XMTPiOS/Messages/MessageHeaderV1.swift

This file was deleted.

18 changes: 0 additions & 18 deletions Sources/XMTPiOS/Messages/MessageHeaderV2.swift

This file was deleted.

Loading

0 comments on commit 7b1f5f2

Please sign in to comment.