hasUserSeenMessage method

Future<bool> hasUserSeenMessage(
  1. String roomId,
  2. String messageId
)

Checks if the user has seen a message.

Implementation

Future<bool> hasUserSeenMessage(String roomId, String messageId) async {
  final fu = firebaseUser;

  if (fu == null) return false;

  /// Fetch the current message document
  final messageDoc = await getFirebaseFirestore()
      .collection('${config.roomsCollectionName}/$roomId/messages')
      .doc(messageId)
      .get();

  if (!messageDoc.exists) return false;

  /// Get the current `seenBy` map
  final seenBy = messageDoc.data()?['seenBy'] as Map<String, dynamic>? ?? {};

  /// Check if the current user has already seen the message
  return seenBy.containsKey(fu.uid);
}