Merge branch 'develop' into fix/message-search-pagination
This commit is contained in:
@@ -42,10 +42,9 @@ class ChannelDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates all the channels using the new [channelList] data
|
||||
Future<void> updateChannels(List<ChannelModel> channelList) => batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
channels,
|
||||
channelList.map((c) => c.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,13 +45,12 @@ class ChannelQueryDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}
|
||||
|
||||
await batch((it) {
|
||||
it.insertAll(
|
||||
it.insertAllOnConflictUpdate(
|
||||
channelQueries,
|
||||
cids
|
||||
.map((cid) =>
|
||||
ChannelQueryEntity(queryHash: hash, channelCid: cid))
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
/// Update stored connection event with latest data
|
||||
Future<int> updateConnectionEvent(Event event) => transaction(() async {
|
||||
final connectionInfo = await select(connectionEvents).getSingleOrNull();
|
||||
return into(connectionEvents).insert(
|
||||
return into(connectionEvents).insertOnConflictUpdate(
|
||||
ConnectionEventEntity(
|
||||
id: 1,
|
||||
type: event.type,
|
||||
@@ -38,7 +38,6 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
unreadChannels:
|
||||
event.unreadChannels ?? connectionInfo?.unreadChannels,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ export 'connection_event_dao.dart';
|
||||
export 'member_dao.dart';
|
||||
export 'message_dao.dart';
|
||||
export 'pinned_message_dao.dart';
|
||||
export 'pinned_message_reaction_dao.dart';
|
||||
export 'reaction_dao.dart';
|
||||
export 'read_dao.dart';
|
||||
export 'user_dao.dart';
|
||||
|
||||
@@ -30,14 +30,19 @@ class MemberDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
}).get();
|
||||
|
||||
/// Updates all the members using the new [memberList] data
|
||||
Future<void> updateMembers(String cid, List<Member> memberList) async =>
|
||||
batch(
|
||||
(it) => it.insertAll(
|
||||
members,
|
||||
memberList.map((m) => m.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
Future<void> updateMembers(String cid, List<Member> memberList) =>
|
||||
bulkUpdateMembers({cid: memberList});
|
||||
|
||||
/// Bulk updates the members data of multiple channels
|
||||
Future<void> bulkUpdateMembers(Map<String, List<Member>> channelWithMembers) {
|
||||
final entities = channelWithMembers.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(member) => member.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch((batch) => batch.insertAllOnConflictUpdate(members, entities));
|
||||
}
|
||||
|
||||
/// Deletes all the members whose [Members.channelCid] is present in [cids]
|
||||
Future<void> deleteMemberByCids(List<String> cids) async => batch((it) {
|
||||
|
||||
@@ -170,13 +170,21 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the message data of a particular channel with
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
messages,
|
||||
messageList.map((it) => it.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) =>
|
||||
bulkUpdateMessages({cid: messageList});
|
||||
|
||||
/// Bulk updates the message data of multiple channels
|
||||
Future<void> bulkUpdateMessages(
|
||||
Map<String, List<Message>> channelWithMessages,
|
||||
) {
|
||||
final entities = channelWithMessages.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(message) => message.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch(
|
||||
(batch) => batch.insertAllOnConflictUpdate(messages, entities),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,8 +39,10 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
final userEntity = rows.readTableOrNull(users);
|
||||
final pinnedByEntity = rows.readTableOrNull(_pinnedByUsers);
|
||||
final msgEntity = rows.readTable(pinnedMessages);
|
||||
final latestReactions = await _db.reactionDao.getReactions(msgEntity.id);
|
||||
final ownReactions = await _db.reactionDao.getReactionsByUserId(
|
||||
final latestReactions =
|
||||
await _db.pinnedMessageReactionDao.getReactions(msgEntity.id);
|
||||
final ownReactions =
|
||||
await _db.pinnedMessageReactionDao.getReactionsByUserId(
|
||||
msgEntity.id,
|
||||
_db.userId,
|
||||
);
|
||||
@@ -168,13 +170,21 @@ class PinnedMessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the message data of a particular channel with
|
||||
/// the new [messageList] data
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) => batch(
|
||||
(batch) {
|
||||
batch.insertAll(
|
||||
pinnedMessages,
|
||||
messageList.map((it) => it.toPinnedEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
},
|
||||
);
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) =>
|
||||
bulkUpdateMessages({cid: messageList});
|
||||
|
||||
/// Bulk updates the message data of multiple channels
|
||||
Future<void> bulkUpdateMessages(
|
||||
Map<String, List<Message>> channelWithMessages,
|
||||
) {
|
||||
final entities = channelWithMessages.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(message) => message.toPinnedEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch(
|
||||
(batch) => batch.insertAllOnConflictUpdate(pinnedMessages, entities),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:stream_chat_persistence/src/db/moor_chat_database.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/pinned_message_reactions.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/users.dart';
|
||||
import 'package:stream_chat_persistence/src/mapper/mapper.dart';
|
||||
|
||||
part 'pinned_message_reaction_dao.g.dart';
|
||||
|
||||
/// The Data Access Object for operations in [PinnedMessageReactions] table.
|
||||
@UseDao(tables: [PinnedMessageReactions, Users])
|
||||
class PinnedMessageReactionDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
with _$PinnedMessageReactionDaoMixin {
|
||||
/// Creates a new reaction dao instance
|
||||
PinnedMessageReactionDao(MoorChatDatabase db) : super(db);
|
||||
|
||||
/// Returns all the reactions of a particular message by matching
|
||||
/// [Reactions.messageId] with [messageId]
|
||||
Future<List<Reaction>> getReactions(String messageId) =>
|
||||
(select(pinnedMessageReactions).join([
|
||||
leftOuterJoin(users, pinnedMessageReactions.userId.equalsExp(users.id)),
|
||||
])
|
||||
..where(pinnedMessageReactions.messageId.equals(messageId))
|
||||
..orderBy([OrderingTerm.asc(pinnedMessageReactions.createdAt)]))
|
||||
.map((rows) {
|
||||
final userEntity = rows.readTableOrNull(users);
|
||||
final reactionEntity = rows.readTable(pinnedMessageReactions);
|
||||
return reactionEntity.toReaction(user: userEntity?.toUser());
|
||||
}).get();
|
||||
|
||||
/// Returns all the reactions of a particular message
|
||||
/// added by a particular user by matching
|
||||
/// [Reactions.messageId] with [messageId] and
|
||||
/// [Reactions.userId] with [userId]
|
||||
Future<List<Reaction>> getReactionsByUserId(
|
||||
String messageId,
|
||||
String userId,
|
||||
) async {
|
||||
final reactions = await getReactions(messageId);
|
||||
return reactions.where((it) => it.userId == userId).toList();
|
||||
}
|
||||
|
||||
/// Updates the reactions data with the new [reactionList] data
|
||||
Future<void> updateReactions(List<Reaction> reactionList) => batch((it) {
|
||||
it.insertAllOnConflictUpdate(
|
||||
pinnedMessageReactions,
|
||||
reactionList.map((r) => r.toPinnedEntity()).toList(),
|
||||
);
|
||||
});
|
||||
|
||||
/// Deletes all the reactions whose [Reactions.messageId] is
|
||||
/// present in [messageIds]
|
||||
Future<void> deleteReactionsByMessageIds(List<String> messageIds) =>
|
||||
batch((it) {
|
||||
it.deleteWhere<PinnedMessageReactions, PinnedMessageReactionEntity>(
|
||||
pinnedMessageReactions,
|
||||
(r) => r.messageId.isIn(messageIds),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'pinned_message_reaction_dao.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// DaoGenerator
|
||||
// **************************************************************************
|
||||
|
||||
mixin _$PinnedMessageReactionDaoMixin on DatabaseAccessor<MoorChatDatabase> {
|
||||
$PinnedMessageReactionsTable get pinnedMessageReactions =>
|
||||
attachedDatabase.pinnedMessageReactions;
|
||||
$UsersTable get users => attachedDatabase.users;
|
||||
}
|
||||
@@ -42,10 +42,9 @@ class ReactionDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Updates the reactions data with the new [reactionList] data
|
||||
Future<void> updateReactions(List<Reaction> reactionList) => batch((it) {
|
||||
it.insertAll(
|
||||
it.insertAllOnConflictUpdate(
|
||||
reactions,
|
||||
reactionList.map((r) => r.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -29,11 +29,17 @@ class ReadDao extends DatabaseAccessor<MoorChatDatabase> with _$ReadDaoMixin {
|
||||
|
||||
/// Updates the read data of a particular channel with
|
||||
/// the new [readList] data
|
||||
Future<void> updateReads(String cid, List<Read> readList) => batch(
|
||||
(it) => it.insertAll(
|
||||
reads,
|
||||
readList.map((r) => r.toEntity(cid: cid)).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
Future<void> updateReads(String cid, List<Read> readList) =>
|
||||
bulkUpdateReads({cid: readList});
|
||||
|
||||
/// Bulk updates the reads data of multiple channels
|
||||
Future<void> bulkUpdateReads(Map<String, List<Read>> channelWithReads) {
|
||||
final entities = channelWithReads.entries
|
||||
.map((entry) => entry.value.map(
|
||||
(read) => read.toEntity(cid: entry.key),
|
||||
))
|
||||
.expand((it) => it)
|
||||
.toList(growable: false);
|
||||
return batch((batch) => batch.insertAllOnConflictUpdate(reads, entities));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,9 @@ class UserDao extends DatabaseAccessor<MoorChatDatabase> with _$UserDaoMixin {
|
||||
|
||||
/// Updates the users data with the new [userList] data
|
||||
Future<void> updateUsers(List<User> userList) => batch(
|
||||
(it) => it.insertAll(
|
||||
(it) => it.insertAllOnConflictUpdate(
|
||||
users,
|
||||
userList.map((u) => u.toEntity()).toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user