[StreamChatPersistence] Fix connectionEventEntity, MessageDao
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -16,12 +16,8 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
|
||||
/// Get the latest stored connection event
|
||||
Future<Event> get connectionEvent {
|
||||
return select(connectionEvents).join([
|
||||
leftOuterJoin(users, connectionEvents.ownUserId.equalsExp(users.id)),
|
||||
]).map((rows) {
|
||||
final event = rows.readTable(connectionEvents);
|
||||
final user = rows.readTable(users);
|
||||
return event.toEvent(user: user?.toUser());
|
||||
return select(connectionEvents).map((eventEntity) {
|
||||
return eventEntity.toEvent();
|
||||
}).getSingle();
|
||||
}
|
||||
|
||||
@@ -40,7 +36,7 @@ class ConnectionEventDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
lastEventAt: event.createdAt ?? connectionInfo?.lastEventAt,
|
||||
totalUnreadCount:
|
||||
event.totalUnreadCount ?? connectionInfo?.totalUnreadCount,
|
||||
ownUserId: event.me?.id ?? connectionInfo?.ownUserId,
|
||||
ownUser: event.me?.toJson() ?? connectionInfo?.ownUser,
|
||||
unreadChannels: event.unreadChannels ?? connectionInfo?.unreadChannels,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
|
||||
@@ -97,9 +97,7 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
///
|
||||
Future<List<Message>> getMessagesByCid(
|
||||
String cid, {
|
||||
int limit = 20,
|
||||
String messageLessThan,
|
||||
String messageGreaterThan,
|
||||
PaginationParams messagePagination,
|
||||
}) async {
|
||||
final msgList = await Future.wait(await (select(messages).join([
|
||||
leftOuterJoin(users, messages.userId.equalsExp(users.id)),
|
||||
@@ -111,27 +109,30 @@ class MessageDao extends DatabaseAccessor<MoorChatDatabase>
|
||||
.map(_messageFromJoinRow)
|
||||
.get());
|
||||
|
||||
if (messageLessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere((m) => m.id == messageLessThan);
|
||||
if (messagePagination.lessThan != null) {
|
||||
final lessThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.lessThan,
|
||||
);
|
||||
if (lessThanIndex != -1) {
|
||||
msgList.removeRange(lessThanIndex, msgList.length);
|
||||
}
|
||||
}
|
||||
if (messageGreaterThan != null) {
|
||||
final greaterThanIndex =
|
||||
msgList.indexWhere((m) => m.id == messageGreaterThan);
|
||||
if (messagePagination.greaterThanOrEqual != null) {
|
||||
final greaterThanIndex = msgList.indexWhere(
|
||||
(m) => m.id == messagePagination.greaterThanOrEqual,
|
||||
);
|
||||
if (greaterThanIndex != -1) {
|
||||
msgList.removeRange(0, greaterThanIndex);
|
||||
}
|
||||
}
|
||||
if (limit != null) {
|
||||
return msgList.take(limit).toList();
|
||||
if (messagePagination.limit != null) {
|
||||
return msgList.take(messagePagination.limit).toList();
|
||||
}
|
||||
return msgList;
|
||||
}
|
||||
|
||||
///
|
||||
Future<int> updateMessages(String cid, List<Message> messageList) {
|
||||
Future<void> updateMessages(String cid, List<Message> messageList) {
|
||||
return batch((batch) {
|
||||
batch.insertAll(
|
||||
messages,
|
||||
|
||||
Reference in New Issue
Block a user