This commit is contained in:
2026-10-16 01:25:50 +05:30
commit c60ea2d370
89 changed files with 4661 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
import 'support_ticket.dart';
const maxReplyLength = 4000;
class SupportMessage {
const SupportMessage({
required this.id,
required this.ticketId,
required this.authorKind,
required this.authorName,
required this.body,
required this.createdAt,
});
final String id;
final String ticketId;
final String authorKind;
final String authorName;
final String body;
final DateTime createdAt;
bool get isStaff => authorKind == 'staff';
factory SupportMessage.fromJson(Map<String, dynamic> json) {
return SupportMessage(
id: json['id'] as String,
ticketId: json['ticketId'] as String,
authorKind: json['authorKind'] as String? ?? 'player',
authorName: json['authorName'] as String? ?? '',
body: json['body'] as String? ?? '',
createdAt: DateTime.parse(json['createdAt'] as String),
);
}
}
class SupportThread {
const SupportThread({required this.ticket, required this.messages});
final SupportTicket ticket;
final List<SupportMessage> messages;
factory SupportThread.fromJson(Map<String, dynamic> json) {
final ticketJson = json['ticket'];
final messagesJson = json['messages'];
if (ticketJson is! Map || messagesJson is! List) {
throw const FormatException('Unexpected thread payload');
}
return SupportThread(
ticket: SupportTicket.fromJson(Map<String, dynamic>.from(ticketJson)),
messages: [
for (final item in messagesJson)
if (item is Map)
SupportMessage.fromJson(Map<String, dynamic>.from(item)),
],
);
}
}
/// Returns an error message when [raw] is not 1–4000 characters after trim.
String? validateReplyBody(String raw) {
final body = raw.trim();
if (body.isEmpty) {
return 'Enter a message.';
}
if (body.length > maxReplyLength) {
return 'Message must be $maxReplyLength characters or fewer.';
}
return null;
}