[StreamChatPersistence] Fix ownReactions userId bug

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-01-27 15:51:55 +05:30
parent e74a0d40ff
commit 3b9af05214
9 changed files with 29 additions and 19 deletions
@@ -10,12 +10,12 @@ import 'shared/shared_db.dart';
part 'moor_chat_database.g.dart';
LazyDatabase _openConnection(
String dbName, {
String userId, {
logStatements = false,
}) {
return LazyDatabase(() async {
return await SharedDB.constructDatabase(
dbName,
userId,
logStatements: logStatements,
);
});
@@ -44,19 +44,25 @@ LazyDatabase _openConnection(
class MoorChatDatabase extends _$MoorChatDatabase {
/// Instantiate a new database instance
MoorChatDatabase(
String dbName, {
this._userId, {
logStatements = false,
}) : super(_openConnection(
dbName,
_userId,
logStatements: logStatements,
));
/// Instantiate a new database instance
MoorChatDatabase.connect(
this._userId,
this._isolate,
DatabaseConnection connection,
) : super.connect(connection);
final String _userId;
/// User id to which the database is connected
String get userId => _userId;
MoorIsolate _isolate;
// you should bump this number whenever you change or add a table definition.
@@ -12,9 +12,10 @@ import '../moor_chat_database.dart';
class SharedDB {
static Future<VmDatabase> constructDatabase(
String dbName, {
String userId, {
bool logStatements = false,
}) async {
final dbName = 'db_$userId';
if (Platform.isIOS || Platform.isAndroid) {
final dir = await getApplicationDocumentsDirectory();
final path = join(dir.path, '$dbName.sqlite');
@@ -62,15 +63,16 @@ class SharedDB {
}
static Future<MoorChatDatabase> constructOfflineStorage(
String dbName, {
String userId, {
bool logStatements = false,
}) async {
final dbName = 'db_$userId';
final isolate = await _createMoorIsolate(
dbName,
logStatements: logStatements,
);
final connection = await isolate.connect();
return MoorChatDatabase.connect(isolate, connection);
return MoorChatDatabase.connect(userId, isolate, connection);
}
}
@@ -3,14 +3,14 @@
class SharedDB {
static constructDatabase(
String dbName, {
String userId, {
bool logStatements = false,
}) {
throw 'Unsupported Platform';
}
static constructOfflineStorage(
String dbName, {
String userId, {
bool logStatements = false,
}) {
throw 'Unsupported Platform';
@@ -6,16 +6,18 @@ import '../moor_chat_database.dart';
class SharedDB {
static constructDatabase(
String dbName, {
String userId, {
bool logStatements = false,
}) async {
final dbName = 'db_$userId';
return WebDatabase(dbName, logStatements: logStatements);
}
static Future<MoorChatDatabase> constructOfflineStorage(
String dbName, {
String userId, {
bool logStatements = false,
}) async {
final dbName = 'db_$userId';
return MoorChatDatabase(dbName, logStatements: logStatements);
}
}