updateStatus method

Future<void> updateStatus(
  1. UserStatusType type, {
  2. String? customMessage,
  3. bool forceUpdate = false,
})

Cập nhật trạng thái

Implementation

Future<void> updateStatus(
  UserStatusType type, {
  String? customMessage,
  bool forceUpdate = false,
}) async {
  _updateLastActivity();

  final now = DateTime.now().millisecondsSinceEpoch;
  final userId = loggedUsername;

  // Tạo hoặc cập nhật trạng thái trong cache
  final newStatus = UserStatusInfo(
    userId: userId,
    type: type,
    customMessage: type == UserStatusType.custom ? customMessage : null,
    lastSeenAt: now,
    needsUpdate: true,
  );

  _statusCache[userId] = newStatus;

  // Thông báo thay đổi
  _notifyStatusChange(userId);

  // Cập nhật ngay lập tức nếu cần
  if (forceUpdate) {
    await _syncWithServer();
  }
}