Files
TravelMate/lib/blocs/message/message_state.dart

99 lines
3.5 KiB
Dart

/// States for message-related operations in the MessageBloc.
///
/// This file defines all possible states that the MessageBloc can emit in response
/// to message-related events. The states represent different phases of message
/// operations including loading, success, and error states for real-time chat functionality.
///
/// State Categories:
/// - **Initial State**: MessageInitial
/// - **Loading States**: MessageLoading
/// - **Success States**: MessagesLoaded
/// - **Error States**: MessageError
///
/// The states support real-time chat features including message streaming,
/// reactions, editing, and deletion within group conversations.
///
/// All states extend [MessageState] and implement [Equatable] for proper
/// equality comparison and state change detection in the BLoC pattern.
library;
import 'package:equatable/equatable.dart';
import '../../models/message.dart';
/// Base class for all message-related states.
///
/// All message states must extend this class and implement the [props] getter
/// for proper equality comparison in the BLoC pattern.
abstract class MessageState extends Equatable {
const MessageState();
@override
List<Object?> get props => [];
}
/// The initial state of the MessageBloc before any operations are performed.
///
/// This is the default state when the bloc is first created and represents
/// a clean slate with no message data loaded or operations in progress.
class MessageInitial extends MessageState {}
/// State indicating that a message operation is currently in progress.
///
/// This state is emitted when the bloc is performing operations like
/// loading messages or initializing the real-time message stream.
/// UI components can use this state to show loading indicators.
class MessageLoading extends MessageState {}
/// State containing a list of successfully loaded messages for a group.
///
/// This state is emitted when messages have been successfully retrieved
/// from the repository, either through initial loading or real-time updates.
/// The state includes both the messages and the group ID for context.
/// The UI can use this data to display the chat conversation.
///
/// Properties:
/// [messages]: List of Message objects in the conversation
/// [groupId]: The unique identifier of the group these messages belong to
class MessagesLoaded extends MessageState {
/// The list of messages in the conversation
final List<Message> messages;
/// The unique identifier of the group
final String groupId;
/// Creates a MessagesLoaded state.
///
/// Args:
/// [messages]: The list of messages to include in this state
/// [groupId]: The group ID these messages belong to
const MessagesLoaded({
required this.messages,
required this.groupId,
});
@override
List<Object?> get props => [messages, groupId];
}
/// State indicating that a message operation has failed.
///
/// This state is emitted when any message operation encounters an error,
/// such as failing to load messages, send a message, or perform other
/// message-related operations. It contains an error message that can be
/// displayed to the user to explain what went wrong.
///
/// Properties:
/// [message]: An error message describing what went wrong
class MessageError extends MessageState {
/// The error message to display to the user
final String message;
/// Creates a MessageError state.
///
/// Args:
/// [message]: The error message to display
const MessageError(this.message);
@override
List<Object?> get props => [message];
}