[StreamChatPersistence] Fix ownReactions userId bug
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -456,7 +456,7 @@ class Client {
|
||||
wsConnectionStatus.value = ConnectionStatus.connecting;
|
||||
|
||||
if (persistenceEnabled) {
|
||||
await chatPersistenceClient.connect('db_${state.user.id}');
|
||||
await chatPersistenceClient.connect(state.user.id);
|
||||
}
|
||||
|
||||
_ws = WebSocket(
|
||||
|
||||
@@ -11,7 +11,7 @@ import 'package:stream_chat/src/models/user.dart';
|
||||
///
|
||||
abstract class ChatPersistenceClient {
|
||||
/// Creates a new connection to the client
|
||||
Future<void> connect(String name);
|
||||
Future<void> connect(String userId);
|
||||
|
||||
/// Closes the client connection
|
||||
/// If [flush] is true, the data will also be deleted
|
||||
|
||||
@@ -36,9 +36,9 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
final userEntity = rows.readTable(users);
|
||||
final msgEntity = rows.readTable(messages);
|
||||
final latestReactions = await _db.reactionDao.getReactions(msgEntity.id);
|
||||
final ownReactions = await _db.reactionDao.getOwnReactions(
|
||||
final ownReactions = await _db.reactionDao.getReactionsByUserId(
|
||||
msgEntity.id,
|
||||
userEntity.id,
|
||||
_db.userId,
|
||||
);
|
||||
Message quotedMessage;
|
||||
if (msgEntity.quotedMessageId != null) {
|
||||
|
||||
@@ -29,7 +29,7 @@ class ReactionDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
///
|
||||
Future<List<Reaction>> getOwnReactions(
|
||||
Future<List<Reaction>> getReactionsByUserId(
|
||||
String messageId,
|
||||
String userId,
|
||||
) async {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> connect(String name) async {
|
||||
Future<void> connect(String userId) async {
|
||||
if (_db != null) {
|
||||
throw Exception(
|
||||
'An instance of StreamChatDatabase is already connected.\n'
|
||||
@@ -52,11 +52,11 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
switch (_connectionMode) {
|
||||
case ConnectionMode.regular:
|
||||
_logger.info('Connecting on a regular isolate');
|
||||
_db = MoorChatDatabase(name);
|
||||
_db = MoorChatDatabase(userId);
|
||||
return;
|
||||
case ConnectionMode.background:
|
||||
_logger.info('Connecting on background isolate');
|
||||
_db = await SharedDB.constructOfflineStorage(name);
|
||||
_db = await SharedDB.constructOfflineStorage(userId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user