resolvedStatus property

MessageStatus? get resolvedStatus

Calculates the current status of the message based on its timestamps or status field. Returns null if the message has no specific status yet (only createdAt).

Implementation

MessageStatus? get resolvedStatus {
  if (status != null) return status;
  // Message status is determined by the most recent state change in the message lifecycle.
  // The order of checks matters - we check from most recent to oldest state.
  // Note: createdAt, updatedAt, and deletedAt are message states rather than statuses.
  if (metadata?['sending'] == true) return MessageStatus.sending;
  if (failedAt != null) return MessageStatus.error;
  if (seenAt != null) return MessageStatus.seen;
  if (deliveredAt != null) return MessageStatus.delivered;
  if (sentAt != null) return MessageStatus.sent;
  return null;
}