Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions Modules/Sources/Support/Extensions/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@ extension String {
}
}

extension AttributedString {
func toHtml() -> String {
NSAttributedString(self).toHtml()
}
}

extension NSAttributedString {
func toHtml() -> String {
let documentAttributes = [
NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html
]

guard
let htmlData = try? self.data(from: NSMakeRange(0, self.length), documentAttributes: documentAttributes),
let htmlString = String(data: htmlData, encoding: .utf8)
else {
return self.string
}

return htmlString
}
}

func convertMarkdownHeadingsToBold(in markdown: String) -> String {
let lines = markdown.components(separatedBy: .newlines)
var convertedLines: [String] = []
Expand Down
224 changes: 0 additions & 224 deletions Modules/Sources/Support/InternalDataProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extension SupportDataProvider {
applicationLogProvider: InternalLogDataProvider(),
botConversationDataProvider: InternalBotConversationDataProvider(),
userDataProvider: InternalUserDataProvider(),
supportConversationDataProvider: InternalSupportConversationDataProvider(),
diagnosticsDataProvider: InternalDiagnosticsDataProvider(),
mediaHost: InternalMediaHost()
)
Expand Down Expand Up @@ -107,156 +106,6 @@ extension SupportDataProvider {
)
])
}

static let supportConversationSummaries: [ConversationSummary] = [
ConversationSummary(
id: 1,
title: "Login Issues with Two-Factor Authentication",
description: "I'm having trouble logging into my account. The two-factor authentication code isn't working properly and I keep getting locked out.",
status: .waitingForSupport,
lastMessageSentAt: Date().addingTimeInterval(-300) // 5 minutes ago
),
ConversationSummary(
id: 2,
title: "Billing Question - Duplicate Charges",
description: "I noticed duplicate charges on my credit card statement for this month's subscription. Can you help me understand what happened?",
status: .waitingForUser,
lastMessageSentAt: Date().addingTimeInterval(-3600) // 1 hour ago
),
ConversationSummary(
id: 3,
title: "Feature Request: Dark Mode Support",
description: "Would it be possible to add dark mode support to the mobile app? Many users in our team have been requesting this feature.",
status: .resolved,
lastMessageSentAt: Date().addingTimeInterval(-86400) // 1 day ago
),
ConversationSummary(
id: 4,
title: "Data Export Not Working",
description: "I'm trying to export my data but the process keeps failing at 50%. Is there a known issue with large datasets?",
status: .resolved,
lastMessageSentAt: Date().addingTimeInterval(-172800) // 2 days ago
),
ConversationSummary(
id: 5,
title: "Account Migration Assistance",
description: "I need help migrating my old account to the new system. I have several years of data that I don't want to lose.",
status: .resolved,
lastMessageSentAt: Date().addingTimeInterval(-259200) // 3 days ago
),
ConversationSummary(
id: 6,
title: "API Rate Limiting Questions",
description: "Our application is hitting rate limits frequently. Can we discuss increasing our API quota or optimizing our usage patterns?",
status: .closed,
lastMessageSentAt: Date().addingTimeInterval(-604800) // 1 week ago
),
ConversationSummary(
id: 7,
title: "Security Concern - Suspicious Activity",
description: "I received an email about suspicious activity on my account. I want to make sure my account is secure and review recent access logs.",
status: .closed,
lastMessageSentAt: Date().addingTimeInterval(-1209600) // 2 weeks ago
),
ConversationSummary(
id: 8,
title: "Integration Help with Webhook Setup",
description: "I'm having trouble setting up webhooks for our CRM integration. The endpoints aren't receiving the expected payload format.",
status: .closed,
lastMessageSentAt: Date().addingTimeInterval(-1814400) // 3 weeks ago
)
]

static let supportConversation = Conversation(
id: 1,
title: "Issue with app crashes",
description: "The app keeps crashing when I try to upload photos. This has been happening for the past week and is very frustrating.",
lastMessageSentAt: Date().addingTimeInterval(-2400),
status: .closed,
messages: [
Message(
id: 1,
content: "Hello! I'm having trouble with the app crashing when I try to upload photos. Can you help?",
createdAt: Date().addingTimeInterval(-3600),
authorName: "Test User",
authorIsUser: true,
attachments: []
),
Message(
id: 2,
content: "Hi there! I'm sorry to hear you're experiencing crashes. Let me help you troubleshoot this issue. Can you tell me what device you're using and what version of the app?",
createdAt: Date().addingTimeInterval(-3000),
authorName: "Support Engineer Alice",
authorIsUser: false,
attachments: []
),
Message(
id: 3,
content: "I'm using an iPhone 14 Pro with iOS 17.1 and the latest version of the app from the App Store. The crashes seem to happen right after I tap the Upload button and pick a photo from my library.",
createdAt: Date().addingTimeInterval(-2400),
authorName: "Test User",
authorIsUser: true,
attachments: []
)
,
Message(
id: 4,
content: "Understood. Do you notice this with any photo, or only certain ones (for example, very large HEIF images or Live Photos)?",
createdAt: Date().addingTimeInterval(-1950),
authorName: "Support Engineer Alice",
authorIsUser: false,
attachments: []
),
Message(
id: 5,
content: "It happens mostly with Live Photos. Regular photos sometimes work.",
createdAt: Date().addingTimeInterval(-1800),
authorName: "Test User",
authorIsUser: true,
attachments: [
Attachment(
id: 1234,
filename: "sample-1234.jpg",
contentType: "application/jpeg",
fileSize: 1234,
url: URL(string: "https://picsum.photos/seed/1/800/600")!
)
]
),
Message(
id: 6,
content: "Thanks, that helps. We recently fixed an issue with Live Photo processing. Could you try disabling Live Photo upload in Settings > Upload Options and try again?",
createdAt: Date().addingTimeInterval(-1650),
authorName: "Support Engineer Alice",
authorIsUser: false,
attachments: []
),
Message(
id: 7,
content: "I disabled Live Photo upload and the app no longer crashes. Upload works now!",
createdAt: Date().addingTimeInterval(-1500),
authorName: "Test User",
authorIsUser: true,
attachments: []
),
Message(
id: 8,
content: "Great to hear! We'll include the fix in the next update so Live Photos work without disabling. In the meantime, you can keep that setting off. Anything else I can help with?",
createdAt: Date().addingTimeInterval(-1350),
authorName: "Support Engineer Alice",
authorIsUser: false,
attachments: []
),
Message(
id: 9,
content: "No, that's all. Thanks for the quick help!",
createdAt: Date().addingTimeInterval(-1200),
authorName: "Test User",
authorIsUser: true,
attachments: []
)
]
)
}

actor InternalLogDataProvider: ApplicationLogDataProvider {
Expand Down Expand Up @@ -347,79 +196,6 @@ actor InternalUserDataProvider: CurrentUserDataProvider {
}
}

actor InternalSupportConversationDataProvider: SupportConversationDataProvider {
let maximumUploadSize: UInt64 = 5_000_000 // 5MB

private var conversations: [UInt64: Conversation] = [:]

nonisolated func loadSupportConversations() throws -> any CachedAndFetchedResult<[ConversationSummary]> {
UncachedResult {
return await SupportDataProvider.supportConversationSummaries
}
}

nonisolated func loadSupportConversation(id: UInt64) throws -> any CachedAndFetchedResult<Conversation> {
UncachedResult {
let conversation = await SupportDataProvider.supportConversation
await self.cache(conversation)
return conversation
}
}

func replyToSupportConversation(
id: UInt64,
message: String,
user: SupportUser,
attachments: [URL]
) async throws -> Conversation {

let conversation = try await loadSupportConversation(id: id).fetchedResult()

if Bool.random() {
throw CocoaError(.validationInvalidDate)
}

let newMessage = Message(
id: UInt64.random(in: 0...UInt64.max),
content: message,
createdAt: Date(),
authorName: user.username,
authorIsUser: true,
attachments: [] // TODO
)

try await Task.sleep(for: .seconds(3))
return conversation.addingMessage(newMessage)
}

func createSupportConversation(
subject: String,
message: String,
user: SupportUser,
attachments: [URL]
) async throws -> Conversation {
return Conversation(
id: 9999,
title: subject,
description: message,
lastMessageSentAt: Date(),
status: .waitingForSupport,
messages: [Message(
id: 1234,
content: message,
createdAt: Date(),
authorName: user.username,
authorIsUser: true,
attachments: []
)]
)
}

private func cache(_ value: Conversation) {
self.conversations[value.id] = value
}
}

actor InternalDiagnosticsDataProvider: DiagnosticsDataProvider {

private var didClear: Bool = false
Expand Down
Loading