Files
halobestie-clone/client_app/lib/core/constants.dart
ramadhan sjamsani 14b5cc966b Phase 4 Stage 6: chat-room countdown UX + voice-call mode pill
Customer chat screen:
- Voice-call header pill (mode == 'call' renders accent-colored pill;
  chat mode renders no pill).
- HaloSnackbar fires once per session at 180s remaining ('sisa 3 menit
  lagi ya 🤍'), driven by the backend session_warning WS event.
- Last-2-min danger styling: timer pill flips to HaloTokens.danger +
  bold JetBrainsMono when remaining <= 120s.
- Floating ChatExpiredBanner widget injected above the input bar when
  remaining hits 0 in closing-grace state. perpanjang -> existing
  pricing bottom sheet.
- pricing_bottom_sheet.dart rewritten to the 5-option layout with
  chat|call mode toggle (mirrors duration-pick from Stage 3).

Mitra chat screen: voice-call header pill only (no countdown UX per PRD).

Backend:
- session.service.js getSessionById JOINs payment_sessions so mode +
  expires_at ship in /api/shared/chat/:id/info.
- session-timer.service.js onThreeMinuteWarning now emits expires_at +
  remaining_seconds for client resync.
- Dev-only POST /internal/_test/force-session-expires-at clears the
  3-min flag, reschedules the timer, and broadcasts WS resync. Lets
  the Maestro flow drive 175s -> 90s -> 0s without waiting live.

New chatRemainingSeconds StreamProvider derived from expiresAt, fed by
session_warning / session_timer / session_expired resync messages
(plan referenced a secondsLeftProvider that didn't actually exist).

Maestro 06_chat_countdown.yaml + force_session_expires_at.js helper.

Out of scope: meet.google.com URL launching - url_launcher isn't a
client_app dependency and message bubbles render plain Text. Defer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 17:25:11 +08:00

178 lines
5.4 KiB
Dart

/// Format a remaining-seconds countdown for display in a button or label.
/// - Under 90 seconds: "Xd" (e.g. "60d")
/// - 90 seconds and up: "Xm Yd" (e.g. "11m 40d")
/// `d` and `m` are Indonesian short forms for detik (second) and menit (minute).
String formatCountdown(int totalSeconds) {
if (totalSeconds < 90) return '${totalSeconds}d';
final minutes = totalSeconds ~/ 60;
final seconds = totalSeconds % 60;
return '${minutes}m ${seconds}d';
}
/// Format an integer rupiah amount with dot thousand-separators: 1234567 → "Rp 1.234.567".
String formatRupiah(int amount) {
final str = amount.toString();
final buffer = StringBuffer();
for (var i = 0; i < str.length; i++) {
if (i > 0 && (str.length - i) % 3 == 0) buffer.write('.');
buffer.write(str[i]);
}
return 'Rp $buffer';
}
/// 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._();
}
/// Session mode — chat or voice call. Mirrors backend `payment_sessions.mode`
/// (added in Phase 4 stage 1). A `call` session is functionally a chat with a
/// "voice call" badge and (eventually) a Meet link the mitra pastes manually;
/// no real audio transport is built yet.
enum SessionMode {
chat('chat'),
call('call');
final String value;
const SessionMode(this.value);
static SessionMode fromString(String? v) =>
values.firstWhere((e) => e.value == v, orElse: () => SessionMode.chat);
}
/// 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';
// Phase 4 — soft countdown warning (`kind: 'three_minutes_left'`).
// Customer-only: mitra never sees a countdown.
static const sessionWarning = 'session_warning';
// 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';
// Returning-chat (intermediate failures — payment stays confirmed)
static const returningChatTimeout = 'returning_chat_timeout';
static const returningChatRejected = 'returning_chat_rejected';
// Terminal pairing failure on a confirmed payment session
static const pairingFailed = 'pairing_failed';
WsMessage._();
}
/// Pairing-failure cause tags. Mirror of backend
/// `PairingFailureCause` (see backend/src/constants.js). Use for both routing
/// (terminal vs. intermediate) and surfacing copy on the failed-pairing screen.
enum PairingFailureCause {
noMitraAvailable('no_mitra_available'),
allMitrasRejected('all_mitras_rejected'),
targetedMitraOffline('targeted_mitra_offline'),
targetedMitraRejected('targeted_mitra_rejected'),
targetedMitraTimeout('targeted_mitra_timeout'),
paymentSessionExpired('payment_session_expired'),
customerCancelled('customer_cancelled'),
unknown('unknown');
final String value;
const PairingFailureCause(this.value);
static PairingFailureCause fromString(String? v) =>
values.firstWhere((e) => e.value == v, orElse: () => PairingFailureCause.unknown);
}
/// Payment session lifecycle. Mirror of backend
/// `PaymentSessionStatus`.
class PaymentSessionStatus {
static const pending = 'pending';
static const confirmed = 'confirmed';
static const consumed = 'consumed';
static const failedPairing = 'failed_pairing';
static const abandoned = 'abandoned';
static const expired = 'expired';
PaymentSessionStatus._();
}