Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/stream_chat_persistence/lib/src/dao/member_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class MemberDao extends DatabaseAccessor<DriftChatDatabase>
};
}

/// Updates all the members using the new [memberList] data
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,
Expand Down
5 changes: 0 additions & 5 deletions packages/stream_chat_persistence/lib/src/dao/message_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ class MessageDao extends DatabaseAccessor<DriftChatDatabase>
return msgList;
}

/// Updates the message data of a particular channel with
/// the new [messageList] data
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PinnedMessageDao extends DatabaseAccessor<DriftChatDatabase>
);
}

/// Returns a single message by matching the [PinnedMessages.id] with [id]
/// Returns a single message by matching the [PinnedMessages.id] with [id].
Future<Message?> getMessageById(
String id, {
bool fetchDraft = true,
Expand All @@ -102,65 +102,6 @@ class PinnedMessageDao extends DatabaseAccessor<DriftChatDatabase>
);
}

/// Returns all the messages of a particular thread by matching
/// [PinnedMessages.channelCid] with [cid]
Future<List<Message>> getThreadMessages(String cid) async =>
Future.wait(await (select(pinnedMessages).join([
leftOuterJoin(_users, pinnedMessages.userId.equalsExp(_users.id)),
leftOuterJoin(
_pinnedByUsers,
pinnedMessages.pinnedByUserId.equalsExp(_pinnedByUsers.id),
),
])
..where(pinnedMessages.channelCid.equals(cid))
..where(pinnedMessages.parentId.isNotNull())
..orderBy([OrderingTerm.asc(pinnedMessages.createdAt)]))
.map(_messageFromJoinRow)
.get());

/// Returns all the messages of a particular thread by matching
/// [PinnedMessages.parentId] with [parentId]
Future<List<Message>> getThreadMessagesByParentId(
String parentId, {
PaginationParams? options,
}) async {
final msgList = await Future.wait(await (select(pinnedMessages).join([
leftOuterJoin(_users, pinnedMessages.userId.equalsExp(_users.id)),
leftOuterJoin(
_pinnedByUsers,
pinnedMessages.pinnedByUserId.equalsExp(_pinnedByUsers.id),
),
])
..where(pinnedMessages.parentId.isNotNull())
..where(pinnedMessages.parentId.equals(parentId))
..orderBy([OrderingTerm.asc(pinnedMessages.createdAt)]))
.map(_messageFromJoinRow)
.get());

if (msgList.isNotEmpty) {
if (options?.lessThan != null) {
final lessThanIndex = msgList.indexWhere(
(m) => m.id == options!.lessThan,
);
if (lessThanIndex != -1) {
msgList.removeRange(lessThanIndex, msgList.length);
}
}
if (options?.greaterThan != null) {
final greaterThanIndex = msgList.indexWhere(
(m) => m.id == options!.greaterThan,
);
if (greaterThanIndex != -1) {
msgList.removeRange(0, greaterThanIndex);
}
}
if (options?.limit != null) {
return msgList.take(options!.limit).toList();
}
}
return msgList;
}

/// Returns all the messages of a channel by matching
/// [PinnedMessages.channelCid] with [parentId]
Future<List<Message>> getMessagesByCid(
Expand Down Expand Up @@ -216,11 +157,6 @@ class PinnedMessageDao extends DatabaseAccessor<DriftChatDatabase>
return msgList;
}

/// Updates the message data of a particular channel with
/// the new [messageList] data
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,
Expand Down
7 changes: 0 additions & 7 deletions packages/stream_chat_persistence/lib/src/dao/poll_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ class PollDao extends DatabaseAccessor<DriftChatDatabase> with _$PollDaoMixin {
),
);

/// Returns the list of all the polls stored in db
Future<List<Poll>> getPolls() async => Future.wait(await (select(polls)
..orderBy([(it) => OrderingTerm.desc(it.createdAt)]))
.join([leftOuterJoin(users, polls.createdById.equalsExp(users.id))])
.map(_pollFromJoinRow)
.get());

/// Deletes all the polls whose [Polls.id] is present in [pollIds]
Future<void> deletePollsByIds(List<String> pollIds) =>
(delete(polls)..where((tbl) => tbl.id.isIn(pollIds))).go();
Expand Down
5 changes: 0 additions & 5 deletions packages/stream_chat_persistence/lib/src/dao/read_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class ReadDao extends DatabaseAccessor<DriftChatDatabase> with _$ReadDaoMixin {
return readEntity.toRead(user: userEntity.toUser());
}).get();

/// Updates the read data of a particular channel with
/// the new [readList] data
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
Expand Down
6 changes: 0 additions & 6 deletions packages/stream_chat_persistence/lib/src/dao/user_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,4 @@ class UserDao extends DatabaseAccessor<DriftChatDatabase> with _$UserDaoMixin {
userList.map((u) => u.toEntity()).toList(),
),
);

/// Returns the list of all the users stored in db
Future<List<User>> getUsers() =>
(select(users)..orderBy([(u) => OrderingTerm.desc(u.createdAt)]))
.map((it) => it.toUser())
.get();
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ void main() {

// Saving a dummy member
final dummyMember = Member(userId: userId, user: dummyUser);
await database.memberDao.updateMembers(cid, [dummyMember]);
await database.memberDao.bulkUpdateMembers({
cid: [dummyMember]
});

// Should match the dummy member
final updatedMembers = await database.memberDao.getMembersByCid(cid);
Expand All @@ -78,7 +80,9 @@ void main() {
// Saving a dummy message
const messageId = 'messageId';
final dummyMessage = Message(id: messageId, user: dummyUser);
await database.messageDao.updateMessages(cid, [dummyMessage]);
await database.messageDao.bulkUpdateMessages({
cid: [dummyMessage]
});

// Should match the dummy message
final updatedMessages = await database.messageDao.getMessagesByCid(cid);
Expand All @@ -91,7 +95,9 @@ void main() {
user: dummyUser,
lastReadMessageId: messageId,
);
await database.readDao.updateReads(cid, [dummyRead]);
await database.readDao.bulkUpdateReads({
cid: [dummyRead]
});

// Should match the dummy read
final updatedReads = await database.readDao.getReadsByCid(cid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void main() {
await database.channelDao.updateChannels(allChannels);

if (withParentMessage || withQuotedMessage) {
await database.messageDao.updateMessages(cid, messages);
await database.messageDao.bulkUpdateMessages({cid: messages});
}

if (withPoll && polls != null) {
Expand Down Expand Up @@ -287,7 +287,9 @@ void main() {

await database.userDao.updateUsers([user]);
await database.channelDao.updateChannels([ChannelModel(cid: cid)]);
await database.messageDao.updateMessages(cid, [parentMessage]);
await database.messageDao.bulkUpdateMessages({
cid: [parentMessage],
});

// Create first thread draft
final firstDraft = Draft(
Expand Down Expand Up @@ -421,7 +423,7 @@ void main() {

await database.userDao.updateUsers([user]);
await database.channelDao.updateChannels([ChannelModel(cid: cid)]);
await database.messageDao.updateMessages(cid, messages);
await database.messageDao.bulkUpdateMessages({cid: messages});

// Create a channel draft (no parent message)
final channelDraft = Draft(
Expand Down
16 changes: 10 additions & 6 deletions packages/stream_chat_persistence/test/src/dao/member_dao_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void main() {
);
await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await memberDao.updateMembers(cid, memberList);
await memberDao.bulkUpdateMembers({cid: memberList});
return memberList;
}

Expand Down Expand Up @@ -112,9 +112,11 @@ void main() {
ChannelModel(cid: cid2),
ChannelModel(cid: cid3),
]);
await memberDao.updateMembers(cid1, [memberFor(targetUser)]);
await memberDao.updateMembers(cid2, [memberFor(targetUser)]);
await memberDao.updateMembers(cid3, [memberFor(otherUser)]);
await memberDao.bulkUpdateMembers({
cid1: [memberFor(targetUser)],
cid2: [memberFor(targetUser)],
cid3: [memberFor(otherUser)],
});

// Should return memberships only for channels where target user
// is a member, keyed by channelCid.
Expand All @@ -130,7 +132,7 @@ void main() {
expect(memberships[cid2]!.user!.id, targetUserId);
});

test('updateMembers', () async {
test('bulkUpdateMembers', () async {
const cid = 'test:Cid';

// Preparing test data
Expand Down Expand Up @@ -174,7 +176,9 @@ void main() {
updatedAt: DateTime.now(),
);
await database.userDao.updateUsers([newUser]);
await memberDao.updateMembers(cid, [copyMember, newMember]);
await memberDao.bulkUpdateMembers({
cid: [copyMember, newMember],
});

// Fetched member length should be one more than inserted members.
// copyMember `banned` modified field should be true.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void main() {
);
await database.userDao.updateUsers(users);
await database.channelDao.updateChannels(channels);
await messageDao.updateMessages(cid, allMessages);
await messageDao.bulkUpdateMessages({cid: allMessages});
await database.reactionDao.updateReactions([reaction]);
return allMessages;
}
Expand Down Expand Up @@ -393,7 +393,7 @@ void main() {
expect(fetchedMessages.first.id != lessThan, true);
});

test('updateMessages', () async {
test('bulkUpdateMessages', () async {
const cid = 'test:Cid';

// Preparing test data
Expand All @@ -418,7 +418,9 @@ void main() {
pinnedBy: User(id: 'testUserId4'),
);

await messageDao.updateMessages(cid, [copyMessage, newMessage]);
await messageDao.bulkUpdateMessages({
cid: [copyMessage, newMessage],
});

// Fetched messages length should be one more than inserted message.
// copyMessage `showInChannel` modified field should be false.
Expand Down
Loading
Loading