diff --git a/packages/stream_chat_persistence/lib/src/db/shared/native_db.dart b/packages/stream_chat_persistence/lib/src/db/shared/native_db.dart index 90f19de6..74cf91f8 100644 --- a/packages/stream_chat_persistence/lib/src/db/shared/native_db.dart +++ b/packages/stream_chat_persistence/lib/src/db/shared/native_db.dart @@ -1,5 +1,3 @@ -//ignore_for_file: public_member_api_docs - import 'dart:io'; import 'dart:isolate'; import 'package:moor/ffi.dart'; @@ -7,10 +5,18 @@ import 'package:moor/isolate.dart'; import 'package:moor/moor.dart'; import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:stream_chat_persistence/src/stream_chat_persistence_client.dart'; +import 'package:stream_chat_persistence/stream_chat_persistence.dart'; import '../moor_chat_database.dart'; +/// A Helper class to construct new instances of [MoorChatDatabase] specifically +/// for native platform applications class SharedDB { + /// Returns a new instance of [VmDatabase] created using [userId] + /// on a regular isolate. + /// + /// Generally used with [ConnectionMode.regular]. static Future constructDatabase( String userId, { bool logStatements = false, @@ -62,7 +68,11 @@ class SharedDB { return (await receivePort.first as MoorIsolate); } - static Future constructOfflineStorage( + /// Returns a new instance of [MoorChatDatabase] using the factory constructor + /// [MoorChatDatabase.connect] created on a background isolate. + /// + /// Generally used with [ConnectionMode.background]. + static Future constructMoorChatDatabase( String userId, { bool logStatements = false, }) async { diff --git a/packages/stream_chat_persistence/lib/src/db/shared/unsupported_db.dart b/packages/stream_chat_persistence/lib/src/db/shared/unsupported_db.dart index b014c833..303d925f 100644 --- a/packages/stream_chat_persistence/lib/src/db/shared/unsupported_db.dart +++ b/packages/stream_chat_persistence/lib/src/db/shared/unsupported_db.dart @@ -1,15 +1,21 @@ -//ignore_for_file: public_member_api_docs -//ignore_for_file: always_declare_return_types +import 'package:stream_chat_persistence/stream_chat_persistence.dart'; +/// A Helper class to construct new instances of [MoorChatDatabase] class SharedDB { - static constructDatabase( + /// Returns a new instance of database. + /// + /// Generally used with [ConnectionMode.regular]. + static dynamic constructDatabase( String userId, { bool logStatements = false, }) { throw 'Unsupported Platform'; } - static constructOfflineStorage( + /// Return a new instance of moor chat database. + /// + /// Generally used with [ConnectionMode.background]. + static dynamic constructMoorChatDatabase( String userId, { bool logStatements = false, }) { diff --git a/packages/stream_chat_persistence/lib/src/db/shared/web_db.dart b/packages/stream_chat_persistence/lib/src/db/shared/web_db.dart index e30d08ea..6f4360c0 100644 --- a/packages/stream_chat_persistence/lib/src/db/shared/web_db.dart +++ b/packages/stream_chat_persistence/lib/src/db/shared/web_db.dart @@ -1,11 +1,15 @@ -//ignore_for_file: public_member_api_docs -//ignore_for_file: always_declare_return_types import 'package:moor/moor_web.dart'; +import 'package:stream_chat_persistence/src/stream_chat_persistence_client.dart'; import '../moor_chat_database.dart'; +/// A Helper class to construct new instances of [MoorChatDatabase] specifically +/// for Web applications class SharedDB { - static constructDatabase( + /// Returns a new instance of [WebDatabase] created using [userId]. + /// + /// Generally used with [ConnectionMode.regular]. + static Future constructDatabase( String userId, { bool logStatements = false, }) async { @@ -13,7 +17,11 @@ class SharedDB { return WebDatabase(dbName, logStatements: logStatements); } - static Future constructOfflineStorage( + /// Returns a new instance of [MoorChatDatabase] creating using the + /// default constructor. + /// + /// Generally used with [ConnectionMode.background]. + static Future constructMoorChatDatabase( String userId, { bool logStatements = false, }) async { diff --git a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart index ebad74f8..0962c9ac 100644 --- a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart +++ b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart @@ -43,7 +43,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { return; case ConnectionMode.background: _logger.info('Connecting on background isolate'); - _db = await SharedDB.constructOfflineStorage(userId); + _db = await SharedDB.constructMoorChatDatabase(userId); return; } } diff --git a/packages/stream_chat_persistence/pubspec.yaml b/packages/stream_chat_persistence/pubspec.yaml index b8e49170..0702431b 100644 --- a/packages/stream_chat_persistence/pubspec.yaml +++ b/packages/stream_chat_persistence/pubspec.yaml @@ -20,3 +20,4 @@ dev_dependencies: test: ^1.15.7 build_runner: ^1.11.0 moor_generator: ^3.4.1 + pedantic: ^1.9.2