Skip to content

Commit

Permalink
update all streams
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 1, 2024
1 parent d5225e7 commit 22ada26
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension GenericErrorDescribing {
let .GroupMutablePermissions(message),
let .SignatureRequestError(message),
let .Erc1271SignatureError(message),
let .FailedToConvertToU32(message),
let .Verifier(message):
return message
}
Expand Down
25 changes: 12 additions & 13 deletions Sources/XMTPiOS/Conversations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public enum ConversationOrder {
}

final class ConversationStreamCallback: FfiConversationCallback {
func onError(error: LibXMTP.FfiSubscribeError) {
print("Error ConversationStreamCallback \(error)")
}

let callback: (FfiConversation) -> Void

init(callback: @escaping (FfiConversation) -> Void) {
Expand All @@ -66,6 +70,10 @@ final class ConversationStreamCallback: FfiConversationCallback {
}

final class V2SubscriptionCallback: FfiV2SubscriptionCallback {
func onError(error: LibXMTP.GenericError) {
print("Error V2SubscriptionCallback \(error)")
}

let callback: (Envelope) -> Void

init(callback: @escaping (Envelope) -> Void) {
Expand Down Expand Up @@ -139,7 +147,7 @@ public actor Conversations {
guard let v3Client = client.v3Client else {
return []
}
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil)
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil, consentState: nil)
if let createdAfter {
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
}
Expand All @@ -159,7 +167,7 @@ public actor Conversations {
guard let v3Client = client.v3Client else {
return []
}
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil)
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil, consentState: nil)
if let createdAfter {
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
}
Expand All @@ -180,7 +188,7 @@ public actor Conversations {
guard let v3Client = client.v3Client else {
return []
}
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil)
var options = FfiListConversationsOptions(createdAfterNs: nil, createdBeforeNs: nil, limit: nil, consentState: consentState?.toFFI)
if let createdAfter {
options.createdAfterNs = Int64(createdAfter.millisecondsSinceEpoch)
}
Expand All @@ -192,8 +200,7 @@ public actor Conversations {
}
let ffiConversations = try await v3Client.conversations().list(opts: options)

let filteredConversations = try filterByConsentState(ffiConversations, consentState: consentState)
let sortedConversations = try sortConversations(filteredConversations, order: order)
let sortedConversations = try sortConversations(ffiConversations, order: order)

return try sortedConversations.map { try $0.toConversation(client: client) }
}
Expand Down Expand Up @@ -226,14 +233,6 @@ public actor Conversations {
}
}

private func filterByConsentState(
_ conversations: [FfiConversation],
consentState: ConsentState?
) throws -> [FfiConversation] {
guard let state = consentState else { return conversations }
return try conversations.filter { try $0.consentState() == state.toFFI }
}

public func streamGroups() async throws -> AsyncThrowingStream<Group, Error> {
AsyncThrowingStream { continuation in
let ffiStreamActor = FfiStreamActor()
Expand Down
4 changes: 3 additions & 1 deletion Sources/XMTPiOS/Dm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public struct Dm: Identifiable, Equatable, Hashable {
}

public var peerInboxId: String {
ffiConversation.dmPeerInboxId()
get throws {
try ffiConversation.dmPeerInboxId()
}
}

public var createdAt: Date {
Expand Down
4 changes: 4 additions & 0 deletions Sources/XMTPiOS/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import Foundation
import LibXMTP

final class MessageCallback: FfiMessageCallback {
func onError(error: LibXMTP.FfiSubscribeError) {
print("Error MessageCallback \(error)")
}

let client: Client
let callback: (LibXMTP.FfiMessage) -> Void

Expand Down

0 comments on commit 22ada26

Please sign in to comment.