LCOV - code coverage report
Current view: top level - lib\data\local\local_storage.dart - local_storage.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 29 29 100.0 %
Date: Tue Jul 13 13:39:38 2021 Functions: 0 0 -

          Line data    Source code
       1             : 
       2             : 
       3             : import 'package:chatwoot_client_sdk/data/local/dao/chatwoot_contact_dao.dart';
       4             : import 'package:chatwoot_client_sdk/data/local/dao/chatwoot_conversation_dao.dart';
       5             : import 'package:chatwoot_client_sdk/data/local/dao/chatwoot_messages_dao.dart';
       6             : import 'package:chatwoot_client_sdk/data/local/dao/chatwoot_user_dao.dart';
       7             : import 'package:chatwoot_client_sdk/data/local/entity/chatwoot_conversation.dart';
       8             : import 'package:chatwoot_client_sdk/data/remote/responses/chatwoot_event.dart';
       9             : import 'package:hive_flutter/hive_flutter.dart';
      10             : 
      11             : import 'entity/chatwoot_contact.dart';
      12             : import 'entity/chatwoot_conversation.dart';
      13             : import 'entity/chatwoot_message.dart';
      14             : import 'entity/chatwoot_user.dart';
      15             : 
      16             : class LocalStorage{
      17             :   ChatwootUserDao userDao;
      18             :   ChatwootConversationDao conversationDao;
      19             :   ChatwootContactDao contactDao;
      20             :   ChatwootMessagesDao messagesDao;
      21             : 
      22           2 :   LocalStorage({
      23             :     required this.userDao,
      24             :     required this.conversationDao,
      25             :     required this.contactDao,
      26             :     required this.messagesDao,
      27             :   });
      28             : 
      29           2 :   static Future<void> openDB({void Function()? onInitializeHive}) async{
      30             : 
      31             :     if(onInitializeHive == null){
      32           3 :       await Hive.initFlutter();
      33           1 :       Hive
      34           2 :         ..registerAdapter(ChatwootContactAdapter())
      35           2 :         ..registerAdapter(ChatwootConversationAdapter())
      36           2 :         ..registerAdapter(ChatwootMessageAdapter())
      37           2 :         ..registerAdapter(ChatwootEventMessageUserAdapter())
      38           2 :         ..registerAdapter(ChatwootUserAdapter());
      39             :     }else{
      40           1 :       onInitializeHive();
      41             :     }
      42             : 
      43           4 :     await PersistedChatwootContactDao.openDB();
      44           4 :     await PersistedChatwootConversationDao.openDB();
      45           4 :     await PersistedChatwootMessagesDao.openDB();
      46           2 :     await PersistedChatwootUserDao.openDB();
      47             :   }
      48             : 
      49           1 :   Future<void> clear({bool clearChatwootUserStorage = true}) async{
      50           3 :     await conversationDao.deleteConversation();
      51           3 :     await contactDao.deleteContact();
      52           3 :     await messagesDao.clear();
      53             :     if(clearChatwootUserStorage){
      54           3 :       await userDao.deleteUser();
      55             :     }
      56             :   }
      57             : 
      58           1 :   Future<void> clearAll() async{
      59           3 :     await conversationDao.clearAll();
      60           3 :     await contactDao.clearAll();
      61           3 :     await messagesDao.clearAll();
      62           3 :     await userDao.clearAll();
      63             :   }
      64             : 
      65           1 :   dispose(){
      66           2 :     userDao.onDispose();
      67           2 :     conversationDao.onDispose();
      68           2 :     contactDao.onDispose();
      69           2 :     messagesDao.onDispose();
      70             :   }
      71             : }

Generated by: LCOV version 1.15.alpha0w