11import Foundation
2+ import WordPressCore
23
34public enum SupportFormAction {
45 case viewSupportForm
56}
67
8+ public enum DiagnosticAction {
9+ case clearDiskCache
10+ }
11+
12+ public enum DiagnosticActionStatus {
13+ case running( progress: Float )
14+ case success
15+ case error( Error )
16+ }
17+
718@MainActor
819public final class SupportDataProvider : ObservableObject , Sendable {
920
@@ -33,34 +44,38 @@ public final class SupportDataProvider: ObservableObject, Sendable {
3344 self . supportDelegate? . userDid ( action)
3445 }
3546
47+ public func userDid( _ action: DiagnosticAction , progress: @escaping ( DiagnosticActionStatus ) -> Void ) {
48+ self . supportDelegate? . userDid ( action, progress: progress)
49+ }
50+
3651 // Support Bots Data Source
37- public func loadSupportIdentity( ) async throws -> SupportUser {
52+ public func loadSupportIdentity( ) async throws -> any CachedAndFetchedResult < SupportUser > {
3853 try await self . userDataProvider. fetchCurrentSupportUser ( )
3954 }
4055
4156 // Bot Conversation Data Source
42- public func loadConversations( ) async throws -> [ BotConversation ] {
57+ public func loadConversations( ) async throws -> any CachedAndFetchedResult < [ BotConversation ] > {
4358 try await self . botConversationDataProvider. loadBotConversations ( )
4459 }
4560
46- public func loadConversation( id: UInt64 ) async throws -> BotConversation ? {
61+ public func loadConversation( id: UInt64 ) async throws -> any CachedAndFetchedResult < BotConversation > {
4762 try await self . botConversationDataProvider. loadBotConversation ( id: id)
4863 }
4964
5065 public func delete( conversationIds: [ UInt64 ] ) async throws {
5166 try await self . botConversationDataProvider. delete ( conversationIds: conversationIds)
5267 }
5368
54- public func sendMessage( message: String , in conversation: BotConversation ? ) async throws -> BotConversation {
69+ public func sendMessage( message: String , in conversation: BotConversation ? = nil ) async throws -> BotConversation {
5570 try await self . botConversationDataProvider. sendMessage ( message: message, in: conversation)
5671 }
5772
5873 // Support Conversations Data Source
59- public func loadSupportConversations( ) async throws -> [ ConversationSummary ] {
74+ public func loadSupportConversations( ) async throws -> any CachedAndFetchedResult < [ ConversationSummary ] > {
6075 try await self . supportConversationDataProvider. loadSupportConversations ( )
6176 }
6277
63- public func loadSupportConversation( id: UInt64 ) async throws -> Conversation {
78+ public func loadSupportConversation( id: UInt64 ) async throws -> any CachedAndFetchedResult < Conversation > {
6479 try await self . supportConversationDataProvider. loadSupportConversation ( id: id)
6580 }
6681
@@ -147,10 +162,16 @@ extension SupportFormDataProvider {
147162
148163public protocol SupportDelegate : NSObject {
149164 func userDid( _ action: SupportFormAction )
165+ func userDid( _ action: DiagnosticAction , progress: ( DiagnosticActionStatus ) -> Void )
166+ }
167+
168+ public enum SupportUserPermission : Sendable , Codable {
169+ case createChatConversation
170+ case createSupportRequest
150171}
151172
152173public protocol CurrentUserDataProvider : Actor {
153- func fetchCurrentSupportUser( ) async throws -> SupportUser
174+ func fetchCurrentSupportUser( ) async throws -> any CachedAndFetchedResult < SupportUser >
154175}
155176
156177public protocol ApplicationLogDataProvider : Actor {
@@ -173,16 +194,16 @@ public extension ApplicationLogDataProvider {
173194}
174195
175196public protocol BotConversationDataProvider : Actor {
176- func loadBotConversations( ) async throws -> [ BotConversation ]
177- func loadBotConversation( id: UInt64 ) async throws -> BotConversation ?
197+ func loadBotConversations( ) async throws -> any CachedAndFetchedResult < [ BotConversation ] >
198+ func loadBotConversation( id: UInt64 ) async throws -> any CachedAndFetchedResult < BotConversation >
178199
179200 func sendMessage( message: String , in conversation: BotConversation ? ) async throws -> BotConversation
180201 func delete( conversationIds: [ UInt64 ] ) async throws
181202}
182203
183204public protocol SupportConversationDataProvider : Actor {
184- func loadSupportConversations( ) async throws -> [ ConversationSummary ]
185- func loadSupportConversation( id: UInt64 ) async throws -> Conversation
205+ func loadSupportConversations( ) async throws -> any CachedAndFetchedResult < [ ConversationSummary ] >
206+ func loadSupportConversation( id: UInt64 ) async throws -> any CachedAndFetchedResult < Conversation >
186207
187208 func replyToSupportConversation(
188209 id: UInt64 ,
0 commit comments