ChatService class

ChatService provides methods to interact with chat functionalities such as sending messages, updating last seen, and managing chat summaries.

Constructors

ChatService.new()
Factory constructor to return the singleton instance
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
initialLimit int
The initial limit for message pagination.
getter/setter pair
lastDocument ↔ QueryDocumentSnapshot<Map<String, dynamic>>
The last document fetched for pagination.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

deleteMessage(String chatId, String messageId) Future<void>
Delete a message and its associated media (if any)
fetchMessages(String chatId, {Message? lastMessage}) Future<List<Message>>
Fetches messages for a chat, optionally paginated after lastMessage.
getChatId(String user1, String user2) String
Generate a unique chat ID based on user IDs
getLastSeen(String userId) Stream<Timestamp?>
Returns a stream of the last seen timestamp for a user.
getUserChats(String userId) Stream<List<ChatSummary>>
Get a stream of chat summaries for a specific user
initializeFirebase() Future<void>
Initializes Firebase for chat services.
markMessagesAsRead(String chatId, String currentUserId) Future<void>
Mark all unread messages as "read" when the recipient opens the chat
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendMessage(Message message) Future<void>
Sends a new message and updates chat summary.
setTypingStatus(String senderId, String receiverId, bool isTyping) Future<void>
Set the typing status for a user in a chat This updates the typing status in Firestore for the specified chat and user.
streamLatestMessages(String chatId) Stream<List<Message>>
Streams the latest messages for a chat, limited to the initial limit.
streamTotalUnreadMessagesForUser(String userId) Stream<int>
Get the total unread messages for a specific user
toString() String
A string representation of this object.
inherited
typingStatusStream(String senderId, String receiverId) Stream<bool>
Get the typing status of the other user in a chat Returns a stream that emits true if the other user is typing, false otherwise.
updateLastSeen(String userId) Future<void>
Updates the last seen timestamp for a user.
updateMessageStatus(String chatId, String messageId, MessageStatus status) Future<void>
Update message status (delivered, unread, read)

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

instance ChatService
Singleton instance
final