@@ -2,7 +2,27 @@ import Foundation
22import WordPressCore
33
44public enum SupportFormAction {
5- case viewSupportForm
5+ case viewApplicationLogList
6+ case viewApplicationLog( String )
7+ case deleteApplicationLogs( [ String ] )
8+ case deleteAllApplicationLogs
9+
10+ case viewSupportBotConversationList
11+ case startSupportBotConversation
12+ case viewSupportBotConversation( conversationId: UInt64 )
13+ case replyToSupportBotMessage( conversationId: UInt64 )
14+ case failToCreateBotConversation( Error )
15+ case failToReplyToBotConversation( Error )
16+
17+ case viewSupportTicketList
18+ case viewSupportTicket( ticketId: UInt64 )
19+ case createSupportTicket
20+ case replyToSupportTicket( ticketId: UInt64 )
21+ case failToCreateSupportTicket( Error )
22+ case failToReplyToSupportTicket( Error )
23+
24+ case viewDiagnostics
25+ case emptyDiskCache( bytesSaved: Int64 )
626}
727
828@MainActor
@@ -53,7 +73,23 @@ public final class SupportDataProvider: ObservableObject, Sendable {
5373 }
5474
5575 public func sendMessage( message: String , in conversation: BotConversation ? = nil ) async throws -> BotConversation {
56- try await self . botConversationDataProvider. sendMessage ( message: message, in: conversation)
76+ if let conversation {
77+ self . userDid ( . replyToSupportBotMessage( conversationId: conversation. id) )
78+ } else {
79+ self . userDid ( . startSupportBotConversation)
80+ }
81+
82+ do {
83+ return try await self . botConversationDataProvider. sendMessage ( message: message, in: conversation)
84+ } catch {
85+ if conversation != nil {
86+ self . userDid ( . failToCreateBotConversation( error) )
87+ } else {
88+ self . userDid ( . failToReplyToBotConversation( error) )
89+ }
90+
91+ throw error
92+ }
5793 }
5894
5995 // Support Conversations Data Source
@@ -71,12 +107,19 @@ public final class SupportDataProvider: ObservableObject, Sendable {
71107 user: SupportUser ,
72108 attachments: [ URL ]
73109 ) async throws -> Conversation {
74- try await self . supportConversationDataProvider. replyToSupportConversation (
75- id: id,
76- message: message,
77- user: user,
78- attachments: attachments
79- )
110+ self . userDid ( . replyToSupportTicket( ticketId: id) )
111+
112+ do {
113+ return try await self . supportConversationDataProvider. replyToSupportConversation (
114+ id: id,
115+ message: message,
116+ user: user,
117+ attachments: attachments
118+ )
119+ } catch {
120+ self . userDid ( . failToReplyToSupportTicket( error) )
121+ throw error
122+ }
80123 }
81124
82125 public func createSupportConversation(
@@ -85,12 +128,19 @@ public final class SupportDataProvider: ObservableObject, Sendable {
85128 user: SupportUser ,
86129 attachments: [ URL ]
87130 ) async throws -> Conversation {
88- try await self . supportConversationDataProvider. createSupportConversation (
89- subject: subject,
90- message: message,
91- user: user,
92- attachments: attachments
93- )
131+ self . userDid ( . createSupportTicket)
132+
133+ do {
134+ return try await self . supportConversationDataProvider. createSupportConversation (
135+ subject: subject,
136+ message: message,
137+ user: user,
138+ attachments: attachments
139+ )
140+ } catch {
141+ self . userDid ( . failToCreateSupportTicket( error) )
142+ throw error
143+ }
94144 }
95145
96146 // Application Logs
@@ -103,10 +153,12 @@ public final class SupportDataProvider: ObservableObject, Sendable {
103153 }
104154
105155 public func deleteApplicationLogs( in list: [ ApplicationLog ] ) async throws {
156+ self . userDid ( . deleteApplicationLogs( list. map ( { $0. id } ) ) )
106157 try await self . applicationLogProvider. deleteApplicationLogs ( in: list)
107158 }
108159
109160 public func deleteAllApplicationLogs( ) async throws {
161+ self . userDid ( . deleteAllApplicationLogs)
110162 try await self . applicationLogProvider. deleteAllApplicationLogs ( )
111163 }
112164}
0 commit comments