Files
halobestie-clone/mitra_app/lib/core/constants.dart
ramadhan sjamsani 89afd01899 Phase 3.5: Mitra Chat Request History (backend route + mitra app screens)
Replaces the home-screen pending-requests banner with a "Riwayat
Permintaan" CTA that opens a list of the mitra's last 20 chat requests
(any status). Pending rows pin to the top; non-pending rows open a
read-only detail screen with a "Lihat percakapan" CTA on accepted rows.

Backend:
- New service `getRecentRequestsForMitra(mitraId, { limit })` capped at
  20, pending pinned via `(response IS NULL AND status='pending_acceptance')
  DESC`. Customer call_name returned verbatim, with `'Anonim'` only as
  null-safety fallback (no anonymity-flag masking — see project memory).
- New route `GET /api/mitra/chat-requests/recent`. Strictly per-mitra
  scoped via the existing `resolveMitra` preHandler.

Mitra app:
- New `RequestResponse` enum in core/constants.dart.
- New Riverpod notifier `requestHistoryProvider` (AsyncValue<List<...>>,
  keepAlive) — pull-to-refresh + screen-mount fetch only, no WS.
- Two new screens (history list + detail) and two new GoRoutes.
- Home screen: `_PendingRequestsBanner` removed → `_RequestHistoryButton`
  Card with red count badge. Live count comes from the existing
  chatRequestProvider so nothing changes about the WS-driven badge math.

Plan + acceptance criteria in requirement/phase3.5-plan.md. flutter
analyze clean (zero new issues). Backend smoke-tested against real DB.
Real-device E2E pending.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 18:59:17 +08:00

119 lines
2.9 KiB
Dart

/// User types
class UserType {
static const customer = 'customer';
static const mitra = 'mitra';
UserType._();
}
/// Chat session statuses
class SessionStatus {
static const searching = 'searching';
static const pendingAcceptance = 'pending_acceptance';
static const pendingPayment = 'pending_payment';
static const active = 'active';
static const extending = 'extending';
static const closing = 'closing';
static const completed = 'completed';
static const cancelled = 'cancelled';
static const expired = 'expired';
SessionStatus._();
}
/// Chat message statuses
class MessageStatus {
static const sent = 'sent';
static const delivered = 'delivered';
static const read = 'read';
MessageStatus._();
}
/// Chat message types
class MessageType {
static const text = 'text';
MessageType._();
}
/// Session extension statuses
class ExtensionStatus {
static const pending = 'pending';
static const accepted = 'accepted';
static const rejected = 'rejected';
static const timeout = 'timeout';
ExtensionStatus._();
}
/// Chat request notification responses (Phase 3.5).
/// `null` on the wire means "still pending" — no enum value.
enum RequestResponse {
accepted('accepted'),
declined('declined'),
missed('missed'),
ignored('ignored');
final String value;
const RequestResponse(this.value);
static RequestResponse? fromString(String? v) {
if (v == null) return null;
for (final e in values) {
if (e.value == v) return e;
}
return null;
}
}
/// Session topic sensitivity
enum TopicSensitivity {
regular('regular'),
sensitive('sensitive');
final String value;
const TopicSensitivity(this.value);
static TopicSensitivity fromString(String? v) =>
values.firstWhere((e) => e.value == v, orElse: () => TopicSensitivity.regular);
}
/// WebSocket message types
class WsMessage {
// Auth
static const auth = 'auth';
static const authOk = 'auth_ok';
static const error = 'error';
// Chat
static const message = 'message';
static const messageAck = 'message_ack';
static const messageStatus = 'message_status';
static const typing = 'typing';
// Pairing
static const chatRequest = 'chat_request';
static const chatRequestClosed = 'chat_request_closed';
static const paired = 'paired';
// Session lifecycle
static const sessionTimer = 'session_timer';
static const sessionExpired = 'session_expired';
static const sessionClosing = 'session_closing';
static const sessionCompleted = 'session_completed';
static const sessionPaused = 'session_paused';
static const sessionResumed = 'session_resumed';
// Extension
static const extensionRequest = 'extension_request';
static const extensionResponse = 'extension_response';
// Topic sensitivity
static const sessionTopicUpdated = 'session_topic_updated';
// Delivery
static const delivered = 'delivered';
static const read = 'read';
// Early end
static const earlyEnd = 'early_end';
WsMessage._();
}