deleteChat method

dynamic deleteChat({
  1. required String chatId,
  2. required CollectionReference<Object?> chatCollection,
  3. Future<bool?> handleConfirmation()?,
  4. Future<bool?> handleError(
    1. Object
    )?,
})

//This all we will do later

Implementation

// sendNotification(){
//   // if (deviceIds.isNotEmpty) {
//   //   customPrint("datdatdatdatdtadatdatdta:::::::::");
//   //   customLogs(
//   //       "datdatdatdatdtadatdatdta:::::::::${userData?.fullData}");
//   //   Map<dynamic, dynamic> data = userData?.fullData ?? {};
//   //   data.remove("dateOfAccountCreation");
//   //   data.remove("lastLoginDate");
//   //   try {
//   //     FirebaseCloudMessagingV1().sendPushNotifications(
//   //
//   //
//   //         deviceIds: deviceIds,
//   //         data: {
//   //           ApiKeys.screenName: ScreenNames.chat_screen,
//   //           ApiKeys.chatId: getSessionId(message.to),
//   //           'isBlocked': isBlocked.toString(),
//   //           "data": data.toString(),
//   //           'notificationType': NotificationType.textMessage.name
//   //         },
//   //         body: notificationMessage ?? getNotificationMessage(message),
//   //         // body: '${message.message}',
//   //         title: notificationTitle ?? userData?.username ?? '');
//   //   } catch (e) {
//   //     customPrint("kskkcnknckncksnkcnks::::::::::::::::::::::${e}");
//   //   }
//   // }
// }

 deleteChat(
    {
      // bool isQwikChat = false,
      required String chatId,
      required CollectionReference chatCollection,

      Future<bool?> Function()? handleConfirmation,
      Future<bool?> Function(Object)? handleError,
      }) async
 {
  customPrint('sdfdsafdsff');
  bool? confirmation = true;
  if (handleConfirmation != null) {
   confirmation = await handleConfirmation();
  }
  if (confirmation != true) {
    return;
  }



  try {
    // var collection = FirebaseCollections.chatsCollection;

    var messages = await chatCollection.doc(chatId).collection('messages').get();
    for (var message in messages.docs) {
      await chatCollection
          .doc(chatId)
          .collection('messages')
          .doc(message.id)
          .delete();
    }
    customPrint('the message length is ${messages.docs.length}');

    await chatCollection.doc(chatId).delete();
    // showSnackbar('the message length is ${messages.docs.length}');
    // showSnackbar('Chat Deleted successfully ');
  } catch (e) {
    if(handleError!=null){
      handleError(e);
    }
    customPrint('Some Error occurred ');
  }
  // deleteLoader.value = false;
}