Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions packages/stream_chat_persistence/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming changes

🔄 Internal / Non-breaking

- Removed unused / test-only methods from internal DAO classes.

## 9.25.0

🚀 Performance
Expand Down
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 @@ -334,11 +334,6 @@ class MessageDao extends DatabaseAccessor<DriftChatDatabase>
return _messagesFromJoinRows(orderedRows, fetchDraft: fetchDraft);
}

/// 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 @@ -174,68 +174,6 @@ class PinnedMessageDao extends DatabaseAccessor<DriftChatDatabase>
return hydrated.firstOrNull;
}

/// Returns all the messages of a particular thread by matching
/// [PinnedMessages.channelCid] with [cid]
Future<List<Message>> getThreadMessages(String cid) async {
final rows = 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)]))
.get();
return _messagesFromJoinRows(rows);
}

/// Returns all the messages of a particular thread by matching
/// [PinnedMessages.parentId] with [parentId]
Future<List<Message>> getThreadMessagesByParentId(
String parentId, {
PaginationParams? options,
}) async {
final rows = 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)]))
.get();
final msgList = await _messagesFromJoinRows(rows);

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

/// Returns all the messages of a channel by matching
/// [PinnedMessages.channelCid] with [parentId]
Future<List<Message>> getMessagesByCid(
Expand Down Expand Up @@ -284,11 +222,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
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ class PinnedMessageReactionDao extends DatabaseAccessor<DriftChatDatabase>
/// Creates a new reaction dao instance
PinnedMessageReactionDao(super.db);

/// Returns all the reactions of a particular message by matching
/// [Reactions.messageId] with [messageId].
///
/// Not used in production — `PinnedMessageDao` hydrates via the batched
/// [getReactionsForMessages]. Kept for convenience (tests + ad-hoc
/// single-id lookups).
Future<List<Reaction>> getReactions(String messageId) {
final where = pinnedMessageReactions.messageId.equals(messageId);
return _selectReactions(where);
}

/// Returns all the reactions of a particular message
/// added by a particular user by matching
/// [Reactions.messageId] with [messageId] and
/// [Reactions.userId] with [userId].
///
/// Not used in production — `PinnedMessageDao` hydrates via the batched
/// [getReactionsForMessagesByUserId]. Kept for convenience.
Future<List<Reaction>> getReactionsByUserId(
String messageId,
String userId,
) {
final where = pinnedMessageReactions.messageId.equals(messageId) &
pinnedMessageReactions.userId.equals(userId);
return _selectReactions(where);
}

/// Returns pinned-message reactions for every id in [messageIds], grouped
/// by message id.
Future<Map<String, List<Reaction>>> getReactionsForMessages(
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 @@ -86,13 +86,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
27 changes: 0 additions & 27 deletions packages/stream_chat_persistence/lib/src/dao/reaction_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,6 @@ class ReactionDao extends DatabaseAccessor<DriftChatDatabase>
/// Creates a new reaction dao instance
ReactionDao(super.db);

/// Returns all the reactions of a particular message by matching
/// [Reactions.messageId] with [messageId].
///
/// Not used in production — `MessageDao` hydrates via the batched
/// [getReactionsForMessages]. Kept for convenience (tests + ad-hoc
/// single-id lookups).
Future<List<Reaction>> getReactions(String messageId) {
final where = reactions.messageId.equals(messageId);
return _selectReactions(where);
}

/// Returns all the reactions of a particular message
/// added by a particular user by matching
/// [Reactions.messageId] with [messageId] and
/// [Reactions.userId] with [userId].
///
/// Not used in production — `MessageDao` hydrates via the batched
/// [getReactionsForMessagesByUserId]. Kept for convenience.
Future<List<Reaction>> getReactionsByUserId(
String messageId,
String userId,
) {
final where =
reactions.messageId.equals(messageId) & reactions.userId.equals(userId);
return _selectReactions(where);
}

/// Returns reactions for every id in [messageIds], grouped by message id.
Future<Map<String, List<Reaction>>> getReactionsForMessages(
List<String> messageIds,
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 All @@ -104,8 +110,8 @@ void main() {
await database.reactionDao.updateReactions([dummyReaction]);

// Should match the dummy reaction
final updatedReactions =
await database.reactionDao.getReactionsByUserId(messageId, userId);
final updatedReactions = (await database.reactionDao
.getReactionsForMessagesByUserId([messageId], userId))[messageId]!;
expect(updatedReactions.length, 1);
expect(updatedReactions.first.messageId, messageId);

Expand All @@ -129,8 +135,8 @@ void main() {
expect(reads, isEmpty);

// Fetched readtions for passed message id and user id should be empty
final reactions =
await database.reactionDao.getReactionsByUserId(messageId, userId);
final reactions = (await database.reactionDao
.getReactionsForMessagesByUserId([messageId], userId))[messageId]!;
expect(reactions, isEmpty);
});

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 @@ -394,7 +396,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]
});

await draftMessageDao.updateDraftMessages([
Draft(
Expand Down Expand Up @@ -465,7 +469,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 Expand Up @@ -574,28 +578,32 @@ void main() {
ChannelModel(cid: cidA),
ChannelModel(cid: cidB),
]);
await database.messageDao.updateMessages(cidA, [
Message(
id: parentWithDraft,
user: user,
createdAt: DateTime.now(),
text: 'A',
),
Message(
id: parentWithoutDraft,
user: user,
createdAt: DateTime.now(),
text: 'B',
),
]);
await database.messageDao.updateMessages(cidB, [
Message(
id: parentInOtherChannel,
user: user,
createdAt: DateTime.now(),
text: 'C',
),
]);
await database.messageDao.bulkUpdateMessages({
cidA: [
Message(
id: parentWithDraft,
user: user,
createdAt: DateTime.now(),
text: 'A',
),
Message(
id: parentWithoutDraft,
user: user,
createdAt: DateTime.now(),
text: 'B',
),
]
});
await database.messageDao.bulkUpdateMessages({
cidB: [
Message(
id: parentInOtherChannel,
user: user,
createdAt: DateTime.now(),
text: 'C',
),
]
});
// One draft in cidA on parentWithDraft, and one draft in cidB to
// confirm the cid filter excludes it from the cidA lookup.
await draftMessageDao.updateDraftMessages([
Expand Down
Loading
Loading