getChatByUser method

  1. @override
Future<ChatModel> getChatByUser(
  1. ChatUserModel user
)

Retrieves a chat by the given user.

user: The user associated with the chat.

Implementation

@override
Future<ChatModel> getChatByUser(ChatUserModel user) async {
  var currentUser = await _userService.getCurrentUser();
  var collection = await _db
      .collection(_options.usersCollectionName)
      .doc(currentUser?.id)
      .collection(_options.userChatsCollectionName)
      .where('users', arrayContains: user.id)
      .get();

  var doc = collection.docs.isNotEmpty ? collection.docs.first : null;

  return PersonalChatModel(
    id: doc?.id,
    user: user,
  );
}