From fa7ae0fe3d03e982ca961e6f3939e5ddefd5b794 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Mon, 30 Dec 2024 11:10:24 +0100 Subject: [PATCH] feat(persistence): add support for polls and poll votes (#2060) Co-authored-by: Deven Joshi Co-authored-by: xsahil03x --- .github/actions/pana/action.yml | 10 +- ...e__temporarily_override_dep_to_local.patch | 79 - melos.yaml | 2 +- .../stream_chat/lib/src/core/models/poll.dart | 2 + .../lib/src/core/models/poll_vote.dart | 22 + .../lib/src/db/chat_persistence_client.dart | 126 +- .../src/db/chat_persistence_client_test.dart | 24 + packages/stream_chat_persistence/CHANGELOG.md | 7 +- .../lib/src/converter/converter.dart | 1 + .../voting_visibility_converter.dart | 33 + .../lib/src/dao/dao.dart | 2 + .../lib/src/dao/message_dao.dart | 6 + .../lib/src/dao/pinned_message_dao.dart | 6 + .../lib/src/dao/poll_dao.dart | 72 + .../lib/src/dao/poll_dao.g.dart | 10 + .../lib/src/dao/poll_vote_dao.dart | 45 + .../lib/src/dao/poll_vote_dao.g.dart | 10 + .../lib/src/db/drift_chat_database.dart | 7 +- .../lib/src/db/drift_chat_database.g.dart | 7763 +++++++++++------ .../lib/src/entity/entity.dart | 2 + .../lib/src/entity/messages.dart | 3 + .../lib/src/entity/poll_votes.dart | 38 + .../lib/src/entity/polls.dart | 75 + .../lib/src/mapper/message_mapper.dart | 4 + .../lib/src/mapper/pinned_message_mapper.dart | 4 + .../lib/src/mapper/poll_mapper.dart | 66 + .../lib/src/mapper/poll_vote_mapper.dart | 34 + .../src/stream_chat_persistence_client.dart | 28 + packages/stream_chat_persistence/pubspec.yaml | 2 +- .../test/mock_chat_database.dart | 42 +- .../voting_visibility_converter_test.dart | 26 + .../test/src/dao/poll_dao_test.dart | 170 + .../test/src/dao/poll_vote_dao_test.dart | 177 + .../test/src/dao/reaction_dao_test.dart | 2 +- .../test/src/mapper/message_mapper_test.dart | 25 + .../mapper/pinned_message_mapper_test.dart | 25 + .../test/src/mapper/poll_mapper_test.dart | 193 + .../src/mapper/poll_vote_mapper_test.dart | 52 + .../stream_chat_persistence_client_test.dart | 42 + 39 files changed, 6268 insertions(+), 2969 deletions(-) delete mode 100644 .github/actions/pana/chore__temporarily_override_dep_to_local.patch create mode 100644 packages/stream_chat_persistence/lib/src/converter/voting_visibility_converter.dart create mode 100644 packages/stream_chat_persistence/lib/src/dao/poll_dao.dart create mode 100644 packages/stream_chat_persistence/lib/src/dao/poll_dao.g.dart create mode 100644 packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.dart create mode 100644 packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.g.dart create mode 100644 packages/stream_chat_persistence/lib/src/entity/poll_votes.dart create mode 100644 packages/stream_chat_persistence/lib/src/entity/polls.dart create mode 100644 packages/stream_chat_persistence/lib/src/mapper/poll_mapper.dart create mode 100644 packages/stream_chat_persistence/lib/src/mapper/poll_vote_mapper.dart create mode 100644 packages/stream_chat_persistence/test/src/converter/voting_visibility_converter_test.dart create mode 100644 packages/stream_chat_persistence/test/src/dao/poll_dao_test.dart create mode 100644 packages/stream_chat_persistence/test/src/dao/poll_vote_dao_test.dart create mode 100644 packages/stream_chat_persistence/test/src/mapper/poll_mapper_test.dart create mode 100644 packages/stream_chat_persistence/test/src/mapper/poll_vote_mapper_test.dart diff --git a/.github/actions/pana/action.yml b/.github/actions/pana/action.yml index c8a90f601..90c26868f 100644 --- a/.github/actions/pana/action.yml +++ b/.github/actions/pana/action.yml @@ -21,9 +21,13 @@ runs: using: "composite" steps: - name: Temporary Override Local Dependencies - shell: bash - run: | - git apply .github/actions/pana/chore__temporarily_override_dep_to_local.patch + uses: mikefarah/yq@master + with: + cmd: | + yq eval '.dependencies.stream_chat_flutter = {"path": "../stream_chat_flutter"}' -i packages/stream_chat_localizations/pubspec.yaml + yq eval '.dependencies.stream_chat = {"path": "../stream_chat"}' -i packages/stream_chat_flutter_core/pubspec.yaml + yq eval '.dependencies.stream_chat_flutter_core = {"path": "../stream_chat_flutter_core"}' -i packages/stream_chat_flutter/pubspec.yaml + yq eval '.dependencies.stream_chat = {"path": "../stream_chat"}' -i packages/stream_chat_persistence/pubspec.yaml - name: Install Flutter uses: subosito/flutter-action@v2 diff --git a/.github/actions/pana/chore__temporarily_override_dep_to_local.patch b/.github/actions/pana/chore__temporarily_override_dep_to_local.patch deleted file mode 100644 index 143592511..000000000 --- a/.github/actions/pana/chore__temporarily_override_dep_to_local.patch +++ /dev/null @@ -1,79 +0,0 @@ -Subject: [PATCH] chore: temporarily override dep to local ---- -Index: packages/stream_chat_localizations/pubspec.yaml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/packages/stream_chat_localizations/pubspec.yaml b/packages/stream_chat_localizations/pubspec.yaml ---- a/packages/stream_chat_localizations/pubspec.yaml (revision 5d78c24f7d7411e55fc6d1adfbe193b743abcbba) -+++ b/packages/stream_chat_localizations/pubspec.yaml (date 1734716942871) -@@ -26,7 +26,8 @@ - sdk: flutter - flutter_localizations: - sdk: flutter -- stream_chat_flutter: ^8.3.0 -+ stream_chat_flutter: -+ path: ../stream_chat_flutter - - dev_dependencies: - flutter_test: -Index: packages/stream_chat_flutter_core/pubspec.yaml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/packages/stream_chat_flutter_core/pubspec.yaml b/packages/stream_chat_flutter_core/pubspec.yaml ---- a/packages/stream_chat_flutter_core/pubspec.yaml (revision 5d78c24f7d7411e55fc6d1adfbe193b743abcbba) -+++ b/packages/stream_chat_flutter_core/pubspec.yaml (date 1734716650052) -@@ -29,7 +29,8 @@ - freezed_annotation: ^2.4.1 - meta: ^1.9.1 - rxdart: ^0.28.0 -- stream_chat: ^8.3.0 -+ stream_chat: -+ path: ../stream_chat - - dev_dependencies: - build_runner: ^2.4.9 -@@ -38,4 +39,3 @@ - sdk: flutter - freezed: ^2.4.2 - mocktail: ^1.0.0 -- -Index: packages/stream_chat_flutter/pubspec.yaml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/packages/stream_chat_flutter/pubspec.yaml b/packages/stream_chat_flutter/pubspec.yaml ---- a/packages/stream_chat_flutter/pubspec.yaml (revision 5d78c24f7d7411e55fc6d1adfbe193b743abcbba) -+++ b/packages/stream_chat_flutter/pubspec.yaml (date 1734716942864) -@@ -54,7 +54,8 @@ - rxdart: ^0.28.0 - share_plus: ^10.0.2 - shimmer: ^3.0.0 -- stream_chat_flutter_core: ^8.3.0 -+ stream_chat_flutter_core: -+ path: ../stream_chat_flutter_core - synchronized: ^3.1.0+1 - thumblr: ^0.0.4 - url_launcher: ^6.3.0 -Index: packages/stream_chat_persistence/pubspec.yaml -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/packages/stream_chat_persistence/pubspec.yaml b/packages/stream_chat_persistence/pubspec.yaml ---- a/packages/stream_chat_persistence/pubspec.yaml (revision 5d78c24f7d7411e55fc6d1adfbe193b743abcbba) -+++ b/packages/stream_chat_persistence/pubspec.yaml (date 1734717094786) -@@ -30,7 +30,8 @@ - path: ^1.8.3 - path_provider: ^2.1.3 - sqlite3_flutter_libs: ^0.5.24 -- stream_chat: ^8.3.0 -+ stream_chat: -+ path: ../stream_chat - - dev_dependencies: - build_runner: ^2.4.9 diff --git a/melos.yaml b/melos.yaml index e9d16483c..f3d3eb706 100644 --- a/melos.yaml +++ b/melos.yaml @@ -61,7 +61,7 @@ command: rxdart: ^0.28.0 share_plus: ^10.0.2 shimmer: ^3.0.0 - sqlite3_flutter_libs: ^0.5.24 + sqlite3_flutter_libs: ^0.5.26 stream_chat: ^8.3.0 stream_chat_flutter: ^8.3.0 stream_chat_flutter_core: ^8.3.0 diff --git a/packages/stream_chat/lib/src/core/models/poll.dart b/packages/stream_chat/lib/src/core/models/poll.dart index aaea50233..4b9ed91a0 100644 --- a/packages/stream_chat/lib/src/core/models/poll.dart +++ b/packages/stream_chat/lib/src/core/models/poll.dart @@ -20,9 +20,11 @@ const _nullConst = _NullConst(); /// {@endtemplate} enum VotingVisibility { /// The voting process is anonymous. + @JsonValue('anonymous') anonymous, /// The voting process is public. + @JsonValue('public') public, } diff --git a/packages/stream_chat/lib/src/core/models/poll_vote.dart b/packages/stream_chat/lib/src/core/models/poll_vote.dart index 03f556a69..c7a2bb40b 100644 --- a/packages/stream_chat/lib/src/core/models/poll_vote.dart +++ b/packages/stream_chat/lib/src/core/models/poll_vote.dart @@ -70,6 +70,28 @@ class PollVote extends Equatable { /// Serialize to json Map toJson() => _$PollVoteToJson(this); + /// Creates a copy of [PollVote] with specified attributes overridden. + PollVote copyWith({ + String? id, + String? pollId, + String? optionId, + String? answerText, + DateTime? createdAt, + DateTime? updatedAt, + String? userId, + User? user, + }) => + PollVote( + id: id ?? this.id, + pollId: pollId ?? this.pollId, + optionId: optionId ?? this.optionId, + answerText: answerText ?? this.answerText, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, + userId: userId ?? this.userId, + user: user ?? this.user, + ); + @override List get props => [ id, diff --git a/packages/stream_chat/lib/src/db/chat_persistence_client.dart b/packages/stream_chat/lib/src/db/chat_persistence_client.dart index 1199eefab..0da0225f3 100644 --- a/packages/stream_chat/lib/src/db/chat_persistence_client.dart +++ b/packages/stream_chat/lib/src/db/chat_persistence_client.dart @@ -6,6 +6,8 @@ import 'package:stream_chat/src/core/models/event.dart'; import 'package:stream_chat/src/core/models/filter.dart'; import 'package:stream_chat/src/core/models/member.dart'; import 'package:stream_chat/src/core/models/message.dart'; +import 'package:stream_chat/src/core/models/poll.dart'; +import 'package:stream_chat/src/core/models/poll_vote.dart'; import 'package:stream_chat/src/core/models/reaction.dart'; import 'package:stream_chat/src/core/models/read.dart'; import 'package:stream_chat/src/core/models/user.dart'; @@ -169,6 +171,12 @@ abstract class ChatPersistenceClient { /// Updates all the channels using the new [channels] data. Future updateChannels(List channels); + /// Updates all the polls using the new [polls] data. + Future updatePolls(List polls); + + /// Deletes all the polls by [pollIds]. + Future deletePollsByIds(List pollIds); + /// Updates all the members of a particular channle [cid] /// with the new [members] data Future updateMembers(String cid, List members) => @@ -194,12 +202,18 @@ abstract class ChatPersistenceClient { /// Updates the pinned message reactions data with the new [reactions] data Future updatePinnedMessageReactions(List reactions); + /// Updates the poll votes data with the new [pollVotes] data + Future updatePollVotes(List pollVotes); + /// Deletes all the reactions by [messageIds] Future deleteReactionsByMessageId(List messageIds); /// Deletes all the pinned messages reactions by [messageIds] Future deletePinnedMessageReactionsByMessageId(List messageIds); + /// Deletes all the poll votes by [pollIds] + Future deletePollVotesByPollIds(List pollIds); + /// Deletes all the members by channel [cids] Future deleteMembersByCids(List cids); @@ -245,50 +259,64 @@ abstract class ChatPersistenceClient { final reactions = []; final pinnedReactions = []; + final polls = []; + final pollVotes = []; + final pollVotesToDelete = []; + for (final state in channelStates) { final channel = state.channel; - if (channel != null) { - channels.add(channel); - - final cid = channel.cid; - final reads = state.read; - final members = state.members; - final Iterable? messages; - if (CurrentPlatform.isWeb) { - messages = state.messages?.where( + // Continue if channel is not available. + if (channel == null) continue; + channels.add(channel); + + final cid = channel.cid; + final reads = state.read; + final members = state.members; + final messages = switch (CurrentPlatform.isWeb) { + true => state.messages?.where( (it) => !it.attachments.any( (it) => it.uploadState != const UploadState.success(), ), - ); - } else { - messages = state.messages; - } - final pinnedMessages = state.pinnedMessages; - - // Preparing deletion data - membersToDelete.add(cid); - reactionsToDelete.addAll(state.messages?.map((it) => it.id) ?? []); - pinnedReactionsToDelete - .addAll(state.pinnedMessages?.map((it) => it.id) ?? []); - - // preparing addition data - channelWithReads[cid] = reads; - channelWithMembers[cid] = members; - channelWithMessages[cid] = messages?.toList(); - channelWithPinnedMessages[cid] = pinnedMessages; - - reactions.addAll(messages?.expand(_expandReactions) ?? []); - pinnedReactions.addAll(pinnedMessages?.expand(_expandReactions) ?? []); - - users.addAll([ - channel.createdBy, - ...messages?.map((it) => it.user) ?? [], - ...reads?.map((it) => it.user) ?? [], - ...members?.map((it) => it.user) ?? [], - ...reactions.map((it) => it.user), - ...pinnedReactions.map((it) => it.user), - ].withNullifyer); - } + ), + _ => state.messages, + }; + + final pinnedMessages = state.pinnedMessages; + + // Preparing deletion data + membersToDelete.add(cid); + reactionsToDelete.addAll(messages?.map((it) => it.id) ?? []); + pinnedReactionsToDelete.addAll(pinnedMessages?.map((it) => it.id) ?? []); + + // preparing addition data + channelWithReads[cid] = reads; + channelWithMembers[cid] = members; + channelWithMessages[cid] = messages?.toList(); + channelWithPinnedMessages[cid] = pinnedMessages; + + reactions.addAll(messages?.expand(_expandReactions) ?? []); + pinnedReactions.addAll(pinnedMessages?.expand(_expandReactions) ?? []); + + polls.addAll([ + ...?messages?.map((it) => it.poll), + ...?pinnedMessages?.map((it) => it.poll), + ].withNullifyer); + + pollVotesToDelete.addAll(polls.map((it) => it.id)); + + pollVotes.addAll(polls.expand(_expandPollVotes)); + + users.addAll([ + channel.createdBy, + ...?messages?.map((it) => it.user), + ...?pinnedMessages?.map((it) => it.user), + ...?reads?.map((it) => it.user), + ...?members?.map((it) => it.user), + ...reactions.map((it) => it.user), + ...pinnedReactions.map((it) => it.user), + ...polls.map((it) => it.createdBy), + ...pollVotes.map((it) => it.user), + ].withNullifyer); } // Removing old members and reactions data as they may have @@ -297,12 +325,14 @@ abstract class ChatPersistenceClient { deleteMembersByCids(membersToDelete), deleteReactionsByMessageId(reactionsToDelete), deletePinnedMessageReactionsByMessageId(pinnedReactionsToDelete), + deletePollVotesByPollIds(pollVotesToDelete), ]); // Updating first as does not depend on any other table. await Future.wait([ updateUsers(users.toList(growable: false)), updateChannels(channels.toList(growable: false)), + updatePolls(polls.toList(growable: false)), ]); // All has a foreign key relation with channels table. @@ -315,10 +345,9 @@ abstract class ChatPersistenceClient { // Both has a foreign key relation with messages, pinnedMessages table. await Future.wait([ - updateReactions(reactions.toList(growable: false)), - updatePinnedMessageReactions( - pinnedReactions.toList(growable: false), - ), + updateReactions(reactions), + updatePinnedMessageReactions(pinnedReactions), + updatePollVotes(pollVotes), ]); } @@ -330,4 +359,15 @@ abstract class ChatPersistenceClient { if (latest != null) ...latest.where((r) => r.userId != null), ]; } + + List _expandPollVotes(Poll poll) { + final latestAnswers = poll.latestAnswers; + final latestVotes = poll.latestVotesByOption.values; + final ownVotesAndAnswers = poll.ownVotesAndAnswers; + return [ + ...latestAnswers, + ...latestVotes.expand((it) => it), + ...ownVotesAndAnswers, + ]; + } } diff --git a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart index 4bc646f7a..cd5313698 100644 --- a/packages/stream_chat/test/src/db/chat_persistence_client_test.dart +++ b/packages/stream_chat/test/src/db/chat_persistence_client_test.dart @@ -5,6 +5,8 @@ import 'package:stream_chat/src/core/models/event.dart'; import 'package:stream_chat/src/core/models/filter.dart'; import 'package:stream_chat/src/core/models/member.dart'; import 'package:stream_chat/src/core/models/message.dart'; +import 'package:stream_chat/src/core/models/poll.dart'; +import 'package:stream_chat/src/core/models/poll_vote.dart'; import 'package:stream_chat/src/core/models/reaction.dart'; import 'package:stream_chat/src/core/models/read.dart'; import 'package:stream_chat/src/core/models/user.dart'; @@ -49,6 +51,9 @@ class TestPersistenceClient extends ChatPersistenceClient { List messageIds) => Future.value(); + @override + Future deletePollVotesByPollIds(List pollIds) => Future.value(); + @override Future disconnect({bool flush = false}) => throw UnimplementedError(); @@ -119,6 +124,9 @@ class TestPersistenceClient extends ChatPersistenceClient { Future updatePinnedMessageReactions(List reactions) => Future.value(); + @override + Future updatePollVotes(List pollVotes) => Future.value(); + @override Future updateUsers(List users) => Future.value(); @@ -137,6 +145,12 @@ class TestPersistenceClient extends ChatPersistenceClient { @override Future bulkUpdateReads(Map?> reads) => Future.value(); + + @override + Future deletePollsByIds(List pollIds) => Future.value(); + + @override + Future updatePolls(List polls) => Future.value(); } void main() { @@ -169,6 +183,16 @@ void main() { expect(channelState, isNotNull); }); + test('deletePollsByIds', () { + const pollIds = ['poll-id']; + persistenceClient.deletePollsByIds(pollIds); + }); + + test('updatePolls', () async { + final poll = Poll(id: 'poll-id', name: 'poll-name', options: const []); + persistenceClient.updatePolls([poll]); + }); + test('updateChannelThreads', () async { const cid = 'test:cid'; final user = User(id: 'test-user-id'); diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index fa08a65fa..0d536528f 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -1,5 +1,6 @@ ## Upcoming +- Added support for `Poll` and `PollVote` entities in the database. - Updated minimum Flutter version to 3.24.5 for the SDK. ## 8.3.0 @@ -73,8 +74,7 @@ ## 6.7.0 -- [[#1683]](https://github.com/GetStream/stream-chat-flutter/issues/1683) Fixed SqliteException no such - column `messages.state`. +- [[#1683]](https://github.com/GetStream/stream-chat-flutter/issues/1683) Fixed SqliteException no such column `messages.state`. - Updated `stream_chat` dependency to [`6.7.0`](https://pub.dev/packages/stream_chat/changelog). ## 6.6.0 @@ -169,8 +169,7 @@ ## 3.0.0 - Updated `stream_chat` dependency to [`3.0.0`](https://pub.dev/packages/stream_chat/changelog). -- [[#604]](https://github.com/GetStream/stream-chat-flutter/issues/604) Fix cascade deletion by - enabling `pragma foreign_keys`. +- [[#604]](https://github.com/GetStream/stream-chat-flutter/issues/604) Fix cascade deletion by enabling `pragma foreign_keys`. - Added a new table `PinnedMessageReactions` and dao `PinnedMessageReactionDao` specifically for pinned messages. ## 2.2.0 diff --git a/packages/stream_chat_persistence/lib/src/converter/converter.dart b/packages/stream_chat_persistence/lib/src/converter/converter.dart index 98d34e93c..8608b30fd 100644 --- a/packages/stream_chat_persistence/lib/src/converter/converter.dart +++ b/packages/stream_chat_persistence/lib/src/converter/converter.dart @@ -1,2 +1,3 @@ export 'list_converter.dart'; export 'map_converter.dart'; +export 'voting_visibility_converter.dart'; diff --git a/packages/stream_chat_persistence/lib/src/converter/voting_visibility_converter.dart b/packages/stream_chat_persistence/lib/src/converter/voting_visibility_converter.dart new file mode 100644 index 000000000..2d5786d55 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/converter/voting_visibility_converter.dart @@ -0,0 +1,33 @@ +import 'package:drift/drift.dart'; +import 'package:stream_chat/stream_chat.dart'; + +/// A [TypeConverter] that serializes [VotingVisibility] to a [String] column. +class VotingVisibilityConverter + extends TypeConverter { + /// Constant default constructor. + const VotingVisibilityConverter(); + + @override + VotingVisibility fromSql(String fromDb) { + for (final entry in _votingVisibilityEnumMap.entries) { + if (entry.value == fromDb) { + return entry.key; + } + } + + throw ArgumentError( + '`$fromDb` is not one of the supported values: ' + '${_votingVisibilityEnumMap.values.join(', ')}', + ); + } + + @override + String toSql(VotingVisibility value) { + return _votingVisibilityEnumMap[value]!; + } +} + +const _votingVisibilityEnumMap = { + VotingVisibility.anonymous: 'anonymous', + VotingVisibility.public: 'public', +}; diff --git a/packages/stream_chat_persistence/lib/src/dao/dao.dart b/packages/stream_chat_persistence/lib/src/dao/dao.dart index 56998c985..ea76909b1 100644 --- a/packages/stream_chat_persistence/lib/src/dao/dao.dart +++ b/packages/stream_chat_persistence/lib/src/dao/dao.dart @@ -5,6 +5,8 @@ export 'member_dao.dart'; export 'message_dao.dart'; export 'pinned_message_dao.dart'; export 'pinned_message_reaction_dao.dart'; +export 'poll_dao.dart'; +export 'poll_vote_dao.dart'; export 'reaction_dao.dart'; export 'read_dao.dart'; export 'user_dao.dart'; diff --git a/packages/stream_chat_persistence/lib/src/dao/message_dao.dart b/packages/stream_chat_persistence/lib/src/dao/message_dao.dart index b21bd3cdd..762da39ae 100644 --- a/packages/stream_chat_persistence/lib/src/dao/message_dao.dart +++ b/packages/stream_chat_persistence/lib/src/dao/message_dao.dart @@ -50,12 +50,18 @@ class MessageDao extends DatabaseAccessor if (quotedMessageId != null) { quotedMessage = await getMessageById(quotedMessageId); } + Poll? poll; + final pollId = msgEntity.pollId; + if (pollId != null) { + poll = await _db.pollDao.getPollById(pollId); + } return msgEntity.toMessage( user: userEntity?.toUser(), pinnedBy: pinnedByEntity?.toUser(), latestReactions: latestReactions, ownReactions: ownReactions, quotedMessage: quotedMessage, + poll: poll, ); } diff --git a/packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart b/packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart index 8be2399b6..bf7b45b12 100644 --- a/packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart +++ b/packages/stream_chat_persistence/lib/src/dao/pinned_message_dao.dart @@ -51,12 +51,18 @@ class PinnedMessageDao extends DatabaseAccessor if (quotedMessageId != null) { quotedMessage = await getMessageById(quotedMessageId); } + Poll? poll; + final pollId = msgEntity.pollId; + if (pollId != null) { + poll = await _db.pollDao.getPollById(pollId); + } return msgEntity.toMessage( user: userEntity?.toUser(), pinnedBy: pinnedByEntity?.toUser(), latestReactions: latestReactions, ownReactions: ownReactions, quotedMessage: quotedMessage, + poll: poll, ); } diff --git a/packages/stream_chat_persistence/lib/src/dao/poll_dao.dart b/packages/stream_chat_persistence/lib/src/dao/poll_dao.dart new file mode 100644 index 000000000..10a10a024 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/dao/poll_dao.dart @@ -0,0 +1,72 @@ +import 'package:drift/drift.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; +import 'package:stream_chat_persistence/src/entity/poll_votes.dart'; +import 'package:stream_chat_persistence/src/entity/polls.dart'; +import 'package:stream_chat_persistence/src/entity/users.dart'; +import 'package:stream_chat_persistence/src/mapper/poll_mapper.dart'; +import 'package:stream_chat_persistence/src/mapper/user_mapper.dart'; + +part 'poll_dao.g.dart'; + +/// The Data Access Object for operations in [Polls] table. +@DriftAccessor(tables: [Polls, PollVotes, Users]) +class PollDao extends DatabaseAccessor with _$PollDaoMixin { + /// Creates a new poll dao instance + PollDao(this._db) : super(_db); + + final DriftChatDatabase _db; + + Future _pollFromJoinRow(TypedResult row) async { + final pollEntity = row.readTable(polls); + final userEntity = row.readTable(users); + final allVotes = await _db.pollVoteDao.getPollVotes(pollEntity.id); + final latestAnswers = allVotes.where((it) => it.isAnswer); + final ownVotesAndAnswers = allVotes.where((it) => it.userId == _db.userId); + + final latestVotesByOption = >{}; + for (final vote in allVotes) { + if (vote.isAnswer) continue; + if (vote.optionId case final optionId?) { + latestVotesByOption.update( + optionId, + (value) => [...value, vote], + ifAbsent: () => [vote], + ); + } + } + + return pollEntity.toPoll( + createdBy: userEntity.toUser(), + latestAnswers: latestAnswers.toList(), + ownVotesAndAnswers: ownVotesAndAnswers.toList(), + latestVotesByOption: latestVotesByOption, + ); + } + + /// Returns the poll by matching [Polls.id] with [pollId] + Future getPollById(String pollId) async => + await (select(polls)..where((it) => it.id.equals(pollId))) + .join([leftOuterJoin(users, polls.createdById.equalsExp(users.id))]) + .map(_pollFromJoinRow) + .getSingleOrNull(); + + /// Updates all the polls using the new [pollList] data + Future updatePolls(List pollList) => batch( + (it) => it.insertAllOnConflictUpdate( + polls, + pollList.map((it) => it.toEntity()), + ), + ); + + /// Returns the list of all the polls stored in db + Future> 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 deletePollsByIds(List pollIds) => + (delete(polls)..where((tbl) => tbl.id.isIn(pollIds))).go(); +} diff --git a/packages/stream_chat_persistence/lib/src/dao/poll_dao.g.dart b/packages/stream_chat_persistence/lib/src/dao/poll_dao.g.dart new file mode 100644 index 000000000..7b3c32a04 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/dao/poll_dao.g.dart @@ -0,0 +1,10 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'poll_dao.dart'; + +// ignore_for_file: type=lint +mixin _$PollDaoMixin on DatabaseAccessor { + $PollsTable get polls => attachedDatabase.polls; + $PollVotesTable get pollVotes => attachedDatabase.pollVotes; + $UsersTable get users => attachedDatabase.users; +} diff --git a/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.dart b/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.dart new file mode 100644 index 000000000..55884f4a7 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.dart @@ -0,0 +1,45 @@ +import 'package:drift/drift.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; +import 'package:stream_chat_persistence/src/entity/poll_votes.dart'; +import 'package:stream_chat_persistence/src/entity/polls.dart'; +import 'package:stream_chat_persistence/src/entity/users.dart'; +import 'package:stream_chat_persistence/src/mapper/poll_vote_mapper.dart'; +import 'package:stream_chat_persistence/src/mapper/user_mapper.dart'; + +part 'poll_vote_dao.g.dart'; + +/// The Data Access Object for operations in [Polls] table. +@DriftAccessor(tables: [PollVotes, Users]) +class PollVoteDao extends DatabaseAccessor + with _$PollVoteDaoMixin { + /// Creates a new poll vote dao instance + PollVoteDao(super.db); + + /// Returns all the reactions of a particular message by matching + /// [Reactions.messageId] with [messageId] + Future> getPollVotes(String pollId) => + (select(pollVotes).join([ + leftOuterJoin(users, pollVotes.userId.equalsExp(users.id)), + ]) + ..where(pollVotes.pollId.equals(pollId)) + ..orderBy([OrderingTerm.asc(pollVotes.createdAt)])) + .map((rows) { + final userEntity = rows.readTableOrNull(users); + final pollVoteEntity = rows.readTable(pollVotes); + return pollVoteEntity.toPollVote(user: userEntity?.toUser()); + }).get(); + + /// Updates the poll votes data with the new [pollVoteList] data + Future updatePollVotes(List pollVoteList) => batch( + (it) => it.insertAllOnConflictUpdate( + pollVotes, + pollVoteList.map((it) => it.toEntity()), + ), + ); + + /// Deletes all the poll votes whose [PollVote.pollId] is + /// present in [pollIds] + Future deletePollVotesByPollIds(List pollIds) => + (delete(pollVotes)..where((tbl) => tbl.pollId.isIn(pollIds))).go(); +} diff --git a/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.g.dart b/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.g.dart new file mode 100644 index 000000000..9731591eb --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/dao/poll_vote_dao.g.dart @@ -0,0 +1,10 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'poll_vote_dao.dart'; + +// ignore_for_file: type=lint +mixin _$PollVoteDaoMixin on DatabaseAccessor { + $PollsTable get polls => attachedDatabase.polls; + $PollVotesTable get pollVotes => attachedDatabase.pollVotes; + $UsersTable get users => attachedDatabase.users; +} diff --git a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart index 1198a26e2..5acd58f15 100644 --- a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart +++ b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.dart @@ -1,4 +1,5 @@ import 'package:drift/drift.dart'; +import 'package:stream_chat/stream_chat.dart' show VotingVisibility; import 'package:stream_chat_persistence/src/converter/converter.dart'; import 'package:stream_chat_persistence/src/dao/dao.dart'; import 'package:stream_chat_persistence/src/entity/entity.dart'; @@ -13,6 +14,8 @@ part 'drift_chat_database.g.dart'; Channels, Messages, PinnedMessages, + Polls, + PollVotes, PinnedMessageReactions, Reactions, Users, @@ -28,6 +31,8 @@ part 'drift_chat_database.g.dart'; PinnedMessageDao, PinnedMessageReactionDao, MemberDao, + PollDao, + PollVoteDao, ReactionDao, ReadDao, ChannelQueryDao, @@ -48,7 +53,7 @@ class DriftChatDatabase extends _$DriftChatDatabase { // you should bump this number whenever you change or add a table definition. @override - int get schemaVersion => 15; + int get schemaVersion => 16; @override MigrationStrategy get migration => MigrationStrategy( diff --git a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart index 4226d2590..92a8e9f59 100644 --- a/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart +++ b/packages/stream_chat_persistence/lib/src/db/drift_chat_database.g.dart @@ -738,6 +738,11 @@ class $MessagesTable extends Messages late final GeneratedColumn quotedMessageId = GeneratedColumn( 'quoted_message_id', aliasedName, true, type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _pollIdMeta = const VerificationMeta('pollId'); + @override + late final GeneratedColumn pollId = GeneratedColumn( + 'poll_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); static const VerificationMeta _replyCountMeta = const VerificationMeta('replyCount'); @override @@ -878,6 +883,7 @@ class $MessagesTable extends Messages reactionScores, parentId, quotedMessageId, + pollId, replyCount, showInChannel, shadowed, @@ -943,6 +949,10 @@ class $MessagesTable extends Messages quotedMessageId.isAcceptableOrUnknown( data['quoted_message_id']!, _quotedMessageIdMeta)); } + if (data.containsKey('poll_id')) { + context.handle(_pollIdMeta, + pollId.isAcceptableOrUnknown(data['poll_id']!, _pollIdMeta)); + } if (data.containsKey('reply_count')) { context.handle( _replyCountMeta, @@ -1072,6 +1082,8 @@ class $MessagesTable extends Messages .read(DriftSqlType.string, data['${effectivePrefix}parent_id']), quotedMessageId: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}quoted_message_id']), + pollId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}poll_id']), replyCount: attachedDatabase.typeMapping .read(DriftSqlType.int, data['${effectivePrefix}reply_count']), showInChannel: attachedDatabase.typeMapping @@ -1172,6 +1184,9 @@ class MessageEntity extends DataClass implements Insertable { /// The ID of the quoted message, if the message is a quoted reply. final String? quotedMessageId; + /// The ID of the poll, if the message is a poll. + final String? pollId; + /// Number of replies for this message. final int? replyCount; @@ -1239,6 +1254,7 @@ class MessageEntity extends DataClass implements Insertable { this.reactionScores, this.parentId, this.quotedMessageId, + this.pollId, this.replyCount, this.showInChannel, required this.shadowed, @@ -1289,6 +1305,9 @@ class MessageEntity extends DataClass implements Insertable { if (!nullToAbsent || quotedMessageId != null) { map['quoted_message_id'] = Variable(quotedMessageId); } + if (!nullToAbsent || pollId != null) { + map['poll_id'] = Variable(pollId); + } if (!nullToAbsent || replyCount != null) { map['reply_count'] = Variable(replyCount); } @@ -1360,6 +1379,7 @@ class MessageEntity extends DataClass implements Insertable { serializer.fromJson?>(json['reactionScores']), parentId: serializer.fromJson(json['parentId']), quotedMessageId: serializer.fromJson(json['quotedMessageId']), + pollId: serializer.fromJson(json['pollId']), replyCount: serializer.fromJson(json['replyCount']), showInChannel: serializer.fromJson(json['showInChannel']), shadowed: serializer.fromJson(json['shadowed']), @@ -1396,6 +1416,7 @@ class MessageEntity extends DataClass implements Insertable { 'reactionScores': serializer.toJson?>(reactionScores), 'parentId': serializer.toJson(parentId), 'quotedMessageId': serializer.toJson(quotedMessageId), + 'pollId': serializer.toJson(pollId), 'replyCount': serializer.toJson(replyCount), 'showInChannel': serializer.toJson(showInChannel), 'shadowed': serializer.toJson(shadowed), @@ -1430,6 +1451,7 @@ class MessageEntity extends DataClass implements Insertable { Value?> reactionScores = const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), Value replyCount = const Value.absent(), Value showInChannel = const Value.absent(), bool? shadowed, @@ -1464,6 +1486,7 @@ class MessageEntity extends DataClass implements Insertable { quotedMessageId: quotedMessageId.present ? quotedMessageId.value : this.quotedMessageId, + pollId: pollId.present ? pollId.value : this.pollId, replyCount: replyCount.present ? replyCount.value : this.replyCount, showInChannel: showInChannel.present ? showInChannel.value : this.showInChannel, @@ -1519,6 +1542,7 @@ class MessageEntity extends DataClass implements Insertable { quotedMessageId: data.quotedMessageId.present ? data.quotedMessageId.value : this.quotedMessageId, + pollId: data.pollId.present ? data.pollId.value : this.pollId, replyCount: data.replyCount.present ? data.replyCount.value : this.replyCount, showInChannel: data.showInChannel.present @@ -1575,6 +1599,7 @@ class MessageEntity extends DataClass implements Insertable { ..write('reactionScores: $reactionScores, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') + ..write('pollId: $pollId, ') ..write('replyCount: $replyCount, ') ..write('showInChannel: $showInChannel, ') ..write('shadowed: $shadowed, ') @@ -1610,6 +1635,7 @@ class MessageEntity extends DataClass implements Insertable { reactionScores, parentId, quotedMessageId, + pollId, replyCount, showInChannel, shadowed, @@ -1644,6 +1670,7 @@ class MessageEntity extends DataClass implements Insertable { other.reactionScores == this.reactionScores && other.parentId == this.parentId && other.quotedMessageId == this.quotedMessageId && + other.pollId == this.pollId && other.replyCount == this.replyCount && other.showInChannel == this.showInChannel && other.shadowed == this.shadowed && @@ -1676,6 +1703,7 @@ class MessagesCompanion extends UpdateCompanion { final Value?> reactionScores; final Value parentId; final Value quotedMessageId; + final Value pollId; final Value replyCount; final Value showInChannel; final Value shadowed; @@ -1707,6 +1735,7 @@ class MessagesCompanion extends UpdateCompanion { this.reactionScores = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), + this.pollId = const Value.absent(), this.replyCount = const Value.absent(), this.showInChannel = const Value.absent(), this.shadowed = const Value.absent(), @@ -1739,6 +1768,7 @@ class MessagesCompanion extends UpdateCompanion { this.reactionScores = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), + this.pollId = const Value.absent(), this.replyCount = const Value.absent(), this.showInChannel = const Value.absent(), this.shadowed = const Value.absent(), @@ -1775,6 +1805,7 @@ class MessagesCompanion extends UpdateCompanion { Expression? reactionScores, Expression? parentId, Expression? quotedMessageId, + Expression? pollId, Expression? replyCount, Expression? showInChannel, Expression? shadowed, @@ -1807,6 +1838,7 @@ class MessagesCompanion extends UpdateCompanion { if (reactionScores != null) 'reaction_scores': reactionScores, if (parentId != null) 'parent_id': parentId, if (quotedMessageId != null) 'quoted_message_id': quotedMessageId, + if (pollId != null) 'poll_id': pollId, if (replyCount != null) 'reply_count': replyCount, if (showInChannel != null) 'show_in_channel': showInChannel, if (shadowed != null) 'shadowed': shadowed, @@ -1842,6 +1874,7 @@ class MessagesCompanion extends UpdateCompanion { Value?>? reactionScores, Value? parentId, Value? quotedMessageId, + Value? pollId, Value? replyCount, Value? showInChannel, Value? shadowed, @@ -1873,6 +1906,7 @@ class MessagesCompanion extends UpdateCompanion { reactionScores: reactionScores ?? this.reactionScores, parentId: parentId ?? this.parentId, quotedMessageId: quotedMessageId ?? this.quotedMessageId, + pollId: pollId ?? this.pollId, replyCount: replyCount ?? this.replyCount, showInChannel: showInChannel ?? this.showInChannel, shadowed: shadowed ?? this.shadowed, @@ -1933,6 +1967,9 @@ class MessagesCompanion extends UpdateCompanion { if (quotedMessageId.present) { map['quoted_message_id'] = Variable(quotedMessageId.value); } + if (pollId.present) { + map['poll_id'] = Variable(pollId.value); + } if (replyCount.present) { map['reply_count'] = Variable(replyCount.value); } @@ -2012,6 +2049,7 @@ class MessagesCompanion extends UpdateCompanion { ..write('reactionScores: $reactionScores, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') + ..write('pollId: $pollId, ') ..write('replyCount: $replyCount, ') ..write('showInChannel: $showInChannel, ') ..write('shadowed: $shadowed, ') @@ -2113,6 +2151,11 @@ class $PinnedMessagesTable extends PinnedMessages late final GeneratedColumn quotedMessageId = GeneratedColumn( 'quoted_message_id', aliasedName, true, type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _pollIdMeta = const VerificationMeta('pollId'); + @override + late final GeneratedColumn pollId = GeneratedColumn( + 'poll_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); static const VerificationMeta _replyCountMeta = const VerificationMeta('replyCount'); @override @@ -2251,6 +2294,7 @@ class $PinnedMessagesTable extends PinnedMessages reactionScores, parentId, quotedMessageId, + pollId, replyCount, showInChannel, shadowed, @@ -2317,6 +2361,10 @@ class $PinnedMessagesTable extends PinnedMessages quotedMessageId.isAcceptableOrUnknown( data['quoted_message_id']!, _quotedMessageIdMeta)); } + if (data.containsKey('poll_id')) { + context.handle(_pollIdMeta, + pollId.isAcceptableOrUnknown(data['poll_id']!, _pollIdMeta)); + } if (data.containsKey('reply_count')) { context.handle( _replyCountMeta, @@ -2446,6 +2494,8 @@ class $PinnedMessagesTable extends PinnedMessages .read(DriftSqlType.string, data['${effectivePrefix}parent_id']), quotedMessageId: attachedDatabase.typeMapping.read( DriftSqlType.string, data['${effectivePrefix}quoted_message_id']), + pollId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}poll_id']), replyCount: attachedDatabase.typeMapping .read(DriftSqlType.int, data['${effectivePrefix}reply_count']), showInChannel: attachedDatabase.typeMapping @@ -2548,6 +2598,9 @@ class PinnedMessageEntity extends DataClass /// The ID of the quoted message, if the message is a quoted reply. final String? quotedMessageId; + /// The ID of the poll, if the message is a poll. + final String? pollId; + /// Number of replies for this message. final int? replyCount; @@ -2615,6 +2668,7 @@ class PinnedMessageEntity extends DataClass this.reactionScores, this.parentId, this.quotedMessageId, + this.pollId, this.replyCount, this.showInChannel, required this.shadowed, @@ -2665,6 +2719,9 @@ class PinnedMessageEntity extends DataClass if (!nullToAbsent || quotedMessageId != null) { map['quoted_message_id'] = Variable(quotedMessageId); } + if (!nullToAbsent || pollId != null) { + map['poll_id'] = Variable(pollId); + } if (!nullToAbsent || replyCount != null) { map['reply_count'] = Variable(replyCount); } @@ -2737,6 +2794,7 @@ class PinnedMessageEntity extends DataClass serializer.fromJson?>(json['reactionScores']), parentId: serializer.fromJson(json['parentId']), quotedMessageId: serializer.fromJson(json['quotedMessageId']), + pollId: serializer.fromJson(json['pollId']), replyCount: serializer.fromJson(json['replyCount']), showInChannel: serializer.fromJson(json['showInChannel']), shadowed: serializer.fromJson(json['shadowed']), @@ -2773,6 +2831,7 @@ class PinnedMessageEntity extends DataClass 'reactionScores': serializer.toJson?>(reactionScores), 'parentId': serializer.toJson(parentId), 'quotedMessageId': serializer.toJson(quotedMessageId), + 'pollId': serializer.toJson(pollId), 'replyCount': serializer.toJson(replyCount), 'showInChannel': serializer.toJson(showInChannel), 'shadowed': serializer.toJson(shadowed), @@ -2807,6 +2866,7 @@ class PinnedMessageEntity extends DataClass Value?> reactionScores = const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), Value replyCount = const Value.absent(), Value showInChannel = const Value.absent(), bool? shadowed, @@ -2841,6 +2901,7 @@ class PinnedMessageEntity extends DataClass quotedMessageId: quotedMessageId.present ? quotedMessageId.value : this.quotedMessageId, + pollId: pollId.present ? pollId.value : this.pollId, replyCount: replyCount.present ? replyCount.value : this.replyCount, showInChannel: showInChannel.present ? showInChannel.value : this.showInChannel, @@ -2896,6 +2957,7 @@ class PinnedMessageEntity extends DataClass quotedMessageId: data.quotedMessageId.present ? data.quotedMessageId.value : this.quotedMessageId, + pollId: data.pollId.present ? data.pollId.value : this.pollId, replyCount: data.replyCount.present ? data.replyCount.value : this.replyCount, showInChannel: data.showInChannel.present @@ -2952,6 +3014,7 @@ class PinnedMessageEntity extends DataClass ..write('reactionScores: $reactionScores, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') + ..write('pollId: $pollId, ') ..write('replyCount: $replyCount, ') ..write('showInChannel: $showInChannel, ') ..write('shadowed: $shadowed, ') @@ -2987,6 +3050,7 @@ class PinnedMessageEntity extends DataClass reactionScores, parentId, quotedMessageId, + pollId, replyCount, showInChannel, shadowed, @@ -3021,6 +3085,7 @@ class PinnedMessageEntity extends DataClass other.reactionScores == this.reactionScores && other.parentId == this.parentId && other.quotedMessageId == this.quotedMessageId && + other.pollId == this.pollId && other.replyCount == this.replyCount && other.showInChannel == this.showInChannel && other.shadowed == this.shadowed && @@ -3053,6 +3118,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { final Value?> reactionScores; final Value parentId; final Value quotedMessageId; + final Value pollId; final Value replyCount; final Value showInChannel; final Value shadowed; @@ -3084,6 +3150,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { this.reactionScores = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), + this.pollId = const Value.absent(), this.replyCount = const Value.absent(), this.showInChannel = const Value.absent(), this.shadowed = const Value.absent(), @@ -3116,6 +3183,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { this.reactionScores = const Value.absent(), this.parentId = const Value.absent(), this.quotedMessageId = const Value.absent(), + this.pollId = const Value.absent(), this.replyCount = const Value.absent(), this.showInChannel = const Value.absent(), this.shadowed = const Value.absent(), @@ -3152,6 +3220,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { Expression? reactionScores, Expression? parentId, Expression? quotedMessageId, + Expression? pollId, Expression? replyCount, Expression? showInChannel, Expression? shadowed, @@ -3184,6 +3253,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { if (reactionScores != null) 'reaction_scores': reactionScores, if (parentId != null) 'parent_id': parentId, if (quotedMessageId != null) 'quoted_message_id': quotedMessageId, + if (pollId != null) 'poll_id': pollId, if (replyCount != null) 'reply_count': replyCount, if (showInChannel != null) 'show_in_channel': showInChannel, if (shadowed != null) 'shadowed': shadowed, @@ -3219,6 +3289,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { Value?>? reactionScores, Value? parentId, Value? quotedMessageId, + Value? pollId, Value? replyCount, Value? showInChannel, Value? shadowed, @@ -3250,6 +3321,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { reactionScores: reactionScores ?? this.reactionScores, parentId: parentId ?? this.parentId, quotedMessageId: quotedMessageId ?? this.quotedMessageId, + pollId: pollId ?? this.pollId, replyCount: replyCount ?? this.replyCount, showInChannel: showInChannel ?? this.showInChannel, shadowed: shadowed ?? this.shadowed, @@ -3313,6 +3385,9 @@ class PinnedMessagesCompanion extends UpdateCompanion { if (quotedMessageId.present) { map['quoted_message_id'] = Variable(quotedMessageId.value); } + if (pollId.present) { + map['poll_id'] = Variable(pollId.value); + } if (replyCount.present) { map['reply_count'] = Variable(replyCount.value); } @@ -3392,6 +3467,7 @@ class PinnedMessagesCompanion extends UpdateCompanion { ..write('reactionScores: $reactionScores, ') ..write('parentId: $parentId, ') ..write('quotedMessageId: $quotedMessageId, ') + ..write('pollId: $pollId, ') ..write('replyCount: $replyCount, ') ..write('showInChannel: $showInChannel, ') ..write('shadowed: $shadowed, ') @@ -3417,31 +3493,122 @@ class PinnedMessagesCompanion extends UpdateCompanion { } } -class $PinnedMessageReactionsTable extends PinnedMessageReactions - with TableInfo<$PinnedMessageReactionsTable, PinnedMessageReactionEntity> { +class $PollsTable extends Polls with TableInfo<$PollsTable, PollEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $PinnedMessageReactionsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); + $PollsTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override - late final GeneratedColumn userId = GeneratedColumn( - 'user_id', aliasedName, false, + late final GeneratedColumn id = GeneratedColumn( + 'id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _messageIdMeta = - const VerificationMeta('messageId'); + static const VerificationMeta _nameMeta = const VerificationMeta('name'); @override - late final GeneratedColumn messageId = GeneratedColumn( - 'message_id', aliasedName, false, - type: DriftSqlType.string, - requiredDuringInsert: true, + late final GeneratedColumn name = GeneratedColumn( + 'name', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _descriptionMeta = + const VerificationMeta('description'); + @override + late final GeneratedColumn description = GeneratedColumn( + 'description', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _optionsMeta = + const VerificationMeta('options'); + @override + late final GeneratedColumnWithTypeConverter, String> options = + GeneratedColumn('options', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true) + .withConverter>($PollsTable.$converteroptions); + static const VerificationMeta _votingVisibilityMeta = + const VerificationMeta('votingVisibility'); + @override + late final GeneratedColumnWithTypeConverter + votingVisibility = GeneratedColumn( + 'voting_visibility', aliasedName, false, + type: DriftSqlType.string, + requiredDuringInsert: false, + defaultValue: const Constant('public')) + .withConverter( + $PollsTable.$convertervotingVisibility); + static const VerificationMeta _enforceUniqueVoteMeta = + const VerificationMeta('enforceUniqueVote'); + @override + late final GeneratedColumn enforceUniqueVote = GeneratedColumn( + 'enforce_unique_vote', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways( - 'REFERENCES pinned_messages (id) ON DELETE CASCADE')); - static const VerificationMeta _typeMeta = const VerificationMeta('type'); + 'CHECK ("enforce_unique_vote" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _maxVotesAllowedMeta = + const VerificationMeta('maxVotesAllowed'); @override - late final GeneratedColumn type = GeneratedColumn( - 'type', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true); + late final GeneratedColumn maxVotesAllowed = GeneratedColumn( + 'max_votes_allowed', aliasedName, true, + type: DriftSqlType.int, requiredDuringInsert: false); + static const VerificationMeta _allowUserSuggestedOptionsMeta = + const VerificationMeta('allowUserSuggestedOptions'); + @override + late final GeneratedColumn allowUserSuggestedOptions = + GeneratedColumn('allow_user_suggested_options', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("allow_user_suggested_options" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _allowAnswersMeta = + const VerificationMeta('allowAnswers'); + @override + late final GeneratedColumn allowAnswers = GeneratedColumn( + 'allow_answers', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("allow_answers" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _isClosedMeta = + const VerificationMeta('isClosed'); + @override + late final GeneratedColumn isClosed = GeneratedColumn( + 'is_closed', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: + GeneratedColumn.constraintIsAlways('CHECK ("is_closed" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _answersCountMeta = + const VerificationMeta('answersCount'); + @override + late final GeneratedColumn answersCount = GeneratedColumn( + 'answers_count', aliasedName, false, + type: DriftSqlType.int, + requiredDuringInsert: false, + defaultValue: const Constant(0)); + static const VerificationMeta _voteCountsByOptionMeta = + const VerificationMeta('voteCountsByOption'); + @override + late final GeneratedColumnWithTypeConverter, String> + voteCountsByOption = GeneratedColumn( + 'vote_counts_by_option', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true) + .withConverter>( + $PollsTable.$convertervoteCountsByOption); + static const VerificationMeta _voteCountMeta = + const VerificationMeta('voteCount'); + @override + late final GeneratedColumn voteCount = GeneratedColumn( + 'vote_count', aliasedName, false, + type: DriftSqlType.int, + requiredDuringInsert: false, + defaultValue: const Constant(0)); + static const VerificationMeta _createdByIdMeta = + const VerificationMeta('createdById'); + @override + late final GeneratedColumn createdById = GeneratedColumn( + 'created_by_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); static const VerificationMeta _createdAtMeta = const VerificationMeta('createdAt'); @override @@ -3450,13 +3617,14 @@ class $PinnedMessageReactionsTable extends PinnedMessageReactions type: DriftSqlType.dateTime, requiredDuringInsert: false, defaultValue: currentDateAndTime); - static const VerificationMeta _scoreMeta = const VerificationMeta('score'); + static const VerificationMeta _updatedAtMeta = + const VerificationMeta('updatedAt'); @override - late final GeneratedColumn score = GeneratedColumn( - 'score', aliasedName, false, - type: DriftSqlType.int, + late final GeneratedColumn updatedAt = GeneratedColumn( + 'updated_at', aliasedName, false, + type: DriftSqlType.dateTime, requiredDuringInsert: false, - defaultValue: const Constant(0)); + defaultValue: currentDateAndTime); static const VerificationMeta _extraDataMeta = const VerificationMeta('extraData'); @override @@ -3464,135 +3632,321 @@ class $PinnedMessageReactionsTable extends PinnedMessageReactions extraData = GeneratedColumn('extra_data', aliasedName, true, type: DriftSqlType.string, requiredDuringInsert: false) .withConverter?>( - $PinnedMessageReactionsTable.$converterextraDatan); + $PollsTable.$converterextraDatan); @override - List get $columns => - [userId, messageId, type, createdAt, score, extraData]; + List get $columns => [ + id, + name, + description, + options, + votingVisibility, + enforceUniqueVote, + maxVotesAllowed, + allowUserSuggestedOptions, + allowAnswers, + isClosed, + answersCount, + voteCountsByOption, + voteCount, + createdById, + createdAt, + updatedAt, + extraData + ]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'pinned_message_reactions'; + static const String $name = 'polls'; @override - VerificationContext validateIntegrity( - Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); } else if (isInserting) { - context.missing(_userIdMeta); + context.missing(_idMeta); } - if (data.containsKey('message_id')) { - context.handle(_messageIdMeta, - messageId.isAcceptableOrUnknown(data['message_id']!, _messageIdMeta)); + if (data.containsKey('name')) { + context.handle( + _nameMeta, name.isAcceptableOrUnknown(data['name']!, _nameMeta)); } else if (isInserting) { - context.missing(_messageIdMeta); + context.missing(_nameMeta); } - if (data.containsKey('type')) { + if (data.containsKey('description')) { context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); + _descriptionMeta, + description.isAcceptableOrUnknown( + data['description']!, _descriptionMeta)); + } + context.handle(_optionsMeta, const VerificationResult.success()); + context.handle(_votingVisibilityMeta, const VerificationResult.success()); + if (data.containsKey('enforce_unique_vote')) { + context.handle( + _enforceUniqueVoteMeta, + enforceUniqueVote.isAcceptableOrUnknown( + data['enforce_unique_vote']!, _enforceUniqueVoteMeta)); + } + if (data.containsKey('max_votes_allowed')) { + context.handle( + _maxVotesAllowedMeta, + maxVotesAllowed.isAcceptableOrUnknown( + data['max_votes_allowed']!, _maxVotesAllowedMeta)); + } + if (data.containsKey('allow_user_suggested_options')) { + context.handle( + _allowUserSuggestedOptionsMeta, + allowUserSuggestedOptions.isAcceptableOrUnknown( + data['allow_user_suggested_options']!, + _allowUserSuggestedOptionsMeta)); + } + if (data.containsKey('allow_answers')) { + context.handle( + _allowAnswersMeta, + allowAnswers.isAcceptableOrUnknown( + data['allow_answers']!, _allowAnswersMeta)); + } + if (data.containsKey('is_closed')) { + context.handle(_isClosedMeta, + isClosed.isAcceptableOrUnknown(data['is_closed']!, _isClosedMeta)); + } + if (data.containsKey('answers_count')) { + context.handle( + _answersCountMeta, + answersCount.isAcceptableOrUnknown( + data['answers_count']!, _answersCountMeta)); + } + context.handle(_voteCountsByOptionMeta, const VerificationResult.success()); + if (data.containsKey('vote_count')) { + context.handle(_voteCountMeta, + voteCount.isAcceptableOrUnknown(data['vote_count']!, _voteCountMeta)); + } + if (data.containsKey('created_by_id')) { + context.handle( + _createdByIdMeta, + createdById.isAcceptableOrUnknown( + data['created_by_id']!, _createdByIdMeta)); } if (data.containsKey('created_at')) { context.handle(_createdAtMeta, createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); } - if (data.containsKey('score')) { - context.handle( - _scoreMeta, score.isAcceptableOrUnknown(data['score']!, _scoreMeta)); + if (data.containsKey('updated_at')) { + context.handle(_updatedAtMeta, + updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); } context.handle(_extraDataMeta, const VerificationResult.success()); return context; } @override - Set get $primaryKey => {messageId, type, userId}; + Set get $primaryKey => {id}; @override - PinnedMessageReactionEntity map(Map data, - {String? tablePrefix}) { + PollEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return PinnedMessageReactionEntity( - userId: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, - messageId: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}message_id'])!, - type: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}type'])!, + return PollEntity( + id: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}id'])!, + name: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}name'])!, + description: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}description']), + options: $PollsTable.$converteroptions.fromSql(attachedDatabase + .typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}options'])!), + votingVisibility: $PollsTable.$convertervotingVisibility.fromSql( + attachedDatabase.typeMapping.read(DriftSqlType.string, + data['${effectivePrefix}voting_visibility'])!), + enforceUniqueVote: attachedDatabase.typeMapping.read( + DriftSqlType.bool, data['${effectivePrefix}enforce_unique_vote'])!, + maxVotesAllowed: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}max_votes_allowed']), + allowUserSuggestedOptions: attachedDatabase.typeMapping.read( + DriftSqlType.bool, + data['${effectivePrefix}allow_user_suggested_options'])!, + allowAnswers: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}allow_answers'])!, + isClosed: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}is_closed'])!, + answersCount: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}answers_count'])!, + voteCountsByOption: $PollsTable.$convertervoteCountsByOption.fromSql( + attachedDatabase.typeMapping.read(DriftSqlType.string, + data['${effectivePrefix}vote_counts_by_option'])!), + voteCount: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}vote_count'])!, + createdById: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}created_by_id']), createdAt: attachedDatabase.typeMapping .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, - score: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}score'])!, - extraData: $PinnedMessageReactionsTable.$converterextraDatan.fromSql( - attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])), + updatedAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at'])!, + extraData: $PollsTable.$converterextraDatan.fromSql(attachedDatabase + .typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])), ); } @override - $PinnedMessageReactionsTable createAlias(String alias) { - return $PinnedMessageReactionsTable(attachedDatabase, alias); + $PollsTable createAlias(String alias) { + return $PollsTable(attachedDatabase, alias); } + static TypeConverter, String> $converteroptions = + ListConverter(); + static TypeConverter $convertervotingVisibility = + const VotingVisibilityConverter(); + static TypeConverter, String> $convertervoteCountsByOption = + MapConverter(); static TypeConverter, String> $converterextraData = MapConverter(); static TypeConverter?, String?> $converterextraDatan = NullAwareTypeConverter.wrap($converterextraData); } -class PinnedMessageReactionEntity extends DataClass - implements Insertable { - /// The id of the user that sent the reaction - final String userId; +class PollEntity extends DataClass implements Insertable { + /// The unique identifier of the poll. + final String id; - /// The messageId to which the reaction belongs - final String messageId; + /// The name of the poll. + final String name; - /// The type of the reaction - final String type; + /// The description of the poll. + final String? description; - /// The DateTime on which the reaction is created + /// The list of options available for the poll. + final List options; + + /// Represents the visibility of the voting process. + /// + /// Defaults to 'public'. + final VotingVisibility votingVisibility; + + /// If true, only unique votes are allowed. + /// + /// Defaults to false. + final bool enforceUniqueVote; + + /// The maximum number of votes allowed per user. + final int? maxVotesAllowed; + + /// If true, users can suggest their own options. + /// + /// Defaults to false. + final bool allowUserSuggestedOptions; + + /// If true, users can provide their own answers/comments. + /// + /// Defaults to false. + final bool allowAnswers; + + /// Indicates if the poll is closed. + final bool isClosed; + + /// The total number of answers received by the poll. + final int answersCount; + + /// Map of vote counts by option. + final Map voteCountsByOption; + + /// The total number of votes received by the poll. + final int voteCount; + + /// The id of the user who created the poll. + final String? createdById; + + /// The date when the poll was created. final DateTime createdAt; - /// The score of the reaction (ie. number of reactions sent) - final int score; + /// The date when the poll was last updated. + final DateTime updatedAt; - /// Reaction custom extraData + /// Map of custom poll extraData final Map? extraData; - const PinnedMessageReactionEntity( - {required this.userId, - required this.messageId, - required this.type, + const PollEntity( + {required this.id, + required this.name, + this.description, + required this.options, + required this.votingVisibility, + required this.enforceUniqueVote, + this.maxVotesAllowed, + required this.allowUserSuggestedOptions, + required this.allowAnswers, + required this.isClosed, + required this.answersCount, + required this.voteCountsByOption, + required this.voteCount, + this.createdById, required this.createdAt, - required this.score, + required this.updatedAt, this.extraData}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['user_id'] = Variable(userId); - map['message_id'] = Variable(messageId); - map['type'] = Variable(type); + map['id'] = Variable(id); + map['name'] = Variable(name); + if (!nullToAbsent || description != null) { + map['description'] = Variable(description); + } + { + map['options'] = + Variable($PollsTable.$converteroptions.toSql(options)); + } + { + map['voting_visibility'] = Variable( + $PollsTable.$convertervotingVisibility.toSql(votingVisibility)); + } + map['enforce_unique_vote'] = Variable(enforceUniqueVote); + if (!nullToAbsent || maxVotesAllowed != null) { + map['max_votes_allowed'] = Variable(maxVotesAllowed); + } + map['allow_user_suggested_options'] = + Variable(allowUserSuggestedOptions); + map['allow_answers'] = Variable(allowAnswers); + map['is_closed'] = Variable(isClosed); + map['answers_count'] = Variable(answersCount); + { + map['vote_counts_by_option'] = Variable( + $PollsTable.$convertervoteCountsByOption.toSql(voteCountsByOption)); + } + map['vote_count'] = Variable(voteCount); + if (!nullToAbsent || createdById != null) { + map['created_by_id'] = Variable(createdById); + } map['created_at'] = Variable(createdAt); - map['score'] = Variable(score); + map['updated_at'] = Variable(updatedAt); if (!nullToAbsent || extraData != null) { - map['extra_data'] = Variable( - $PinnedMessageReactionsTable.$converterextraDatan.toSql(extraData)); + map['extra_data'] = + Variable($PollsTable.$converterextraDatan.toSql(extraData)); } return map; } - factory PinnedMessageReactionEntity.fromJson(Map json, + factory PollEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return PinnedMessageReactionEntity( - userId: serializer.fromJson(json['userId']), - messageId: serializer.fromJson(json['messageId']), - type: serializer.fromJson(json['type']), + return PollEntity( + id: serializer.fromJson(json['id']), + name: serializer.fromJson(json['name']), + description: serializer.fromJson(json['description']), + options: serializer.fromJson>(json['options']), + votingVisibility: + serializer.fromJson(json['votingVisibility']), + enforceUniqueVote: serializer.fromJson(json['enforceUniqueVote']), + maxVotesAllowed: serializer.fromJson(json['maxVotesAllowed']), + allowUserSuggestedOptions: + serializer.fromJson(json['allowUserSuggestedOptions']), + allowAnswers: serializer.fromJson(json['allowAnswers']), + isClosed: serializer.fromJson(json['isClosed']), + answersCount: serializer.fromJson(json['answersCount']), + voteCountsByOption: + serializer.fromJson>(json['voteCountsByOption']), + voteCount: serializer.fromJson(json['voteCount']), + createdById: serializer.fromJson(json['createdById']), createdAt: serializer.fromJson(json['createdAt']), - score: serializer.fromJson(json['score']), + updatedAt: serializer.fromJson(json['updatedAt']), extraData: serializer.fromJson?>(json['extraData']), ); } @@ -3600,133 +3954,315 @@ class PinnedMessageReactionEntity extends DataClass Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'userId': serializer.toJson(userId), - 'messageId': serializer.toJson(messageId), - 'type': serializer.toJson(type), + 'id': serializer.toJson(id), + 'name': serializer.toJson(name), + 'description': serializer.toJson(description), + 'options': serializer.toJson>(options), + 'votingVisibility': serializer.toJson(votingVisibility), + 'enforceUniqueVote': serializer.toJson(enforceUniqueVote), + 'maxVotesAllowed': serializer.toJson(maxVotesAllowed), + 'allowUserSuggestedOptions': + serializer.toJson(allowUserSuggestedOptions), + 'allowAnswers': serializer.toJson(allowAnswers), + 'isClosed': serializer.toJson(isClosed), + 'answersCount': serializer.toJson(answersCount), + 'voteCountsByOption': + serializer.toJson>(voteCountsByOption), + 'voteCount': serializer.toJson(voteCount), + 'createdById': serializer.toJson(createdById), 'createdAt': serializer.toJson(createdAt), - 'score': serializer.toJson(score), + 'updatedAt': serializer.toJson(updatedAt), 'extraData': serializer.toJson?>(extraData), }; } - PinnedMessageReactionEntity copyWith( - {String? userId, - String? messageId, - String? type, + PollEntity copyWith( + {String? id, + String? name, + Value description = const Value.absent(), + List? options, + VotingVisibility? votingVisibility, + bool? enforceUniqueVote, + Value maxVotesAllowed = const Value.absent(), + bool? allowUserSuggestedOptions, + bool? allowAnswers, + bool? isClosed, + int? answersCount, + Map? voteCountsByOption, + int? voteCount, + Value createdById = const Value.absent(), DateTime? createdAt, - int? score, + DateTime? updatedAt, Value?> extraData = const Value.absent()}) => - PinnedMessageReactionEntity( - userId: userId ?? this.userId, - messageId: messageId ?? this.messageId, - type: type ?? this.type, + PollEntity( + id: id ?? this.id, + name: name ?? this.name, + description: description.present ? description.value : this.description, + options: options ?? this.options, + votingVisibility: votingVisibility ?? this.votingVisibility, + enforceUniqueVote: enforceUniqueVote ?? this.enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed.present + ? maxVotesAllowed.value + : this.maxVotesAllowed, + allowUserSuggestedOptions: + allowUserSuggestedOptions ?? this.allowUserSuggestedOptions, + allowAnswers: allowAnswers ?? this.allowAnswers, + isClosed: isClosed ?? this.isClosed, + answersCount: answersCount ?? this.answersCount, + voteCountsByOption: voteCountsByOption ?? this.voteCountsByOption, + voteCount: voteCount ?? this.voteCount, + createdById: createdById.present ? createdById.value : this.createdById, createdAt: createdAt ?? this.createdAt, - score: score ?? this.score, + updatedAt: updatedAt ?? this.updatedAt, extraData: extraData.present ? extraData.value : this.extraData, ); - PinnedMessageReactionEntity copyWithCompanion( - PinnedMessageReactionsCompanion data) { - return PinnedMessageReactionEntity( - userId: data.userId.present ? data.userId.value : this.userId, - messageId: data.messageId.present ? data.messageId.value : this.messageId, - type: data.type.present ? data.type.value : this.type, + PollEntity copyWithCompanion(PollsCompanion data) { + return PollEntity( + id: data.id.present ? data.id.value : this.id, + name: data.name.present ? data.name.value : this.name, + description: + data.description.present ? data.description.value : this.description, + options: data.options.present ? data.options.value : this.options, + votingVisibility: data.votingVisibility.present + ? data.votingVisibility.value + : this.votingVisibility, + enforceUniqueVote: data.enforceUniqueVote.present + ? data.enforceUniqueVote.value + : this.enforceUniqueVote, + maxVotesAllowed: data.maxVotesAllowed.present + ? data.maxVotesAllowed.value + : this.maxVotesAllowed, + allowUserSuggestedOptions: data.allowUserSuggestedOptions.present + ? data.allowUserSuggestedOptions.value + : this.allowUserSuggestedOptions, + allowAnswers: data.allowAnswers.present + ? data.allowAnswers.value + : this.allowAnswers, + isClosed: data.isClosed.present ? data.isClosed.value : this.isClosed, + answersCount: data.answersCount.present + ? data.answersCount.value + : this.answersCount, + voteCountsByOption: data.voteCountsByOption.present + ? data.voteCountsByOption.value + : this.voteCountsByOption, + voteCount: data.voteCount.present ? data.voteCount.value : this.voteCount, + createdById: + data.createdById.present ? data.createdById.value : this.createdById, createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, - score: data.score.present ? data.score.value : this.score, + updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, extraData: data.extraData.present ? data.extraData.value : this.extraData, ); } @override String toString() { - return (StringBuffer('PinnedMessageReactionEntity(') - ..write('userId: $userId, ') - ..write('messageId: $messageId, ') - ..write('type: $type, ') + return (StringBuffer('PollEntity(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('description: $description, ') + ..write('options: $options, ') + ..write('votingVisibility: $votingVisibility, ') + ..write('enforceUniqueVote: $enforceUniqueVote, ') + ..write('maxVotesAllowed: $maxVotesAllowed, ') + ..write('allowUserSuggestedOptions: $allowUserSuggestedOptions, ') + ..write('allowAnswers: $allowAnswers, ') + ..write('isClosed: $isClosed, ') + ..write('answersCount: $answersCount, ') + ..write('voteCountsByOption: $voteCountsByOption, ') + ..write('voteCount: $voteCount, ') + ..write('createdById: $createdById, ') ..write('createdAt: $createdAt, ') - ..write('score: $score, ') + ..write('updatedAt: $updatedAt, ') ..write('extraData: $extraData') ..write(')')) .toString(); } @override - int get hashCode => - Object.hash(userId, messageId, type, createdAt, score, extraData); + int get hashCode => Object.hash( + id, + name, + description, + options, + votingVisibility, + enforceUniqueVote, + maxVotesAllowed, + allowUserSuggestedOptions, + allowAnswers, + isClosed, + answersCount, + voteCountsByOption, + voteCount, + createdById, + createdAt, + updatedAt, + extraData); @override bool operator ==(Object other) => identical(this, other) || - (other is PinnedMessageReactionEntity && - other.userId == this.userId && - other.messageId == this.messageId && - other.type == this.type && + (other is PollEntity && + other.id == this.id && + other.name == this.name && + other.description == this.description && + other.options == this.options && + other.votingVisibility == this.votingVisibility && + other.enforceUniqueVote == this.enforceUniqueVote && + other.maxVotesAllowed == this.maxVotesAllowed && + other.allowUserSuggestedOptions == this.allowUserSuggestedOptions && + other.allowAnswers == this.allowAnswers && + other.isClosed == this.isClosed && + other.answersCount == this.answersCount && + other.voteCountsByOption == this.voteCountsByOption && + other.voteCount == this.voteCount && + other.createdById == this.createdById && other.createdAt == this.createdAt && - other.score == this.score && + other.updatedAt == this.updatedAt && other.extraData == this.extraData); } -class PinnedMessageReactionsCompanion - extends UpdateCompanion { - final Value userId; - final Value messageId; - final Value type; +class PollsCompanion extends UpdateCompanion { + final Value id; + final Value name; + final Value description; + final Value> options; + final Value votingVisibility; + final Value enforceUniqueVote; + final Value maxVotesAllowed; + final Value allowUserSuggestedOptions; + final Value allowAnswers; + final Value isClosed; + final Value answersCount; + final Value> voteCountsByOption; + final Value voteCount; + final Value createdById; final Value createdAt; - final Value score; + final Value updatedAt; final Value?> extraData; final Value rowid; - const PinnedMessageReactionsCompanion({ - this.userId = const Value.absent(), - this.messageId = const Value.absent(), - this.type = const Value.absent(), + const PollsCompanion({ + this.id = const Value.absent(), + this.name = const Value.absent(), + this.description = const Value.absent(), + this.options = const Value.absent(), + this.votingVisibility = const Value.absent(), + this.enforceUniqueVote = const Value.absent(), + this.maxVotesAllowed = const Value.absent(), + this.allowUserSuggestedOptions = const Value.absent(), + this.allowAnswers = const Value.absent(), + this.isClosed = const Value.absent(), + this.answersCount = const Value.absent(), + this.voteCountsByOption = const Value.absent(), + this.voteCount = const Value.absent(), + this.createdById = const Value.absent(), this.createdAt = const Value.absent(), - this.score = const Value.absent(), + this.updatedAt = const Value.absent(), this.extraData = const Value.absent(), this.rowid = const Value.absent(), }); - PinnedMessageReactionsCompanion.insert({ - required String userId, - required String messageId, - required String type, + PollsCompanion.insert({ + required String id, + required String name, + this.description = const Value.absent(), + required List options, + this.votingVisibility = const Value.absent(), + this.enforceUniqueVote = const Value.absent(), + this.maxVotesAllowed = const Value.absent(), + this.allowUserSuggestedOptions = const Value.absent(), + this.allowAnswers = const Value.absent(), + this.isClosed = const Value.absent(), + this.answersCount = const Value.absent(), + required Map voteCountsByOption, + this.voteCount = const Value.absent(), + this.createdById = const Value.absent(), this.createdAt = const Value.absent(), - this.score = const Value.absent(), + this.updatedAt = const Value.absent(), this.extraData = const Value.absent(), this.rowid = const Value.absent(), - }) : userId = Value(userId), - messageId = Value(messageId), - type = Value(type); - static Insertable custom({ - Expression? userId, - Expression? messageId, - Expression? type, + }) : id = Value(id), + name = Value(name), + options = Value(options), + voteCountsByOption = Value(voteCountsByOption); + static Insertable custom({ + Expression? id, + Expression? name, + Expression? description, + Expression? options, + Expression? votingVisibility, + Expression? enforceUniqueVote, + Expression? maxVotesAllowed, + Expression? allowUserSuggestedOptions, + Expression? allowAnswers, + Expression? isClosed, + Expression? answersCount, + Expression? voteCountsByOption, + Expression? voteCount, + Expression? createdById, Expression? createdAt, - Expression? score, + Expression? updatedAt, Expression? extraData, Expression? rowid, }) { return RawValuesInsertable({ - if (userId != null) 'user_id': userId, - if (messageId != null) 'message_id': messageId, - if (type != null) 'type': type, + if (id != null) 'id': id, + if (name != null) 'name': name, + if (description != null) 'description': description, + if (options != null) 'options': options, + if (votingVisibility != null) 'voting_visibility': votingVisibility, + if (enforceUniqueVote != null) 'enforce_unique_vote': enforceUniqueVote, + if (maxVotesAllowed != null) 'max_votes_allowed': maxVotesAllowed, + if (allowUserSuggestedOptions != null) + 'allow_user_suggested_options': allowUserSuggestedOptions, + if (allowAnswers != null) 'allow_answers': allowAnswers, + if (isClosed != null) 'is_closed': isClosed, + if (answersCount != null) 'answers_count': answersCount, + if (voteCountsByOption != null) + 'vote_counts_by_option': voteCountsByOption, + if (voteCount != null) 'vote_count': voteCount, + if (createdById != null) 'created_by_id': createdById, if (createdAt != null) 'created_at': createdAt, - if (score != null) 'score': score, + if (updatedAt != null) 'updated_at': updatedAt, if (extraData != null) 'extra_data': extraData, if (rowid != null) 'rowid': rowid, }); } - PinnedMessageReactionsCompanion copyWith( - {Value? userId, - Value? messageId, - Value? type, + PollsCompanion copyWith( + {Value? id, + Value? name, + Value? description, + Value>? options, + Value? votingVisibility, + Value? enforceUniqueVote, + Value? maxVotesAllowed, + Value? allowUserSuggestedOptions, + Value? allowAnswers, + Value? isClosed, + Value? answersCount, + Value>? voteCountsByOption, + Value? voteCount, + Value? createdById, Value? createdAt, - Value? score, + Value? updatedAt, Value?>? extraData, Value? rowid}) { - return PinnedMessageReactionsCompanion( - userId: userId ?? this.userId, - messageId: messageId ?? this.messageId, - type: type ?? this.type, + return PollsCompanion( + id: id ?? this.id, + name: name ?? this.name, + description: description ?? this.description, + options: options ?? this.options, + votingVisibility: votingVisibility ?? this.votingVisibility, + enforceUniqueVote: enforceUniqueVote ?? this.enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed ?? this.maxVotesAllowed, + allowUserSuggestedOptions: + allowUserSuggestedOptions ?? this.allowUserSuggestedOptions, + allowAnswers: allowAnswers ?? this.allowAnswers, + isClosed: isClosed ?? this.isClosed, + answersCount: answersCount ?? this.answersCount, + voteCountsByOption: voteCountsByOption ?? this.voteCountsByOption, + voteCount: voteCount ?? this.voteCount, + createdById: createdById ?? this.createdById, createdAt: createdAt ?? this.createdAt, - score: score ?? this.score, + updatedAt: updatedAt ?? this.updatedAt, extraData: extraData ?? this.extraData, rowid: rowid ?? this.rowid, ); @@ -3735,25 +4271,62 @@ class PinnedMessageReactionsCompanion @override Map toColumns(bool nullToAbsent) { final map = {}; - if (userId.present) { - map['user_id'] = Variable(userId.value); + if (id.present) { + map['id'] = Variable(id.value); } - if (messageId.present) { - map['message_id'] = Variable(messageId.value); + if (name.present) { + map['name'] = Variable(name.value); } - if (type.present) { - map['type'] = Variable(type.value); + if (description.present) { + map['description'] = Variable(description.value); + } + if (options.present) { + map['options'] = + Variable($PollsTable.$converteroptions.toSql(options.value)); + } + if (votingVisibility.present) { + map['voting_visibility'] = Variable( + $PollsTable.$convertervotingVisibility.toSql(votingVisibility.value)); + } + if (enforceUniqueVote.present) { + map['enforce_unique_vote'] = Variable(enforceUniqueVote.value); + } + if (maxVotesAllowed.present) { + map['max_votes_allowed'] = Variable(maxVotesAllowed.value); + } + if (allowUserSuggestedOptions.present) { + map['allow_user_suggested_options'] = + Variable(allowUserSuggestedOptions.value); + } + if (allowAnswers.present) { + map['allow_answers'] = Variable(allowAnswers.value); + } + if (isClosed.present) { + map['is_closed'] = Variable(isClosed.value); + } + if (answersCount.present) { + map['answers_count'] = Variable(answersCount.value); + } + if (voteCountsByOption.present) { + map['vote_counts_by_option'] = Variable($PollsTable + .$convertervoteCountsByOption + .toSql(voteCountsByOption.value)); + } + if (voteCount.present) { + map['vote_count'] = Variable(voteCount.value); + } + if (createdById.present) { + map['created_by_id'] = Variable(createdById.value); } if (createdAt.present) { map['created_at'] = Variable(createdAt.value); } - if (score.present) { - map['score'] = Variable(score.value); + if (updatedAt.present) { + map['updated_at'] = Variable(updatedAt.value); } if (extraData.present) { - map['extra_data'] = Variable($PinnedMessageReactionsTable - .$converterextraDatan - .toSql(extraData.value)); + map['extra_data'] = Variable( + $PollsTable.$converterextraDatan.toSql(extraData.value)); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -3763,12 +4336,23 @@ class PinnedMessageReactionsCompanion @override String toString() { - return (StringBuffer('PinnedMessageReactionsCompanion(') - ..write('userId: $userId, ') - ..write('messageId: $messageId, ') - ..write('type: $type, ') + return (StringBuffer('PollsCompanion(') + ..write('id: $id, ') + ..write('name: $name, ') + ..write('description: $description, ') + ..write('options: $options, ') + ..write('votingVisibility: $votingVisibility, ') + ..write('enforceUniqueVote: $enforceUniqueVote, ') + ..write('maxVotesAllowed: $maxVotesAllowed, ') + ..write('allowUserSuggestedOptions: $allowUserSuggestedOptions, ') + ..write('allowAnswers: $allowAnswers, ') + ..write('isClosed: $isClosed, ') + ..write('answersCount: $answersCount, ') + ..write('voteCountsByOption: $voteCountsByOption, ') + ..write('voteCount: $voteCount, ') + ..write('createdById: $createdById, ') ..write('createdAt: $createdAt, ') - ..write('score: $score, ') + ..write('updatedAt: $updatedAt, ') ..write('extraData: $extraData, ') ..write('rowid: $rowid') ..write(')')) @@ -3776,31 +4360,37 @@ class PinnedMessageReactionsCompanion } } -class $ReactionsTable extends Reactions - with TableInfo<$ReactionsTable, ReactionEntity> { +class $PollVotesTable extends PollVotes + with TableInfo<$PollVotesTable, PollVoteEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $ReactionsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); + $PollVotesTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override - late final GeneratedColumn userId = GeneratedColumn( - 'user_id', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _messageIdMeta = - const VerificationMeta('messageId'); + late final GeneratedColumn id = GeneratedColumn( + 'id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _pollIdMeta = const VerificationMeta('pollId'); @override - late final GeneratedColumn messageId = GeneratedColumn( - 'message_id', aliasedName, false, + late final GeneratedColumn pollId = GeneratedColumn( + 'poll_id', aliasedName, true, type: DriftSqlType.string, - requiredDuringInsert: true, + requiredDuringInsert: false, defaultConstraints: GeneratedColumn.constraintIsAlways( - 'REFERENCES messages (id) ON DELETE CASCADE')); - static const VerificationMeta _typeMeta = const VerificationMeta('type'); + 'REFERENCES polls (id) ON DELETE CASCADE')); + static const VerificationMeta _optionIdMeta = + const VerificationMeta('optionId'); @override - late final GeneratedColumn type = GeneratedColumn( - 'type', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true); + late final GeneratedColumn optionId = GeneratedColumn( + 'option_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _answerTextMeta = + const VerificationMeta('answerText'); + @override + late final GeneratedColumn answerText = GeneratedColumn( + 'answer_text', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); static const VerificationMeta _createdAtMeta = const VerificationMeta('createdAt'); @override @@ -3809,279 +4399,306 @@ class $ReactionsTable extends Reactions type: DriftSqlType.dateTime, requiredDuringInsert: false, defaultValue: currentDateAndTime); - static const VerificationMeta _scoreMeta = const VerificationMeta('score'); + static const VerificationMeta _updatedAtMeta = + const VerificationMeta('updatedAt'); @override - late final GeneratedColumn score = GeneratedColumn( - 'score', aliasedName, false, - type: DriftSqlType.int, + late final GeneratedColumn updatedAt = GeneratedColumn( + 'updated_at', aliasedName, false, + type: DriftSqlType.dateTime, requiredDuringInsert: false, - defaultValue: const Constant(0)); - static const VerificationMeta _extraDataMeta = - const VerificationMeta('extraData'); + defaultValue: currentDateAndTime); + static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); @override - late final GeneratedColumnWithTypeConverter?, String> - extraData = GeneratedColumn('extra_data', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $ReactionsTable.$converterextraDatan); + late final GeneratedColumn userId = GeneratedColumn( + 'user_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); @override List get $columns => - [userId, messageId, type, createdAt, score, extraData]; + [id, pollId, optionId, answerText, createdAt, updatedAt, userId]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'reactions'; + static const String $name = 'poll_votes'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); - } else if (isInserting) { - context.missing(_userIdMeta); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); } - if (data.containsKey('message_id')) { - context.handle(_messageIdMeta, - messageId.isAcceptableOrUnknown(data['message_id']!, _messageIdMeta)); - } else if (isInserting) { - context.missing(_messageIdMeta); + if (data.containsKey('poll_id')) { + context.handle(_pollIdMeta, + pollId.isAcceptableOrUnknown(data['poll_id']!, _pollIdMeta)); } - if (data.containsKey('type')) { + if (data.containsKey('option_id')) { + context.handle(_optionIdMeta, + optionId.isAcceptableOrUnknown(data['option_id']!, _optionIdMeta)); + } + if (data.containsKey('answer_text')) { context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); - } else if (isInserting) { - context.missing(_typeMeta); + _answerTextMeta, + answerText.isAcceptableOrUnknown( + data['answer_text']!, _answerTextMeta)); } if (data.containsKey('created_at')) { context.handle(_createdAtMeta, createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); } - if (data.containsKey('score')) { - context.handle( - _scoreMeta, score.isAcceptableOrUnknown(data['score']!, _scoreMeta)); + if (data.containsKey('updated_at')) { + context.handle(_updatedAtMeta, + updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); + } + if (data.containsKey('user_id')) { + context.handle(_userIdMeta, + userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); } - context.handle(_extraDataMeta, const VerificationResult.success()); return context; } @override - Set get $primaryKey => {messageId, type, userId}; + Set get $primaryKey => {id, pollId}; @override - ReactionEntity map(Map data, {String? tablePrefix}) { + PollVoteEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return ReactionEntity( - userId: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, - messageId: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}message_id'])!, - type: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}type'])!, + return PollVoteEntity( + id: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}id']), + pollId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}poll_id']), + optionId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}option_id']), + answerText: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}answer_text']), createdAt: attachedDatabase.typeMapping .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, - score: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}score'])!, - extraData: $ReactionsTable.$converterextraDatan.fromSql(attachedDatabase - .typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])), + updatedAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at'])!, + userId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}user_id']), ); } @override - $ReactionsTable createAlias(String alias) { - return $ReactionsTable(attachedDatabase, alias); + $PollVotesTable createAlias(String alias) { + return $PollVotesTable(attachedDatabase, alias); } - - static TypeConverter, String> $converterextraData = - MapConverter(); - static TypeConverter?, String?> $converterextraDatan = - NullAwareTypeConverter.wrap($converterextraData); } -class ReactionEntity extends DataClass implements Insertable { - /// The id of the user that sent the reaction - final String userId; +class PollVoteEntity extends DataClass implements Insertable { + /// The unique identifier of the poll vote. + final String? id; - /// The messageId to which the reaction belongs - final String messageId; + /// The unique identifier of the poll the vote belongs to. + final String? pollId; - /// The type of the reaction - final String type; + /// The unique identifier of the option selected in the poll. + /// + /// Nullable if the user provided an answer. + final String? optionId; - /// The DateTime on which the reaction is created + /// The text of the answer provided in the poll. + /// + /// Nullable if the user selected an option. + final String? answerText; + + /// The date when the poll vote was created. final DateTime createdAt; - /// The score of the reaction (ie. number of reactions sent) - final int score; + /// The date when the poll vote was last updated. + final DateTime updatedAt; - /// Reaction custom extraData - final Map? extraData; - const ReactionEntity( - {required this.userId, - required this.messageId, - required this.type, + /// The unique identifier of the user who voted. + /// + /// Nullable if the poll is anonymous. + final String? userId; + const PollVoteEntity( + {this.id, + this.pollId, + this.optionId, + this.answerText, required this.createdAt, - required this.score, - this.extraData}); + required this.updatedAt, + this.userId}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['user_id'] = Variable(userId); - map['message_id'] = Variable(messageId); - map['type'] = Variable(type); - map['created_at'] = Variable(createdAt); - map['score'] = Variable(score); - if (!nullToAbsent || extraData != null) { - map['extra_data'] = Variable( - $ReactionsTable.$converterextraDatan.toSql(extraData)); + if (!nullToAbsent || id != null) { + map['id'] = Variable(id); } - return map; - } - - factory ReactionEntity.fromJson(Map json, + if (!nullToAbsent || pollId != null) { + map['poll_id'] = Variable(pollId); + } + if (!nullToAbsent || optionId != null) { + map['option_id'] = Variable(optionId); + } + if (!nullToAbsent || answerText != null) { + map['answer_text'] = Variable(answerText); + } + map['created_at'] = Variable(createdAt); + map['updated_at'] = Variable(updatedAt); + if (!nullToAbsent || userId != null) { + map['user_id'] = Variable(userId); + } + return map; + } + + factory PollVoteEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return ReactionEntity( - userId: serializer.fromJson(json['userId']), - messageId: serializer.fromJson(json['messageId']), - type: serializer.fromJson(json['type']), + return PollVoteEntity( + id: serializer.fromJson(json['id']), + pollId: serializer.fromJson(json['pollId']), + optionId: serializer.fromJson(json['optionId']), + answerText: serializer.fromJson(json['answerText']), createdAt: serializer.fromJson(json['createdAt']), - score: serializer.fromJson(json['score']), - extraData: serializer.fromJson?>(json['extraData']), + updatedAt: serializer.fromJson(json['updatedAt']), + userId: serializer.fromJson(json['userId']), ); } @override Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'userId': serializer.toJson(userId), - 'messageId': serializer.toJson(messageId), - 'type': serializer.toJson(type), + 'id': serializer.toJson(id), + 'pollId': serializer.toJson(pollId), + 'optionId': serializer.toJson(optionId), + 'answerText': serializer.toJson(answerText), 'createdAt': serializer.toJson(createdAt), - 'score': serializer.toJson(score), - 'extraData': serializer.toJson?>(extraData), + 'updatedAt': serializer.toJson(updatedAt), + 'userId': serializer.toJson(userId), }; } - ReactionEntity copyWith( - {String? userId, - String? messageId, - String? type, + PollVoteEntity copyWith( + {Value id = const Value.absent(), + Value pollId = const Value.absent(), + Value optionId = const Value.absent(), + Value answerText = const Value.absent(), DateTime? createdAt, - int? score, - Value?> extraData = const Value.absent()}) => - ReactionEntity( - userId: userId ?? this.userId, - messageId: messageId ?? this.messageId, - type: type ?? this.type, + DateTime? updatedAt, + Value userId = const Value.absent()}) => + PollVoteEntity( + id: id.present ? id.value : this.id, + pollId: pollId.present ? pollId.value : this.pollId, + optionId: optionId.present ? optionId.value : this.optionId, + answerText: answerText.present ? answerText.value : this.answerText, createdAt: createdAt ?? this.createdAt, - score: score ?? this.score, - extraData: extraData.present ? extraData.value : this.extraData, + updatedAt: updatedAt ?? this.updatedAt, + userId: userId.present ? userId.value : this.userId, ); - ReactionEntity copyWithCompanion(ReactionsCompanion data) { - return ReactionEntity( - userId: data.userId.present ? data.userId.value : this.userId, - messageId: data.messageId.present ? data.messageId.value : this.messageId, - type: data.type.present ? data.type.value : this.type, + PollVoteEntity copyWithCompanion(PollVotesCompanion data) { + return PollVoteEntity( + id: data.id.present ? data.id.value : this.id, + pollId: data.pollId.present ? data.pollId.value : this.pollId, + optionId: data.optionId.present ? data.optionId.value : this.optionId, + answerText: + data.answerText.present ? data.answerText.value : this.answerText, createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, - score: data.score.present ? data.score.value : this.score, - extraData: data.extraData.present ? data.extraData.value : this.extraData, + updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, + userId: data.userId.present ? data.userId.value : this.userId, ); } @override String toString() { - return (StringBuffer('ReactionEntity(') - ..write('userId: $userId, ') - ..write('messageId: $messageId, ') - ..write('type: $type, ') + return (StringBuffer('PollVoteEntity(') + ..write('id: $id, ') + ..write('pollId: $pollId, ') + ..write('optionId: $optionId, ') + ..write('answerText: $answerText, ') ..write('createdAt: $createdAt, ') - ..write('score: $score, ') - ..write('extraData: $extraData') + ..write('updatedAt: $updatedAt, ') + ..write('userId: $userId') ..write(')')) .toString(); } @override - int get hashCode => - Object.hash(userId, messageId, type, createdAt, score, extraData); + int get hashCode => Object.hash( + id, pollId, optionId, answerText, createdAt, updatedAt, userId); @override bool operator ==(Object other) => identical(this, other) || - (other is ReactionEntity && - other.userId == this.userId && - other.messageId == this.messageId && - other.type == this.type && + (other is PollVoteEntity && + other.id == this.id && + other.pollId == this.pollId && + other.optionId == this.optionId && + other.answerText == this.answerText && other.createdAt == this.createdAt && - other.score == this.score && - other.extraData == this.extraData); + other.updatedAt == this.updatedAt && + other.userId == this.userId); } -class ReactionsCompanion extends UpdateCompanion { - final Value userId; - final Value messageId; - final Value type; +class PollVotesCompanion extends UpdateCompanion { + final Value id; + final Value pollId; + final Value optionId; + final Value answerText; final Value createdAt; - final Value score; - final Value?> extraData; + final Value updatedAt; + final Value userId; final Value rowid; - const ReactionsCompanion({ - this.userId = const Value.absent(), - this.messageId = const Value.absent(), - this.type = const Value.absent(), + const PollVotesCompanion({ + this.id = const Value.absent(), + this.pollId = const Value.absent(), + this.optionId = const Value.absent(), + this.answerText = const Value.absent(), this.createdAt = const Value.absent(), - this.score = const Value.absent(), - this.extraData = const Value.absent(), + this.updatedAt = const Value.absent(), + this.userId = const Value.absent(), this.rowid = const Value.absent(), }); - ReactionsCompanion.insert({ - required String userId, - required String messageId, - required String type, + PollVotesCompanion.insert({ + this.id = const Value.absent(), + this.pollId = const Value.absent(), + this.optionId = const Value.absent(), + this.answerText = const Value.absent(), this.createdAt = const Value.absent(), - this.score = const Value.absent(), - this.extraData = const Value.absent(), + this.updatedAt = const Value.absent(), + this.userId = const Value.absent(), this.rowid = const Value.absent(), - }) : userId = Value(userId), - messageId = Value(messageId), - type = Value(type); - static Insertable custom({ - Expression? userId, - Expression? messageId, - Expression? type, + }); + static Insertable custom({ + Expression? id, + Expression? pollId, + Expression? optionId, + Expression? answerText, Expression? createdAt, - Expression? score, - Expression? extraData, + Expression? updatedAt, + Expression? userId, Expression? rowid, }) { return RawValuesInsertable({ - if (userId != null) 'user_id': userId, - if (messageId != null) 'message_id': messageId, - if (type != null) 'type': type, + if (id != null) 'id': id, + if (pollId != null) 'poll_id': pollId, + if (optionId != null) 'option_id': optionId, + if (answerText != null) 'answer_text': answerText, if (createdAt != null) 'created_at': createdAt, - if (score != null) 'score': score, - if (extraData != null) 'extra_data': extraData, + if (updatedAt != null) 'updated_at': updatedAt, + if (userId != null) 'user_id': userId, if (rowid != null) 'rowid': rowid, }); } - ReactionsCompanion copyWith( - {Value? userId, - Value? messageId, - Value? type, + PollVotesCompanion copyWith( + {Value? id, + Value? pollId, + Value? optionId, + Value? answerText, Value? createdAt, - Value? score, - Value?>? extraData, + Value? updatedAt, + Value? userId, Value? rowid}) { - return ReactionsCompanion( - userId: userId ?? this.userId, - messageId: messageId ?? this.messageId, - type: type ?? this.type, + return PollVotesCompanion( + id: id ?? this.id, + pollId: pollId ?? this.pollId, + optionId: optionId ?? this.optionId, + answerText: answerText ?? this.answerText, createdAt: createdAt ?? this.createdAt, - score: score ?? this.score, - extraData: extraData ?? this.extraData, + updatedAt: updatedAt ?? this.updatedAt, + userId: userId ?? this.userId, rowid: rowid ?? this.rowid, ); } @@ -4089,24 +4706,26 @@ class ReactionsCompanion extends UpdateCompanion { @override Map toColumns(bool nullToAbsent) { final map = {}; - if (userId.present) { - map['user_id'] = Variable(userId.value); + if (id.present) { + map['id'] = Variable(id.value); } - if (messageId.present) { - map['message_id'] = Variable(messageId.value); + if (pollId.present) { + map['poll_id'] = Variable(pollId.value); } - if (type.present) { - map['type'] = Variable(type.value); + if (optionId.present) { + map['option_id'] = Variable(optionId.value); + } + if (answerText.present) { + map['answer_text'] = Variable(answerText.value); } if (createdAt.present) { map['created_at'] = Variable(createdAt.value); } - if (score.present) { - map['score'] = Variable(score.value); + if (updatedAt.present) { + map['updated_at'] = Variable(updatedAt.value); } - if (extraData.present) { - map['extra_data'] = Variable( - $ReactionsTable.$converterextraDatan.toSql(extraData.value)); + if (userId.present) { + map['user_id'] = Variable(userId.value); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -4116,429 +4735,330 @@ class ReactionsCompanion extends UpdateCompanion { @override String toString() { - return (StringBuffer('ReactionsCompanion(') - ..write('userId: $userId, ') - ..write('messageId: $messageId, ') - ..write('type: $type, ') + return (StringBuffer('PollVotesCompanion(') + ..write('id: $id, ') + ..write('pollId: $pollId, ') + ..write('optionId: $optionId, ') + ..write('answerText: $answerText, ') ..write('createdAt: $createdAt, ') - ..write('score: $score, ') - ..write('extraData: $extraData, ') + ..write('updatedAt: $updatedAt, ') + ..write('userId: $userId, ') ..write('rowid: $rowid') ..write(')')) .toString(); } } -class $UsersTable extends Users with TableInfo<$UsersTable, UserEntity> { +class $PinnedMessageReactionsTable extends PinnedMessageReactions + with TableInfo<$PinnedMessageReactionsTable, PinnedMessageReactionEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $UsersTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); + $PinnedMessageReactionsTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); @override - late final GeneratedColumn id = GeneratedColumn( - 'id', aliasedName, false, + late final GeneratedColumn userId = GeneratedColumn( + 'user_id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _roleMeta = const VerificationMeta('role'); + static const VerificationMeta _messageIdMeta = + const VerificationMeta('messageId'); @override - late final GeneratedColumn role = GeneratedColumn( - 'role', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false); - static const VerificationMeta _languageMeta = - const VerificationMeta('language'); + late final GeneratedColumn messageId = GeneratedColumn( + 'message_id', aliasedName, false, + type: DriftSqlType.string, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES pinned_messages (id) ON DELETE CASCADE')); + static const VerificationMeta _typeMeta = const VerificationMeta('type'); @override - late final GeneratedColumn language = GeneratedColumn( - 'language', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false); + late final GeneratedColumn type = GeneratedColumn( + 'type', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _createdAtMeta = const VerificationMeta('createdAt'); @override late final GeneratedColumn createdAt = GeneratedColumn( - 'created_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _updatedAtMeta = - const VerificationMeta('updatedAt'); - @override - late final GeneratedColumn updatedAt = GeneratedColumn( - 'updated_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _lastActiveMeta = - const VerificationMeta('lastActive'); - @override - late final GeneratedColumn lastActive = GeneratedColumn( - 'last_active', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _onlineMeta = const VerificationMeta('online'); - @override - late final GeneratedColumn online = GeneratedColumn( - 'online', aliasedName, false, - type: DriftSqlType.bool, + 'created_at', aliasedName, false, + type: DriftSqlType.dateTime, requiredDuringInsert: false, - defaultConstraints: - GeneratedColumn.constraintIsAlways('CHECK ("online" IN (0, 1))'), - defaultValue: const Constant(false)); - static const VerificationMeta _bannedMeta = const VerificationMeta('banned'); + defaultValue: currentDateAndTime); + static const VerificationMeta _scoreMeta = const VerificationMeta('score'); @override - late final GeneratedColumn banned = GeneratedColumn( - 'banned', aliasedName, false, - type: DriftSqlType.bool, + late final GeneratedColumn score = GeneratedColumn( + 'score', aliasedName, false, + type: DriftSqlType.int, requiredDuringInsert: false, - defaultConstraints: - GeneratedColumn.constraintIsAlways('CHECK ("banned" IN (0, 1))'), - defaultValue: const Constant(false)); + defaultValue: const Constant(0)); static const VerificationMeta _extraDataMeta = const VerificationMeta('extraData'); @override - late final GeneratedColumnWithTypeConverter, String> - extraData = GeneratedColumn('extra_data', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true) - .withConverter>($UsersTable.$converterextraData); + late final GeneratedColumnWithTypeConverter?, String> + extraData = GeneratedColumn('extra_data', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false) + .withConverter?>( + $PinnedMessageReactionsTable.$converterextraDatan); @override - List get $columns => [ - id, - role, - language, - createdAt, - updatedAt, - lastActive, - online, - banned, - extraData - ]; + List get $columns => + [userId, messageId, type, createdAt, score, extraData]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'users'; + static const String $name = 'pinned_message_reactions'; @override - VerificationContext validateIntegrity(Insertable instance, - {bool isInserting = false}) { + VerificationContext validateIntegrity( + Insertable instance, + {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + if (data.containsKey('user_id')) { + context.handle(_userIdMeta, + userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); } else if (isInserting) { - context.missing(_idMeta); + context.missing(_userIdMeta); } - if (data.containsKey('role')) { - context.handle( - _roleMeta, role.isAcceptableOrUnknown(data['role']!, _roleMeta)); + if (data.containsKey('message_id')) { + context.handle(_messageIdMeta, + messageId.isAcceptableOrUnknown(data['message_id']!, _messageIdMeta)); + } else if (isInserting) { + context.missing(_messageIdMeta); } - if (data.containsKey('language')) { - context.handle(_languageMeta, - language.isAcceptableOrUnknown(data['language']!, _languageMeta)); + if (data.containsKey('type')) { + context.handle( + _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); + } else if (isInserting) { + context.missing(_typeMeta); } if (data.containsKey('created_at')) { context.handle(_createdAtMeta, createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); } - if (data.containsKey('updated_at')) { - context.handle(_updatedAtMeta, - updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); - } - if (data.containsKey('last_active')) { + if (data.containsKey('score')) { context.handle( - _lastActiveMeta, - lastActive.isAcceptableOrUnknown( - data['last_active']!, _lastActiveMeta)); - } - if (data.containsKey('online')) { - context.handle(_onlineMeta, - online.isAcceptableOrUnknown(data['online']!, _onlineMeta)); - } - if (data.containsKey('banned')) { - context.handle(_bannedMeta, - banned.isAcceptableOrUnknown(data['banned']!, _bannedMeta)); + _scoreMeta, score.isAcceptableOrUnknown(data['score']!, _scoreMeta)); } context.handle(_extraDataMeta, const VerificationResult.success()); return context; } @override - Set get $primaryKey => {id}; + Set get $primaryKey => {messageId, type, userId}; @override - UserEntity map(Map data, {String? tablePrefix}) { + PinnedMessageReactionEntity map(Map data, + {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return UserEntity( - id: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}id'])!, - role: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}role']), - language: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}language']), + return PinnedMessageReactionEntity( + userId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, + messageId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}message_id'])!, + type: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}type'])!, createdAt: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at']), - updatedAt: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at']), - lastActive: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}last_active']), - online: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}online'])!, - banned: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}banned'])!, - extraData: $UsersTable.$converterextraData.fromSql(attachedDatabase - .typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])!), + .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, + score: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}score'])!, + extraData: $PinnedMessageReactionsTable.$converterextraDatan.fromSql( + attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])), ); } @override - $UsersTable createAlias(String alias) { - return $UsersTable(attachedDatabase, alias); + $PinnedMessageReactionsTable createAlias(String alias) { + return $PinnedMessageReactionsTable(attachedDatabase, alias); } static TypeConverter, String> $converterextraData = MapConverter(); + static TypeConverter?, String?> $converterextraDatan = + NullAwareTypeConverter.wrap($converterextraData); } -class UserEntity extends DataClass implements Insertable { - /// User id - final String id; - - /// User role - final String? role; - - /// The language this user prefers. - final String? language; - - /// Date of user creation - final DateTime? createdAt; +class PinnedMessageReactionEntity extends DataClass + implements Insertable { + /// The id of the user that sent the reaction + final String userId; - /// Date of last user update - final DateTime? updatedAt; + /// The messageId to which the reaction belongs + final String messageId; - /// Date of last user connection - final DateTime? lastActive; + /// The type of the reaction + final String type; - /// True if user is online - final bool online; + /// The DateTime on which the reaction is created + final DateTime createdAt; - /// True if user is banned from the chat - final bool banned; + /// The score of the reaction (ie. number of reactions sent) + final int score; - /// Map of custom user extraData - final Map extraData; - const UserEntity( - {required this.id, - this.role, - this.language, - this.createdAt, - this.updatedAt, - this.lastActive, - required this.online, - required this.banned, - required this.extraData}); + /// Reaction custom extraData + final Map? extraData; + const PinnedMessageReactionEntity( + {required this.userId, + required this.messageId, + required this.type, + required this.createdAt, + required this.score, + this.extraData}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['id'] = Variable(id); - if (!nullToAbsent || role != null) { - map['role'] = Variable(role); - } - if (!nullToAbsent || language != null) { - map['language'] = Variable(language); - } - if (!nullToAbsent || createdAt != null) { - map['created_at'] = Variable(createdAt); - } - if (!nullToAbsent || updatedAt != null) { - map['updated_at'] = Variable(updatedAt); - } - if (!nullToAbsent || lastActive != null) { - map['last_active'] = Variable(lastActive); - } - map['online'] = Variable(online); - map['banned'] = Variable(banned); - { - map['extra_data'] = - Variable($UsersTable.$converterextraData.toSql(extraData)); + map['user_id'] = Variable(userId); + map['message_id'] = Variable(messageId); + map['type'] = Variable(type); + map['created_at'] = Variable(createdAt); + map['score'] = Variable(score); + if (!nullToAbsent || extraData != null) { + map['extra_data'] = Variable( + $PinnedMessageReactionsTable.$converterextraDatan.toSql(extraData)); } return map; } - factory UserEntity.fromJson(Map json, + factory PinnedMessageReactionEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return UserEntity( - id: serializer.fromJson(json['id']), - role: serializer.fromJson(json['role']), - language: serializer.fromJson(json['language']), - createdAt: serializer.fromJson(json['createdAt']), - updatedAt: serializer.fromJson(json['updatedAt']), - lastActive: serializer.fromJson(json['lastActive']), - online: serializer.fromJson(json['online']), - banned: serializer.fromJson(json['banned']), - extraData: serializer.fromJson>(json['extraData']), + return PinnedMessageReactionEntity( + userId: serializer.fromJson(json['userId']), + messageId: serializer.fromJson(json['messageId']), + type: serializer.fromJson(json['type']), + createdAt: serializer.fromJson(json['createdAt']), + score: serializer.fromJson(json['score']), + extraData: serializer.fromJson?>(json['extraData']), ); } @override Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'id': serializer.toJson(id), - 'role': serializer.toJson(role), - 'language': serializer.toJson(language), - 'createdAt': serializer.toJson(createdAt), - 'updatedAt': serializer.toJson(updatedAt), - 'lastActive': serializer.toJson(lastActive), - 'online': serializer.toJson(online), - 'banned': serializer.toJson(banned), - 'extraData': serializer.toJson>(extraData), + 'userId': serializer.toJson(userId), + 'messageId': serializer.toJson(messageId), + 'type': serializer.toJson(type), + 'createdAt': serializer.toJson(createdAt), + 'score': serializer.toJson(score), + 'extraData': serializer.toJson?>(extraData), }; } - UserEntity copyWith( - {String? id, - Value role = const Value.absent(), - Value language = const Value.absent(), - Value createdAt = const Value.absent(), - Value updatedAt = const Value.absent(), - Value lastActive = const Value.absent(), - bool? online, - bool? banned, - Map? extraData}) => - UserEntity( - id: id ?? this.id, - role: role.present ? role.value : this.role, - language: language.present ? language.value : this.language, - createdAt: createdAt.present ? createdAt.value : this.createdAt, - updatedAt: updatedAt.present ? updatedAt.value : this.updatedAt, - lastActive: lastActive.present ? lastActive.value : this.lastActive, - online: online ?? this.online, - banned: banned ?? this.banned, - extraData: extraData ?? this.extraData, + PinnedMessageReactionEntity copyWith( + {String? userId, + String? messageId, + String? type, + DateTime? createdAt, + int? score, + Value?> extraData = const Value.absent()}) => + PinnedMessageReactionEntity( + userId: userId ?? this.userId, + messageId: messageId ?? this.messageId, + type: type ?? this.type, + createdAt: createdAt ?? this.createdAt, + score: score ?? this.score, + extraData: extraData.present ? extraData.value : this.extraData, ); - UserEntity copyWithCompanion(UsersCompanion data) { - return UserEntity( - id: data.id.present ? data.id.value : this.id, - role: data.role.present ? data.role.value : this.role, - language: data.language.present ? data.language.value : this.language, + PinnedMessageReactionEntity copyWithCompanion( + PinnedMessageReactionsCompanion data) { + return PinnedMessageReactionEntity( + userId: data.userId.present ? data.userId.value : this.userId, + messageId: data.messageId.present ? data.messageId.value : this.messageId, + type: data.type.present ? data.type.value : this.type, createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, - updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, - lastActive: - data.lastActive.present ? data.lastActive.value : this.lastActive, - online: data.online.present ? data.online.value : this.online, - banned: data.banned.present ? data.banned.value : this.banned, + score: data.score.present ? data.score.value : this.score, extraData: data.extraData.present ? data.extraData.value : this.extraData, ); } @override String toString() { - return (StringBuffer('UserEntity(') - ..write('id: $id, ') - ..write('role: $role, ') - ..write('language: $language, ') + return (StringBuffer('PinnedMessageReactionEntity(') + ..write('userId: $userId, ') + ..write('messageId: $messageId, ') + ..write('type: $type, ') ..write('createdAt: $createdAt, ') - ..write('updatedAt: $updatedAt, ') - ..write('lastActive: $lastActive, ') - ..write('online: $online, ') - ..write('banned: $banned, ') + ..write('score: $score, ') ..write('extraData: $extraData') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(id, role, language, createdAt, updatedAt, - lastActive, online, banned, extraData); + int get hashCode => + Object.hash(userId, messageId, type, createdAt, score, extraData); @override bool operator ==(Object other) => identical(this, other) || - (other is UserEntity && - other.id == this.id && - other.role == this.role && - other.language == this.language && + (other is PinnedMessageReactionEntity && + other.userId == this.userId && + other.messageId == this.messageId && + other.type == this.type && other.createdAt == this.createdAt && - other.updatedAt == this.updatedAt && - other.lastActive == this.lastActive && - other.online == this.online && - other.banned == this.banned && + other.score == this.score && other.extraData == this.extraData); } -class UsersCompanion extends UpdateCompanion { - final Value id; - final Value role; - final Value language; - final Value createdAt; - final Value updatedAt; - final Value lastActive; - final Value online; - final Value banned; - final Value> extraData; +class PinnedMessageReactionsCompanion + extends UpdateCompanion { + final Value userId; + final Value messageId; + final Value type; + final Value createdAt; + final Value score; + final Value?> extraData; final Value rowid; - const UsersCompanion({ - this.id = const Value.absent(), - this.role = const Value.absent(), - this.language = const Value.absent(), + const PinnedMessageReactionsCompanion({ + this.userId = const Value.absent(), + this.messageId = const Value.absent(), + this.type = const Value.absent(), this.createdAt = const Value.absent(), - this.updatedAt = const Value.absent(), - this.lastActive = const Value.absent(), - this.online = const Value.absent(), - this.banned = const Value.absent(), + this.score = const Value.absent(), this.extraData = const Value.absent(), this.rowid = const Value.absent(), }); - UsersCompanion.insert({ - required String id, - this.role = const Value.absent(), - this.language = const Value.absent(), + PinnedMessageReactionsCompanion.insert({ + required String userId, + required String messageId, + required String type, this.createdAt = const Value.absent(), - this.updatedAt = const Value.absent(), - this.lastActive = const Value.absent(), - this.online = const Value.absent(), - this.banned = const Value.absent(), - required Map extraData, + this.score = const Value.absent(), + this.extraData = const Value.absent(), this.rowid = const Value.absent(), - }) : id = Value(id), - extraData = Value(extraData); - static Insertable custom({ - Expression? id, - Expression? role, - Expression? language, + }) : userId = Value(userId), + messageId = Value(messageId), + type = Value(type); + static Insertable custom({ + Expression? userId, + Expression? messageId, + Expression? type, Expression? createdAt, - Expression? updatedAt, - Expression? lastActive, - Expression? online, - Expression? banned, + Expression? score, Expression? extraData, Expression? rowid, }) { return RawValuesInsertable({ - if (id != null) 'id': id, - if (role != null) 'role': role, - if (language != null) 'language': language, + if (userId != null) 'user_id': userId, + if (messageId != null) 'message_id': messageId, + if (type != null) 'type': type, if (createdAt != null) 'created_at': createdAt, - if (updatedAt != null) 'updated_at': updatedAt, - if (lastActive != null) 'last_active': lastActive, - if (online != null) 'online': online, - if (banned != null) 'banned': banned, + if (score != null) 'score': score, if (extraData != null) 'extra_data': extraData, if (rowid != null) 'rowid': rowid, }); } - UsersCompanion copyWith( - {Value? id, - Value? role, - Value? language, - Value? createdAt, - Value? updatedAt, - Value? lastActive, - Value? online, - Value? banned, - Value>? extraData, + PinnedMessageReactionsCompanion copyWith( + {Value? userId, + Value? messageId, + Value? type, + Value? createdAt, + Value? score, + Value?>? extraData, Value? rowid}) { - return UsersCompanion( - id: id ?? this.id, - role: role ?? this.role, - language: language ?? this.language, + return PinnedMessageReactionsCompanion( + userId: userId ?? this.userId, + messageId: messageId ?? this.messageId, + type: type ?? this.type, createdAt: createdAt ?? this.createdAt, - updatedAt: updatedAt ?? this.updatedAt, - lastActive: lastActive ?? this.lastActive, - online: online ?? this.online, - banned: banned ?? this.banned, + score: score ?? this.score, extraData: extraData ?? this.extraData, rowid: rowid ?? this.rowid, ); @@ -4547,33 +5067,25 @@ class UsersCompanion extends UpdateCompanion { @override Map toColumns(bool nullToAbsent) { final map = {}; - if (id.present) { - map['id'] = Variable(id.value); + if (userId.present) { + map['user_id'] = Variable(userId.value); } - if (role.present) { - map['role'] = Variable(role.value); + if (messageId.present) { + map['message_id'] = Variable(messageId.value); } - if (language.present) { - map['language'] = Variable(language.value); + if (type.present) { + map['type'] = Variable(type.value); } if (createdAt.present) { map['created_at'] = Variable(createdAt.value); } - if (updatedAt.present) { - map['updated_at'] = Variable(updatedAt.value); - } - if (lastActive.present) { - map['last_active'] = Variable(lastActive.value); - } - if (online.present) { - map['online'] = Variable(online.value); - } - if (banned.present) { - map['banned'] = Variable(banned.value); + if (score.present) { + map['score'] = Variable(score.value); } if (extraData.present) { - map['extra_data'] = Variable( - $UsersTable.$converterextraData.toSql(extraData.value)); + map['extra_data'] = Variable($PinnedMessageReactionsTable + .$converterextraDatan + .toSql(extraData.value)); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -4583,15 +5095,12 @@ class UsersCompanion extends UpdateCompanion { @override String toString() { - return (StringBuffer('UsersCompanion(') - ..write('id: $id, ') - ..write('role: $role, ') - ..write('language: $language, ') + return (StringBuffer('PinnedMessageReactionsCompanion(') + ..write('userId: $userId, ') + ..write('messageId: $messageId, ') + ..write('type: $type, ') ..write('createdAt: $createdAt, ') - ..write('updatedAt: $updatedAt, ') - ..write('lastActive: $lastActive, ') - ..write('online: $online, ') - ..write('banned: $banned, ') + ..write('score: $score, ') ..write('extraData: $extraData, ') ..write('rowid: $rowid') ..write(')')) @@ -4599,83 +5108,31 @@ class UsersCompanion extends UpdateCompanion { } } -class $MembersTable extends Members - with TableInfo<$MembersTable, MemberEntity> { +class $ReactionsTable extends Reactions + with TableInfo<$ReactionsTable, ReactionEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $MembersTable(this.attachedDatabase, [this._alias]); + $ReactionsTable(this.attachedDatabase, [this._alias]); static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); @override late final GeneratedColumn userId = GeneratedColumn( 'user_id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _channelCidMeta = - const VerificationMeta('channelCid'); + static const VerificationMeta _messageIdMeta = + const VerificationMeta('messageId'); @override - late final GeneratedColumn channelCid = GeneratedColumn( - 'channel_cid', aliasedName, false, + late final GeneratedColumn messageId = GeneratedColumn( + 'message_id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true, defaultConstraints: GeneratedColumn.constraintIsAlways( - 'REFERENCES channels (cid) ON DELETE CASCADE')); - static const VerificationMeta _channelRoleMeta = - const VerificationMeta('channelRole'); - @override - late final GeneratedColumn channelRole = GeneratedColumn( - 'channel_role', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false); - static const VerificationMeta _inviteAcceptedAtMeta = - const VerificationMeta('inviteAcceptedAt'); - @override - late final GeneratedColumn inviteAcceptedAt = - GeneratedColumn('invite_accepted_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _inviteRejectedAtMeta = - const VerificationMeta('inviteRejectedAt'); - @override - late final GeneratedColumn inviteRejectedAt = - GeneratedColumn('invite_rejected_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _invitedMeta = - const VerificationMeta('invited'); - @override - late final GeneratedColumn invited = GeneratedColumn( - 'invited', aliasedName, false, - type: DriftSqlType.bool, - requiredDuringInsert: false, - defaultConstraints: - GeneratedColumn.constraintIsAlways('CHECK ("invited" IN (0, 1))'), - defaultValue: const Constant(false)); - static const VerificationMeta _bannedMeta = const VerificationMeta('banned'); - @override - late final GeneratedColumn banned = GeneratedColumn( - 'banned', aliasedName, false, - type: DriftSqlType.bool, - requiredDuringInsert: false, - defaultConstraints: - GeneratedColumn.constraintIsAlways('CHECK ("banned" IN (0, 1))'), - defaultValue: const Constant(false)); - static const VerificationMeta _shadowBannedMeta = - const VerificationMeta('shadowBanned'); - @override - late final GeneratedColumn shadowBanned = GeneratedColumn( - 'shadow_banned', aliasedName, false, - type: DriftSqlType.bool, - requiredDuringInsert: false, - defaultConstraints: GeneratedColumn.constraintIsAlways( - 'CHECK ("shadow_banned" IN (0, 1))'), - defaultValue: const Constant(false)); - static const VerificationMeta _isModeratorMeta = - const VerificationMeta('isModerator'); + 'REFERENCES messages (id) ON DELETE CASCADE')); + static const VerificationMeta _typeMeta = const VerificationMeta('type'); @override - late final GeneratedColumn isModerator = GeneratedColumn( - 'is_moderator', aliasedName, false, - type: DriftSqlType.bool, - requiredDuringInsert: false, - defaultConstraints: GeneratedColumn.constraintIsAlways( - 'CHECK ("is_moderator" IN (0, 1))'), - defaultValue: const Constant(false)); + late final GeneratedColumn type = GeneratedColumn( + 'type', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _createdAtMeta = const VerificationMeta('createdAt'); @override @@ -4684,35 +5141,31 @@ class $MembersTable extends Members type: DriftSqlType.dateTime, requiredDuringInsert: false, defaultValue: currentDateAndTime); - static const VerificationMeta _updatedAtMeta = - const VerificationMeta('updatedAt'); + static const VerificationMeta _scoreMeta = const VerificationMeta('score'); @override - late final GeneratedColumn updatedAt = GeneratedColumn( - 'updated_at', aliasedName, false, - type: DriftSqlType.dateTime, + late final GeneratedColumn score = GeneratedColumn( + 'score', aliasedName, false, + type: DriftSqlType.int, requiredDuringInsert: false, - defaultValue: currentDateAndTime); + defaultValue: const Constant(0)); + static const VerificationMeta _extraDataMeta = + const VerificationMeta('extraData'); @override - List get $columns => [ - userId, - channelCid, - channelRole, - inviteAcceptedAt, - inviteRejectedAt, - invited, - banned, - shadowBanned, - isModerator, - createdAt, - updatedAt - ]; + late final GeneratedColumnWithTypeConverter?, String> + extraData = GeneratedColumn('extra_data', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false) + .withConverter?>( + $ReactionsTable.$converterextraDatan); + @override + List get $columns => + [userId, messageId, type, createdAt, score, extraData]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'members'; + static const String $name = 'reactions'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); @@ -4722,185 +5175,113 @@ class $MembersTable extends Members } else if (isInserting) { context.missing(_userIdMeta); } - if (data.containsKey('channel_cid')) { - context.handle( - _channelCidMeta, - channelCid.isAcceptableOrUnknown( - data['channel_cid']!, _channelCidMeta)); + if (data.containsKey('message_id')) { + context.handle(_messageIdMeta, + messageId.isAcceptableOrUnknown(data['message_id']!, _messageIdMeta)); } else if (isInserting) { - context.missing(_channelCidMeta); - } - if (data.containsKey('channel_role')) { - context.handle( - _channelRoleMeta, - channelRole.isAcceptableOrUnknown( - data['channel_role']!, _channelRoleMeta)); - } - if (data.containsKey('invite_accepted_at')) { - context.handle( - _inviteAcceptedAtMeta, - inviteAcceptedAt.isAcceptableOrUnknown( - data['invite_accepted_at']!, _inviteAcceptedAtMeta)); - } - if (data.containsKey('invite_rejected_at')) { - context.handle( - _inviteRejectedAtMeta, - inviteRejectedAt.isAcceptableOrUnknown( - data['invite_rejected_at']!, _inviteRejectedAtMeta)); - } - if (data.containsKey('invited')) { - context.handle(_invitedMeta, - invited.isAcceptableOrUnknown(data['invited']!, _invitedMeta)); - } - if (data.containsKey('banned')) { - context.handle(_bannedMeta, - banned.isAcceptableOrUnknown(data['banned']!, _bannedMeta)); - } - if (data.containsKey('shadow_banned')) { - context.handle( - _shadowBannedMeta, - shadowBanned.isAcceptableOrUnknown( - data['shadow_banned']!, _shadowBannedMeta)); + context.missing(_messageIdMeta); } - if (data.containsKey('is_moderator')) { + if (data.containsKey('type')) { context.handle( - _isModeratorMeta, - isModerator.isAcceptableOrUnknown( - data['is_moderator']!, _isModeratorMeta)); + _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); + } else if (isInserting) { + context.missing(_typeMeta); } if (data.containsKey('created_at')) { context.handle(_createdAtMeta, createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); } - if (data.containsKey('updated_at')) { - context.handle(_updatedAtMeta, - updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); + if (data.containsKey('score')) { + context.handle( + _scoreMeta, score.isAcceptableOrUnknown(data['score']!, _scoreMeta)); } + context.handle(_extraDataMeta, const VerificationResult.success()); return context; } @override - Set get $primaryKey => {userId, channelCid}; + Set get $primaryKey => {messageId, type, userId}; @override - MemberEntity map(Map data, {String? tablePrefix}) { + ReactionEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return MemberEntity( + return ReactionEntity( userId: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, - channelCid: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}channel_cid'])!, - channelRole: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}channel_role']), - inviteAcceptedAt: attachedDatabase.typeMapping.read( - DriftSqlType.dateTime, data['${effectivePrefix}invite_accepted_at']), - inviteRejectedAt: attachedDatabase.typeMapping.read( - DriftSqlType.dateTime, data['${effectivePrefix}invite_rejected_at']), - invited: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}invited'])!, - banned: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}banned'])!, - shadowBanned: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}shadow_banned'])!, - isModerator: attachedDatabase.typeMapping - .read(DriftSqlType.bool, data['${effectivePrefix}is_moderator'])!, + messageId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}message_id'])!, + type: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}type'])!, createdAt: attachedDatabase.typeMapping .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, - updatedAt: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at'])!, + score: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}score'])!, + extraData: $ReactionsTable.$converterextraDatan.fromSql(attachedDatabase + .typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])), ); } @override - $MembersTable createAlias(String alias) { - return $MembersTable(attachedDatabase, alias); + $ReactionsTable createAlias(String alias) { + return $ReactionsTable(attachedDatabase, alias); } + + static TypeConverter, String> $converterextraData = + MapConverter(); + static TypeConverter?, String?> $converterextraDatan = + NullAwareTypeConverter.wrap($converterextraData); } -class MemberEntity extends DataClass implements Insertable { - /// The interested user id +class ReactionEntity extends DataClass implements Insertable { + /// The id of the user that sent the reaction final String userId; - /// The channel cid of which this user is part of - final String channelCid; - - /// The role of the user in the channel - final String? channelRole; - - /// The date on which the user accepted the invite to the channel - final DateTime? inviteAcceptedAt; - - /// The date on which the user rejected the invite to the channel - final DateTime? inviteRejectedAt; - - /// True if the user has been invited to the channel - final bool invited; - - /// True if the member is banned from the channel - final bool banned; - - /// True if the member is shadow banned from the channel - final bool shadowBanned; + /// The messageId to which the reaction belongs + final String messageId; - /// True if the user is a moderator of the channel - final bool isModerator; + /// The type of the reaction + final String type; - /// The date of creation + /// The DateTime on which the reaction is created final DateTime createdAt; - /// The last date of update - final DateTime updatedAt; - const MemberEntity( + /// The score of the reaction (ie. number of reactions sent) + final int score; + + /// Reaction custom extraData + final Map? extraData; + const ReactionEntity( {required this.userId, - required this.channelCid, - this.channelRole, - this.inviteAcceptedAt, - this.inviteRejectedAt, - required this.invited, - required this.banned, - required this.shadowBanned, - required this.isModerator, + required this.messageId, + required this.type, required this.createdAt, - required this.updatedAt}); + required this.score, + this.extraData}); @override Map toColumns(bool nullToAbsent) { final map = {}; map['user_id'] = Variable(userId); - map['channel_cid'] = Variable(channelCid); - if (!nullToAbsent || channelRole != null) { - map['channel_role'] = Variable(channelRole); - } - if (!nullToAbsent || inviteAcceptedAt != null) { - map['invite_accepted_at'] = Variable(inviteAcceptedAt); - } - if (!nullToAbsent || inviteRejectedAt != null) { - map['invite_rejected_at'] = Variable(inviteRejectedAt); - } - map['invited'] = Variable(invited); - map['banned'] = Variable(banned); - map['shadow_banned'] = Variable(shadowBanned); - map['is_moderator'] = Variable(isModerator); + map['message_id'] = Variable(messageId); + map['type'] = Variable(type); map['created_at'] = Variable(createdAt); - map['updated_at'] = Variable(updatedAt); + map['score'] = Variable(score); + if (!nullToAbsent || extraData != null) { + map['extra_data'] = Variable( + $ReactionsTable.$converterextraDatan.toSql(extraData)); + } return map; } - factory MemberEntity.fromJson(Map json, + factory ReactionEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return MemberEntity( + return ReactionEntity( userId: serializer.fromJson(json['userId']), - channelCid: serializer.fromJson(json['channelCid']), - channelRole: serializer.fromJson(json['channelRole']), - inviteAcceptedAt: - serializer.fromJson(json['inviteAcceptedAt']), - inviteRejectedAt: - serializer.fromJson(json['inviteRejectedAt']), - invited: serializer.fromJson(json['invited']), - banned: serializer.fromJson(json['banned']), - shadowBanned: serializer.fromJson(json['shadowBanned']), - isModerator: serializer.fromJson(json['isModerator']), + messageId: serializer.fromJson(json['messageId']), + type: serializer.fromJson(json['type']), createdAt: serializer.fromJson(json['createdAt']), - updatedAt: serializer.fromJson(json['updatedAt']), + score: serializer.fromJson(json['score']), + extraData: serializer.fromJson?>(json['extraData']), ); } @override @@ -4908,218 +5289,131 @@ class MemberEntity extends DataClass implements Insertable { serializer ??= driftRuntimeOptions.defaultSerializer; return { 'userId': serializer.toJson(userId), - 'channelCid': serializer.toJson(channelCid), - 'channelRole': serializer.toJson(channelRole), - 'inviteAcceptedAt': serializer.toJson(inviteAcceptedAt), - 'inviteRejectedAt': serializer.toJson(inviteRejectedAt), - 'invited': serializer.toJson(invited), - 'banned': serializer.toJson(banned), - 'shadowBanned': serializer.toJson(shadowBanned), - 'isModerator': serializer.toJson(isModerator), + 'messageId': serializer.toJson(messageId), + 'type': serializer.toJson(type), 'createdAt': serializer.toJson(createdAt), - 'updatedAt': serializer.toJson(updatedAt), + 'score': serializer.toJson(score), + 'extraData': serializer.toJson?>(extraData), }; } - MemberEntity copyWith( + ReactionEntity copyWith( {String? userId, - String? channelCid, - Value channelRole = const Value.absent(), - Value inviteAcceptedAt = const Value.absent(), - Value inviteRejectedAt = const Value.absent(), - bool? invited, - bool? banned, - bool? shadowBanned, - bool? isModerator, + String? messageId, + String? type, DateTime? createdAt, - DateTime? updatedAt}) => - MemberEntity( - userId: userId ?? this.userId, - channelCid: channelCid ?? this.channelCid, - channelRole: channelRole.present ? channelRole.value : this.channelRole, - inviteAcceptedAt: inviteAcceptedAt.present - ? inviteAcceptedAt.value - : this.inviteAcceptedAt, - inviteRejectedAt: inviteRejectedAt.present - ? inviteRejectedAt.value - : this.inviteRejectedAt, - invited: invited ?? this.invited, - banned: banned ?? this.banned, - shadowBanned: shadowBanned ?? this.shadowBanned, - isModerator: isModerator ?? this.isModerator, + int? score, + Value?> extraData = const Value.absent()}) => + ReactionEntity( + userId: userId ?? this.userId, + messageId: messageId ?? this.messageId, + type: type ?? this.type, createdAt: createdAt ?? this.createdAt, - updatedAt: updatedAt ?? this.updatedAt, + score: score ?? this.score, + extraData: extraData.present ? extraData.value : this.extraData, ); - MemberEntity copyWithCompanion(MembersCompanion data) { - return MemberEntity( + ReactionEntity copyWithCompanion(ReactionsCompanion data) { + return ReactionEntity( userId: data.userId.present ? data.userId.value : this.userId, - channelCid: - data.channelCid.present ? data.channelCid.value : this.channelCid, - channelRole: - data.channelRole.present ? data.channelRole.value : this.channelRole, - inviteAcceptedAt: data.inviteAcceptedAt.present - ? data.inviteAcceptedAt.value - : this.inviteAcceptedAt, - inviteRejectedAt: data.inviteRejectedAt.present - ? data.inviteRejectedAt.value - : this.inviteRejectedAt, - invited: data.invited.present ? data.invited.value : this.invited, - banned: data.banned.present ? data.banned.value : this.banned, - shadowBanned: data.shadowBanned.present - ? data.shadowBanned.value - : this.shadowBanned, - isModerator: - data.isModerator.present ? data.isModerator.value : this.isModerator, + messageId: data.messageId.present ? data.messageId.value : this.messageId, + type: data.type.present ? data.type.value : this.type, createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, - updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, + score: data.score.present ? data.score.value : this.score, + extraData: data.extraData.present ? data.extraData.value : this.extraData, ); } @override String toString() { - return (StringBuffer('MemberEntity(') + return (StringBuffer('ReactionEntity(') ..write('userId: $userId, ') - ..write('channelCid: $channelCid, ') - ..write('channelRole: $channelRole, ') - ..write('inviteAcceptedAt: $inviteAcceptedAt, ') - ..write('inviteRejectedAt: $inviteRejectedAt, ') - ..write('invited: $invited, ') - ..write('banned: $banned, ') - ..write('shadowBanned: $shadowBanned, ') - ..write('isModerator: $isModerator, ') + ..write('messageId: $messageId, ') + ..write('type: $type, ') ..write('createdAt: $createdAt, ') - ..write('updatedAt: $updatedAt') + ..write('score: $score, ') + ..write('extraData: $extraData') ..write(')')) .toString(); } @override - int get hashCode => Object.hash( - userId, - channelCid, - channelRole, - inviteAcceptedAt, - inviteRejectedAt, - invited, - banned, - shadowBanned, - isModerator, - createdAt, - updatedAt); + int get hashCode => + Object.hash(userId, messageId, type, createdAt, score, extraData); @override bool operator ==(Object other) => identical(this, other) || - (other is MemberEntity && + (other is ReactionEntity && other.userId == this.userId && - other.channelCid == this.channelCid && - other.channelRole == this.channelRole && - other.inviteAcceptedAt == this.inviteAcceptedAt && - other.inviteRejectedAt == this.inviteRejectedAt && - other.invited == this.invited && - other.banned == this.banned && - other.shadowBanned == this.shadowBanned && - other.isModerator == this.isModerator && + other.messageId == this.messageId && + other.type == this.type && other.createdAt == this.createdAt && - other.updatedAt == this.updatedAt); + other.score == this.score && + other.extraData == this.extraData); } -class MembersCompanion extends UpdateCompanion { +class ReactionsCompanion extends UpdateCompanion { final Value userId; - final Value channelCid; - final Value channelRole; - final Value inviteAcceptedAt; - final Value inviteRejectedAt; - final Value invited; - final Value banned; - final Value shadowBanned; - final Value isModerator; + final Value messageId; + final Value type; final Value createdAt; - final Value updatedAt; + final Value score; + final Value?> extraData; final Value rowid; - const MembersCompanion({ + const ReactionsCompanion({ this.userId = const Value.absent(), - this.channelCid = const Value.absent(), - this.channelRole = const Value.absent(), - this.inviteAcceptedAt = const Value.absent(), - this.inviteRejectedAt = const Value.absent(), - this.invited = const Value.absent(), - this.banned = const Value.absent(), - this.shadowBanned = const Value.absent(), - this.isModerator = const Value.absent(), + this.messageId = const Value.absent(), + this.type = const Value.absent(), this.createdAt = const Value.absent(), - this.updatedAt = const Value.absent(), + this.score = const Value.absent(), + this.extraData = const Value.absent(), this.rowid = const Value.absent(), }); - MembersCompanion.insert({ + ReactionsCompanion.insert({ required String userId, - required String channelCid, - this.channelRole = const Value.absent(), - this.inviteAcceptedAt = const Value.absent(), - this.inviteRejectedAt = const Value.absent(), - this.invited = const Value.absent(), - this.banned = const Value.absent(), - this.shadowBanned = const Value.absent(), - this.isModerator = const Value.absent(), + required String messageId, + required String type, this.createdAt = const Value.absent(), - this.updatedAt = const Value.absent(), + this.score = const Value.absent(), + this.extraData = const Value.absent(), this.rowid = const Value.absent(), }) : userId = Value(userId), - channelCid = Value(channelCid); - static Insertable custom({ + messageId = Value(messageId), + type = Value(type); + static Insertable custom({ Expression? userId, - Expression? channelCid, - Expression? channelRole, - Expression? inviteAcceptedAt, - Expression? inviteRejectedAt, - Expression? invited, - Expression? banned, - Expression? shadowBanned, - Expression? isModerator, + Expression? messageId, + Expression? type, Expression? createdAt, - Expression? updatedAt, + Expression? score, + Expression? extraData, Expression? rowid, }) { return RawValuesInsertable({ if (userId != null) 'user_id': userId, - if (channelCid != null) 'channel_cid': channelCid, - if (channelRole != null) 'channel_role': channelRole, - if (inviteAcceptedAt != null) 'invite_accepted_at': inviteAcceptedAt, - if (inviteRejectedAt != null) 'invite_rejected_at': inviteRejectedAt, - if (invited != null) 'invited': invited, - if (banned != null) 'banned': banned, - if (shadowBanned != null) 'shadow_banned': shadowBanned, - if (isModerator != null) 'is_moderator': isModerator, + if (messageId != null) 'message_id': messageId, + if (type != null) 'type': type, if (createdAt != null) 'created_at': createdAt, - if (updatedAt != null) 'updated_at': updatedAt, + if (score != null) 'score': score, + if (extraData != null) 'extra_data': extraData, if (rowid != null) 'rowid': rowid, }); } - MembersCompanion copyWith( + ReactionsCompanion copyWith( {Value? userId, - Value? channelCid, - Value? channelRole, - Value? inviteAcceptedAt, - Value? inviteRejectedAt, - Value? invited, - Value? banned, - Value? shadowBanned, - Value? isModerator, + Value? messageId, + Value? type, Value? createdAt, - Value? updatedAt, + Value? score, + Value?>? extraData, Value? rowid}) { - return MembersCompanion( + return ReactionsCompanion( userId: userId ?? this.userId, - channelCid: channelCid ?? this.channelCid, - channelRole: channelRole ?? this.channelRole, - inviteAcceptedAt: inviteAcceptedAt ?? this.inviteAcceptedAt, - inviteRejectedAt: inviteRejectedAt ?? this.inviteRejectedAt, - invited: invited ?? this.invited, - banned: banned ?? this.banned, - shadowBanned: shadowBanned ?? this.shadowBanned, - isModerator: isModerator ?? this.isModerator, + messageId: messageId ?? this.messageId, + type: type ?? this.type, createdAt: createdAt ?? this.createdAt, - updatedAt: updatedAt ?? this.updatedAt, + score: score ?? this.score, + extraData: extraData ?? this.extraData, rowid: rowid ?? this.rowid, ); } @@ -5130,35 +5424,21 @@ class MembersCompanion extends UpdateCompanion { if (userId.present) { map['user_id'] = Variable(userId.value); } - if (channelCid.present) { - map['channel_cid'] = Variable(channelCid.value); - } - if (channelRole.present) { - map['channel_role'] = Variable(channelRole.value); - } - if (inviteAcceptedAt.present) { - map['invite_accepted_at'] = Variable(inviteAcceptedAt.value); - } - if (inviteRejectedAt.present) { - map['invite_rejected_at'] = Variable(inviteRejectedAt.value); - } - if (invited.present) { - map['invited'] = Variable(invited.value); - } - if (banned.present) { - map['banned'] = Variable(banned.value); - } - if (shadowBanned.present) { - map['shadow_banned'] = Variable(shadowBanned.value); + if (messageId.present) { + map['message_id'] = Variable(messageId.value); } - if (isModerator.present) { - map['is_moderator'] = Variable(isModerator.value); + if (type.present) { + map['type'] = Variable(type.value); } if (createdAt.present) { map['created_at'] = Variable(createdAt.value); } - if (updatedAt.present) { - map['updated_at'] = Variable(updatedAt.value); + if (score.present) { + map['score'] = Variable(score.value); + } + if (extraData.present) { + map['extra_data'] = Variable( + $ReactionsTable.$converterextraDatan.toSql(extraData.value)); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -5168,327 +5448,464 @@ class MembersCompanion extends UpdateCompanion { @override String toString() { - return (StringBuffer('MembersCompanion(') + return (StringBuffer('ReactionsCompanion(') ..write('userId: $userId, ') - ..write('channelCid: $channelCid, ') - ..write('channelRole: $channelRole, ') - ..write('inviteAcceptedAt: $inviteAcceptedAt, ') - ..write('inviteRejectedAt: $inviteRejectedAt, ') - ..write('invited: $invited, ') - ..write('banned: $banned, ') - ..write('shadowBanned: $shadowBanned, ') - ..write('isModerator: $isModerator, ') + ..write('messageId: $messageId, ') + ..write('type: $type, ') ..write('createdAt: $createdAt, ') - ..write('updatedAt: $updatedAt, ') + ..write('score: $score, ') + ..write('extraData: $extraData, ') ..write('rowid: $rowid') ..write(')')) .toString(); } } -class $ReadsTable extends Reads with TableInfo<$ReadsTable, ReadEntity> { +class $UsersTable extends Users with TableInfo<$UsersTable, UserEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $ReadsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _lastReadMeta = - const VerificationMeta('lastRead'); + $UsersTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); @override - late final GeneratedColumn lastRead = GeneratedColumn( - 'last_read', aliasedName, false, - type: DriftSqlType.dateTime, requiredDuringInsert: true); - static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); - @override - late final GeneratedColumn userId = GeneratedColumn( - 'user_id', aliasedName, false, + late final GeneratedColumn id = GeneratedColumn( + 'id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _channelCidMeta = - const VerificationMeta('channelCid'); + static const VerificationMeta _roleMeta = const VerificationMeta('role'); @override - late final GeneratedColumn channelCid = GeneratedColumn( - 'channel_cid', aliasedName, false, - type: DriftSqlType.string, - requiredDuringInsert: true, - defaultConstraints: GeneratedColumn.constraintIsAlways( - 'REFERENCES channels (cid) ON DELETE CASCADE')); - static const VerificationMeta _unreadMessagesMeta = - const VerificationMeta('unreadMessages'); + late final GeneratedColumn role = GeneratedColumn( + 'role', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _languageMeta = + const VerificationMeta('language'); @override - late final GeneratedColumn unreadMessages = GeneratedColumn( - 'unread_messages', aliasedName, false, - type: DriftSqlType.int, + late final GeneratedColumn language = GeneratedColumn( + 'language', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _createdAtMeta = + const VerificationMeta('createdAt'); + @override + late final GeneratedColumn createdAt = GeneratedColumn( + 'created_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _updatedAtMeta = + const VerificationMeta('updatedAt'); + @override + late final GeneratedColumn updatedAt = GeneratedColumn( + 'updated_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _lastActiveMeta = + const VerificationMeta('lastActive'); + @override + late final GeneratedColumn lastActive = GeneratedColumn( + 'last_active', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _onlineMeta = const VerificationMeta('online'); + @override + late final GeneratedColumn online = GeneratedColumn( + 'online', aliasedName, false, + type: DriftSqlType.bool, requiredDuringInsert: false, - defaultValue: const Constant(0)); - static const VerificationMeta _lastReadMessageIdMeta = - const VerificationMeta('lastReadMessageId'); + defaultConstraints: + GeneratedColumn.constraintIsAlways('CHECK ("online" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _bannedMeta = const VerificationMeta('banned'); @override - late final GeneratedColumn lastReadMessageId = - GeneratedColumn('last_read_message_id', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false); + late final GeneratedColumn banned = GeneratedColumn( + 'banned', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: + GeneratedColumn.constraintIsAlways('CHECK ("banned" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _extraDataMeta = + const VerificationMeta('extraData'); @override - List get $columns => - [lastRead, userId, channelCid, unreadMessages, lastReadMessageId]; + late final GeneratedColumnWithTypeConverter, String> + extraData = GeneratedColumn('extra_data', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true) + .withConverter>($UsersTable.$converterextraData); + @override + List get $columns => [ + id, + role, + language, + createdAt, + updatedAt, + lastActive, + online, + banned, + extraData + ]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'reads'; + static const String $name = 'users'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('last_read')) { - context.handle(_lastReadMeta, - lastRead.isAcceptableOrUnknown(data['last_read']!, _lastReadMeta)); - } else if (isInserting) { - context.missing(_lastReadMeta); - } - if (data.containsKey('user_id')) { - context.handle(_userIdMeta, - userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); } else if (isInserting) { - context.missing(_userIdMeta); + context.missing(_idMeta); } - if (data.containsKey('channel_cid')) { + if (data.containsKey('role')) { context.handle( - _channelCidMeta, - channelCid.isAcceptableOrUnknown( - data['channel_cid']!, _channelCidMeta)); - } else if (isInserting) { - context.missing(_channelCidMeta); + _roleMeta, role.isAcceptableOrUnknown(data['role']!, _roleMeta)); } - if (data.containsKey('unread_messages')) { - context.handle( - _unreadMessagesMeta, - unreadMessages.isAcceptableOrUnknown( - data['unread_messages']!, _unreadMessagesMeta)); + if (data.containsKey('language')) { + context.handle(_languageMeta, + language.isAcceptableOrUnknown(data['language']!, _languageMeta)); } - if (data.containsKey('last_read_message_id')) { + if (data.containsKey('created_at')) { + context.handle(_createdAtMeta, + createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); + } + if (data.containsKey('updated_at')) { + context.handle(_updatedAtMeta, + updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); + } + if (data.containsKey('last_active')) { context.handle( - _lastReadMessageIdMeta, - lastReadMessageId.isAcceptableOrUnknown( - data['last_read_message_id']!, _lastReadMessageIdMeta)); + _lastActiveMeta, + lastActive.isAcceptableOrUnknown( + data['last_active']!, _lastActiveMeta)); + } + if (data.containsKey('online')) { + context.handle(_onlineMeta, + online.isAcceptableOrUnknown(data['online']!, _onlineMeta)); + } + if (data.containsKey('banned')) { + context.handle(_bannedMeta, + banned.isAcceptableOrUnknown(data['banned']!, _bannedMeta)); } + context.handle(_extraDataMeta, const VerificationResult.success()); return context; } @override - Set get $primaryKey => {userId, channelCid}; + Set get $primaryKey => {id}; @override - ReadEntity map(Map data, {String? tablePrefix}) { + UserEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return ReadEntity( - lastRead: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}last_read'])!, - userId: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, - channelCid: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}channel_cid'])!, - unreadMessages: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}unread_messages'])!, - lastReadMessageId: attachedDatabase.typeMapping.read( - DriftSqlType.string, data['${effectivePrefix}last_read_message_id']), + return UserEntity( + id: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}id'])!, + role: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}role']), + language: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}language']), + createdAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at']), + updatedAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at']), + lastActive: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}last_active']), + online: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}online'])!, + banned: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}banned'])!, + extraData: $UsersTable.$converterextraData.fromSql(attachedDatabase + .typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}extra_data'])!), ); } @override - $ReadsTable createAlias(String alias) { - return $ReadsTable(attachedDatabase, alias); + $UsersTable createAlias(String alias) { + return $UsersTable(attachedDatabase, alias); } + + static TypeConverter, String> $converterextraData = + MapConverter(); } -class ReadEntity extends DataClass implements Insertable { - /// Date of the read event - final DateTime lastRead; +class UserEntity extends DataClass implements Insertable { + /// User id + final String id; - /// Id of the User who sent the event - final String userId; + /// User role + final String? role; - /// The channel cid of which this read belongs - final String channelCid; + /// The language this user prefers. + final String? language; - /// Number of unread messages - final int unreadMessages; + /// Date of user creation + final DateTime? createdAt; - /// Id of the last read message - final String? lastReadMessageId; - const ReadEntity( - {required this.lastRead, - required this.userId, - required this.channelCid, - required this.unreadMessages, - this.lastReadMessageId}); + /// Date of last user update + final DateTime? updatedAt; + + /// Date of last user connection + final DateTime? lastActive; + + /// True if user is online + final bool online; + + /// True if user is banned from the chat + final bool banned; + + /// Map of custom user extraData + final Map extraData; + const UserEntity( + {required this.id, + this.role, + this.language, + this.createdAt, + this.updatedAt, + this.lastActive, + required this.online, + required this.banned, + required this.extraData}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['last_read'] = Variable(lastRead); - map['user_id'] = Variable(userId); - map['channel_cid'] = Variable(channelCid); - map['unread_messages'] = Variable(unreadMessages); - if (!nullToAbsent || lastReadMessageId != null) { - map['last_read_message_id'] = Variable(lastReadMessageId); + map['id'] = Variable(id); + if (!nullToAbsent || role != null) { + map['role'] = Variable(role); } - return map; - } - - factory ReadEntity.fromJson(Map json, - {ValueSerializer? serializer}) { - serializer ??= driftRuntimeOptions.defaultSerializer; - return ReadEntity( - lastRead: serializer.fromJson(json['lastRead']), - userId: serializer.fromJson(json['userId']), - channelCid: serializer.fromJson(json['channelCid']), - unreadMessages: serializer.fromJson(json['unreadMessages']), - lastReadMessageId: - serializer.fromJson(json['lastReadMessageId']), + if (!nullToAbsent || language != null) { + map['language'] = Variable(language); + } + if (!nullToAbsent || createdAt != null) { + map['created_at'] = Variable(createdAt); + } + if (!nullToAbsent || updatedAt != null) { + map['updated_at'] = Variable(updatedAt); + } + if (!nullToAbsent || lastActive != null) { + map['last_active'] = Variable(lastActive); + } + map['online'] = Variable(online); + map['banned'] = Variable(banned); + { + map['extra_data'] = + Variable($UsersTable.$converterextraData.toSql(extraData)); + } + return map; + } + + factory UserEntity.fromJson(Map json, + {ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return UserEntity( + id: serializer.fromJson(json['id']), + role: serializer.fromJson(json['role']), + language: serializer.fromJson(json['language']), + createdAt: serializer.fromJson(json['createdAt']), + updatedAt: serializer.fromJson(json['updatedAt']), + lastActive: serializer.fromJson(json['lastActive']), + online: serializer.fromJson(json['online']), + banned: serializer.fromJson(json['banned']), + extraData: serializer.fromJson>(json['extraData']), ); } @override Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'lastRead': serializer.toJson(lastRead), - 'userId': serializer.toJson(userId), - 'channelCid': serializer.toJson(channelCid), - 'unreadMessages': serializer.toJson(unreadMessages), - 'lastReadMessageId': serializer.toJson(lastReadMessageId), + 'id': serializer.toJson(id), + 'role': serializer.toJson(role), + 'language': serializer.toJson(language), + 'createdAt': serializer.toJson(createdAt), + 'updatedAt': serializer.toJson(updatedAt), + 'lastActive': serializer.toJson(lastActive), + 'online': serializer.toJson(online), + 'banned': serializer.toJson(banned), + 'extraData': serializer.toJson>(extraData), }; } - ReadEntity copyWith( - {DateTime? lastRead, - String? userId, - String? channelCid, - int? unreadMessages, - Value lastReadMessageId = const Value.absent()}) => - ReadEntity( - lastRead: lastRead ?? this.lastRead, - userId: userId ?? this.userId, - channelCid: channelCid ?? this.channelCid, - unreadMessages: unreadMessages ?? this.unreadMessages, - lastReadMessageId: lastReadMessageId.present - ? lastReadMessageId.value - : this.lastReadMessageId, + UserEntity copyWith( + {String? id, + Value role = const Value.absent(), + Value language = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), + Value lastActive = const Value.absent(), + bool? online, + bool? banned, + Map? extraData}) => + UserEntity( + id: id ?? this.id, + role: role.present ? role.value : this.role, + language: language.present ? language.value : this.language, + createdAt: createdAt.present ? createdAt.value : this.createdAt, + updatedAt: updatedAt.present ? updatedAt.value : this.updatedAt, + lastActive: lastActive.present ? lastActive.value : this.lastActive, + online: online ?? this.online, + banned: banned ?? this.banned, + extraData: extraData ?? this.extraData, ); - ReadEntity copyWithCompanion(ReadsCompanion data) { - return ReadEntity( - lastRead: data.lastRead.present ? data.lastRead.value : this.lastRead, - userId: data.userId.present ? data.userId.value : this.userId, - channelCid: - data.channelCid.present ? data.channelCid.value : this.channelCid, - unreadMessages: data.unreadMessages.present - ? data.unreadMessages.value - : this.unreadMessages, - lastReadMessageId: data.lastReadMessageId.present - ? data.lastReadMessageId.value - : this.lastReadMessageId, + UserEntity copyWithCompanion(UsersCompanion data) { + return UserEntity( + id: data.id.present ? data.id.value : this.id, + role: data.role.present ? data.role.value : this.role, + language: data.language.present ? data.language.value : this.language, + createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, + updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, + lastActive: + data.lastActive.present ? data.lastActive.value : this.lastActive, + online: data.online.present ? data.online.value : this.online, + banned: data.banned.present ? data.banned.value : this.banned, + extraData: data.extraData.present ? data.extraData.value : this.extraData, ); } @override String toString() { - return (StringBuffer('ReadEntity(') - ..write('lastRead: $lastRead, ') - ..write('userId: $userId, ') - ..write('channelCid: $channelCid, ') - ..write('unreadMessages: $unreadMessages, ') - ..write('lastReadMessageId: $lastReadMessageId') + return (StringBuffer('UserEntity(') + ..write('id: $id, ') + ..write('role: $role, ') + ..write('language: $language, ') + ..write('createdAt: $createdAt, ') + ..write('updatedAt: $updatedAt, ') + ..write('lastActive: $lastActive, ') + ..write('online: $online, ') + ..write('banned: $banned, ') + ..write('extraData: $extraData') ..write(')')) .toString(); } @override - int get hashCode => Object.hash( - lastRead, userId, channelCid, unreadMessages, lastReadMessageId); + int get hashCode => Object.hash(id, role, language, createdAt, updatedAt, + lastActive, online, banned, extraData); @override bool operator ==(Object other) => identical(this, other) || - (other is ReadEntity && - other.lastRead == this.lastRead && - other.userId == this.userId && - other.channelCid == this.channelCid && - other.unreadMessages == this.unreadMessages && - other.lastReadMessageId == this.lastReadMessageId); + (other is UserEntity && + other.id == this.id && + other.role == this.role && + other.language == this.language && + other.createdAt == this.createdAt && + other.updatedAt == this.updatedAt && + other.lastActive == this.lastActive && + other.online == this.online && + other.banned == this.banned && + other.extraData == this.extraData); } -class ReadsCompanion extends UpdateCompanion { - final Value lastRead; - final Value userId; - final Value channelCid; - final Value unreadMessages; - final Value lastReadMessageId; +class UsersCompanion extends UpdateCompanion { + final Value id; + final Value role; + final Value language; + final Value createdAt; + final Value updatedAt; + final Value lastActive; + final Value online; + final Value banned; + final Value> extraData; final Value rowid; - const ReadsCompanion({ - this.lastRead = const Value.absent(), - this.userId = const Value.absent(), - this.channelCid = const Value.absent(), - this.unreadMessages = const Value.absent(), - this.lastReadMessageId = const Value.absent(), + const UsersCompanion({ + this.id = const Value.absent(), + this.role = const Value.absent(), + this.language = const Value.absent(), + this.createdAt = const Value.absent(), + this.updatedAt = const Value.absent(), + this.lastActive = const Value.absent(), + this.online = const Value.absent(), + this.banned = const Value.absent(), + this.extraData = const Value.absent(), this.rowid = const Value.absent(), }); - ReadsCompanion.insert({ - required DateTime lastRead, - required String userId, - required String channelCid, - this.unreadMessages = const Value.absent(), - this.lastReadMessageId = const Value.absent(), + UsersCompanion.insert({ + required String id, + this.role = const Value.absent(), + this.language = const Value.absent(), + this.createdAt = const Value.absent(), + this.updatedAt = const Value.absent(), + this.lastActive = const Value.absent(), + this.online = const Value.absent(), + this.banned = const Value.absent(), + required Map extraData, this.rowid = const Value.absent(), - }) : lastRead = Value(lastRead), - userId = Value(userId), - channelCid = Value(channelCid); - static Insertable custom({ - Expression? lastRead, - Expression? userId, - Expression? channelCid, - Expression? unreadMessages, - Expression? lastReadMessageId, + }) : id = Value(id), + extraData = Value(extraData); + static Insertable custom({ + Expression? id, + Expression? role, + Expression? language, + Expression? createdAt, + Expression? updatedAt, + Expression? lastActive, + Expression? online, + Expression? banned, + Expression? extraData, Expression? rowid, }) { return RawValuesInsertable({ - if (lastRead != null) 'last_read': lastRead, - if (userId != null) 'user_id': userId, - if (channelCid != null) 'channel_cid': channelCid, - if (unreadMessages != null) 'unread_messages': unreadMessages, - if (lastReadMessageId != null) 'last_read_message_id': lastReadMessageId, + if (id != null) 'id': id, + if (role != null) 'role': role, + if (language != null) 'language': language, + if (createdAt != null) 'created_at': createdAt, + if (updatedAt != null) 'updated_at': updatedAt, + if (lastActive != null) 'last_active': lastActive, + if (online != null) 'online': online, + if (banned != null) 'banned': banned, + if (extraData != null) 'extra_data': extraData, if (rowid != null) 'rowid': rowid, }); } - ReadsCompanion copyWith( - {Value? lastRead, - Value? userId, - Value? channelCid, - Value? unreadMessages, - Value? lastReadMessageId, + UsersCompanion copyWith( + {Value? id, + Value? role, + Value? language, + Value? createdAt, + Value? updatedAt, + Value? lastActive, + Value? online, + Value? banned, + Value>? extraData, Value? rowid}) { - return ReadsCompanion( - lastRead: lastRead ?? this.lastRead, - userId: userId ?? this.userId, - channelCid: channelCid ?? this.channelCid, - unreadMessages: unreadMessages ?? this.unreadMessages, - lastReadMessageId: lastReadMessageId ?? this.lastReadMessageId, - rowid: rowid ?? this.rowid, - ); - } - - @override + return UsersCompanion( + id: id ?? this.id, + role: role ?? this.role, + language: language ?? this.language, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, + lastActive: lastActive ?? this.lastActive, + online: online ?? this.online, + banned: banned ?? this.banned, + extraData: extraData ?? this.extraData, + rowid: rowid ?? this.rowid, + ); + } + + @override Map toColumns(bool nullToAbsent) { final map = {}; - if (lastRead.present) { - map['last_read'] = Variable(lastRead.value); + if (id.present) { + map['id'] = Variable(id.value); } - if (userId.present) { - map['user_id'] = Variable(userId.value); + if (role.present) { + map['role'] = Variable(role.value); } - if (channelCid.present) { - map['channel_cid'] = Variable(channelCid.value); + if (language.present) { + map['language'] = Variable(language.value); } - if (unreadMessages.present) { - map['unread_messages'] = Variable(unreadMessages.value); + if (createdAt.present) { + map['created_at'] = Variable(createdAt.value); } - if (lastReadMessageId.present) { - map['last_read_message_id'] = Variable(lastReadMessageId.value); + if (updatedAt.present) { + map['updated_at'] = Variable(updatedAt.value); + } + if (lastActive.present) { + map['last_active'] = Variable(lastActive.value); + } + if (online.present) { + map['online'] = Variable(online.value); + } + if (banned.present) { + map['banned'] = Variable(banned.value); + } + if (extraData.present) { + map['extra_data'] = Variable( + $UsersTable.$converterextraData.toSql(extraData.value)); } if (rowid.present) { map['rowid'] = Variable(rowid.value); @@ -5498,53 +5915,144 @@ class ReadsCompanion extends UpdateCompanion { @override String toString() { - return (StringBuffer('ReadsCompanion(') - ..write('lastRead: $lastRead, ') - ..write('userId: $userId, ') - ..write('channelCid: $channelCid, ') - ..write('unreadMessages: $unreadMessages, ') - ..write('lastReadMessageId: $lastReadMessageId, ') + return (StringBuffer('UsersCompanion(') + ..write('id: $id, ') + ..write('role: $role, ') + ..write('language: $language, ') + ..write('createdAt: $createdAt, ') + ..write('updatedAt: $updatedAt, ') + ..write('lastActive: $lastActive, ') + ..write('online: $online, ') + ..write('banned: $banned, ') + ..write('extraData: $extraData, ') ..write('rowid: $rowid') ..write(')')) .toString(); } } -class $ChannelQueriesTable extends ChannelQueries - with TableInfo<$ChannelQueriesTable, ChannelQueryEntity> { +class $MembersTable extends Members + with TableInfo<$MembersTable, MemberEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $ChannelQueriesTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _queryHashMeta = - const VerificationMeta('queryHash'); + $MembersTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); @override - late final GeneratedColumn queryHash = GeneratedColumn( - 'query_hash', aliasedName, false, + late final GeneratedColumn userId = GeneratedColumn( + 'user_id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); static const VerificationMeta _channelCidMeta = const VerificationMeta('channelCid'); @override late final GeneratedColumn channelCid = GeneratedColumn( 'channel_cid', aliasedName, false, - type: DriftSqlType.string, requiredDuringInsert: true); + type: DriftSqlType.string, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES channels (cid) ON DELETE CASCADE')); + static const VerificationMeta _channelRoleMeta = + const VerificationMeta('channelRole'); @override - List get $columns => [queryHash, channelCid]; + late final GeneratedColumn channelRole = GeneratedColumn( + 'channel_role', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); + static const VerificationMeta _inviteAcceptedAtMeta = + const VerificationMeta('inviteAcceptedAt'); + @override + late final GeneratedColumn inviteAcceptedAt = + GeneratedColumn('invite_accepted_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _inviteRejectedAtMeta = + const VerificationMeta('inviteRejectedAt'); + @override + late final GeneratedColumn inviteRejectedAt = + GeneratedColumn('invite_rejected_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _invitedMeta = + const VerificationMeta('invited'); + @override + late final GeneratedColumn invited = GeneratedColumn( + 'invited', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: + GeneratedColumn.constraintIsAlways('CHECK ("invited" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _bannedMeta = const VerificationMeta('banned'); + @override + late final GeneratedColumn banned = GeneratedColumn( + 'banned', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: + GeneratedColumn.constraintIsAlways('CHECK ("banned" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _shadowBannedMeta = + const VerificationMeta('shadowBanned'); + @override + late final GeneratedColumn shadowBanned = GeneratedColumn( + 'shadow_banned', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("shadow_banned" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _isModeratorMeta = + const VerificationMeta('isModerator'); + @override + late final GeneratedColumn isModerator = GeneratedColumn( + 'is_moderator', aliasedName, false, + type: DriftSqlType.bool, + requiredDuringInsert: false, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'CHECK ("is_moderator" IN (0, 1))'), + defaultValue: const Constant(false)); + static const VerificationMeta _createdAtMeta = + const VerificationMeta('createdAt'); + @override + late final GeneratedColumn createdAt = GeneratedColumn( + 'created_at', aliasedName, false, + type: DriftSqlType.dateTime, + requiredDuringInsert: false, + defaultValue: currentDateAndTime); + static const VerificationMeta _updatedAtMeta = + const VerificationMeta('updatedAt'); + @override + late final GeneratedColumn updatedAt = GeneratedColumn( + 'updated_at', aliasedName, false, + type: DriftSqlType.dateTime, + requiredDuringInsert: false, + defaultValue: currentDateAndTime); + @override + List get $columns => [ + userId, + channelCid, + channelRole, + inviteAcceptedAt, + inviteRejectedAt, + invited, + banned, + shadowBanned, + isModerator, + createdAt, + updatedAt + ]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'channel_queries'; + static const String $name = 'members'; @override - VerificationContext validateIntegrity(Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('query_hash')) { - context.handle(_queryHashMeta, - queryHash.isAcceptableOrUnknown(data['query_hash']!, _queryHashMeta)); + if (data.containsKey('user_id')) { + context.handle(_userIdMeta, + userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); } else if (isInserting) { - context.missing(_queryHashMeta); + context.missing(_userIdMeta); } if (data.containsKey('channel_cid')) { context.handle( @@ -5554,127 +6062,396 @@ class $ChannelQueriesTable extends ChannelQueries } else if (isInserting) { context.missing(_channelCidMeta); } + if (data.containsKey('channel_role')) { + context.handle( + _channelRoleMeta, + channelRole.isAcceptableOrUnknown( + data['channel_role']!, _channelRoleMeta)); + } + if (data.containsKey('invite_accepted_at')) { + context.handle( + _inviteAcceptedAtMeta, + inviteAcceptedAt.isAcceptableOrUnknown( + data['invite_accepted_at']!, _inviteAcceptedAtMeta)); + } + if (data.containsKey('invite_rejected_at')) { + context.handle( + _inviteRejectedAtMeta, + inviteRejectedAt.isAcceptableOrUnknown( + data['invite_rejected_at']!, _inviteRejectedAtMeta)); + } + if (data.containsKey('invited')) { + context.handle(_invitedMeta, + invited.isAcceptableOrUnknown(data['invited']!, _invitedMeta)); + } + if (data.containsKey('banned')) { + context.handle(_bannedMeta, + banned.isAcceptableOrUnknown(data['banned']!, _bannedMeta)); + } + if (data.containsKey('shadow_banned')) { + context.handle( + _shadowBannedMeta, + shadowBanned.isAcceptableOrUnknown( + data['shadow_banned']!, _shadowBannedMeta)); + } + if (data.containsKey('is_moderator')) { + context.handle( + _isModeratorMeta, + isModerator.isAcceptableOrUnknown( + data['is_moderator']!, _isModeratorMeta)); + } + if (data.containsKey('created_at')) { + context.handle(_createdAtMeta, + createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta)); + } + if (data.containsKey('updated_at')) { + context.handle(_updatedAtMeta, + updatedAt.isAcceptableOrUnknown(data['updated_at']!, _updatedAtMeta)); + } return context; } @override - Set get $primaryKey => {queryHash, channelCid}; + Set get $primaryKey => {userId, channelCid}; @override - ChannelQueryEntity map(Map data, {String? tablePrefix}) { + MemberEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return ChannelQueryEntity( - queryHash: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}query_hash'])!, + return MemberEntity( + userId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, channelCid: attachedDatabase.typeMapping .read(DriftSqlType.string, data['${effectivePrefix}channel_cid'])!, + channelRole: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}channel_role']), + inviteAcceptedAt: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, data['${effectivePrefix}invite_accepted_at']), + inviteRejectedAt: attachedDatabase.typeMapping.read( + DriftSqlType.dateTime, data['${effectivePrefix}invite_rejected_at']), + invited: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}invited'])!, + banned: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}banned'])!, + shadowBanned: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}shadow_banned'])!, + isModerator: attachedDatabase.typeMapping + .read(DriftSqlType.bool, data['${effectivePrefix}is_moderator'])!, + createdAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}created_at'])!, + updatedAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}updated_at'])!, ); } @override - $ChannelQueriesTable createAlias(String alias) { - return $ChannelQueriesTable(attachedDatabase, alias); + $MembersTable createAlias(String alias) { + return $MembersTable(attachedDatabase, alias); } } -class ChannelQueryEntity extends DataClass - implements Insertable { - /// The unique hash of this query - final String queryHash; +class MemberEntity extends DataClass implements Insertable { + /// The interested user id + final String userId; - /// The channel cid of this query + /// The channel cid of which this user is part of final String channelCid; - const ChannelQueryEntity({required this.queryHash, required this.channelCid}); + + /// The role of the user in the channel + final String? channelRole; + + /// The date on which the user accepted the invite to the channel + final DateTime? inviteAcceptedAt; + + /// The date on which the user rejected the invite to the channel + final DateTime? inviteRejectedAt; + + /// True if the user has been invited to the channel + final bool invited; + + /// True if the member is banned from the channel + final bool banned; + + /// True if the member is shadow banned from the channel + final bool shadowBanned; + + /// True if the user is a moderator of the channel + final bool isModerator; + + /// The date of creation + final DateTime createdAt; + + /// The last date of update + final DateTime updatedAt; + const MemberEntity( + {required this.userId, + required this.channelCid, + this.channelRole, + this.inviteAcceptedAt, + this.inviteRejectedAt, + required this.invited, + required this.banned, + required this.shadowBanned, + required this.isModerator, + required this.createdAt, + required this.updatedAt}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['query_hash'] = Variable(queryHash); + map['user_id'] = Variable(userId); map['channel_cid'] = Variable(channelCid); + if (!nullToAbsent || channelRole != null) { + map['channel_role'] = Variable(channelRole); + } + if (!nullToAbsent || inviteAcceptedAt != null) { + map['invite_accepted_at'] = Variable(inviteAcceptedAt); + } + if (!nullToAbsent || inviteRejectedAt != null) { + map['invite_rejected_at'] = Variable(inviteRejectedAt); + } + map['invited'] = Variable(invited); + map['banned'] = Variable(banned); + map['shadow_banned'] = Variable(shadowBanned); + map['is_moderator'] = Variable(isModerator); + map['created_at'] = Variable(createdAt); + map['updated_at'] = Variable(updatedAt); return map; } - factory ChannelQueryEntity.fromJson(Map json, + factory MemberEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return ChannelQueryEntity( - queryHash: serializer.fromJson(json['queryHash']), + return MemberEntity( + userId: serializer.fromJson(json['userId']), channelCid: serializer.fromJson(json['channelCid']), + channelRole: serializer.fromJson(json['channelRole']), + inviteAcceptedAt: + serializer.fromJson(json['inviteAcceptedAt']), + inviteRejectedAt: + serializer.fromJson(json['inviteRejectedAt']), + invited: serializer.fromJson(json['invited']), + banned: serializer.fromJson(json['banned']), + shadowBanned: serializer.fromJson(json['shadowBanned']), + isModerator: serializer.fromJson(json['isModerator']), + createdAt: serializer.fromJson(json['createdAt']), + updatedAt: serializer.fromJson(json['updatedAt']), ); } @override Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'queryHash': serializer.toJson(queryHash), + 'userId': serializer.toJson(userId), 'channelCid': serializer.toJson(channelCid), + 'channelRole': serializer.toJson(channelRole), + 'inviteAcceptedAt': serializer.toJson(inviteAcceptedAt), + 'inviteRejectedAt': serializer.toJson(inviteRejectedAt), + 'invited': serializer.toJson(invited), + 'banned': serializer.toJson(banned), + 'shadowBanned': serializer.toJson(shadowBanned), + 'isModerator': serializer.toJson(isModerator), + 'createdAt': serializer.toJson(createdAt), + 'updatedAt': serializer.toJson(updatedAt), }; } - ChannelQueryEntity copyWith({String? queryHash, String? channelCid}) => - ChannelQueryEntity( - queryHash: queryHash ?? this.queryHash, + MemberEntity copyWith( + {String? userId, + String? channelCid, + Value channelRole = const Value.absent(), + Value inviteAcceptedAt = const Value.absent(), + Value inviteRejectedAt = const Value.absent(), + bool? invited, + bool? banned, + bool? shadowBanned, + bool? isModerator, + DateTime? createdAt, + DateTime? updatedAt}) => + MemberEntity( + userId: userId ?? this.userId, channelCid: channelCid ?? this.channelCid, + channelRole: channelRole.present ? channelRole.value : this.channelRole, + inviteAcceptedAt: inviteAcceptedAt.present + ? inviteAcceptedAt.value + : this.inviteAcceptedAt, + inviteRejectedAt: inviteRejectedAt.present + ? inviteRejectedAt.value + : this.inviteRejectedAt, + invited: invited ?? this.invited, + banned: banned ?? this.banned, + shadowBanned: shadowBanned ?? this.shadowBanned, + isModerator: isModerator ?? this.isModerator, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, ); - ChannelQueryEntity copyWithCompanion(ChannelQueriesCompanion data) { - return ChannelQueryEntity( - queryHash: data.queryHash.present ? data.queryHash.value : this.queryHash, + MemberEntity copyWithCompanion(MembersCompanion data) { + return MemberEntity( + userId: data.userId.present ? data.userId.value : this.userId, channelCid: data.channelCid.present ? data.channelCid.value : this.channelCid, + channelRole: + data.channelRole.present ? data.channelRole.value : this.channelRole, + inviteAcceptedAt: data.inviteAcceptedAt.present + ? data.inviteAcceptedAt.value + : this.inviteAcceptedAt, + inviteRejectedAt: data.inviteRejectedAt.present + ? data.inviteRejectedAt.value + : this.inviteRejectedAt, + invited: data.invited.present ? data.invited.value : this.invited, + banned: data.banned.present ? data.banned.value : this.banned, + shadowBanned: data.shadowBanned.present + ? data.shadowBanned.value + : this.shadowBanned, + isModerator: + data.isModerator.present ? data.isModerator.value : this.isModerator, + createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt, + updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, ); } @override String toString() { - return (StringBuffer('ChannelQueryEntity(') - ..write('queryHash: $queryHash, ') - ..write('channelCid: $channelCid') + return (StringBuffer('MemberEntity(') + ..write('userId: $userId, ') + ..write('channelCid: $channelCid, ') + ..write('channelRole: $channelRole, ') + ..write('inviteAcceptedAt: $inviteAcceptedAt, ') + ..write('inviteRejectedAt: $inviteRejectedAt, ') + ..write('invited: $invited, ') + ..write('banned: $banned, ') + ..write('shadowBanned: $shadowBanned, ') + ..write('isModerator: $isModerator, ') + ..write('createdAt: $createdAt, ') + ..write('updatedAt: $updatedAt') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(queryHash, channelCid); + int get hashCode => Object.hash( + userId, + channelCid, + channelRole, + inviteAcceptedAt, + inviteRejectedAt, + invited, + banned, + shadowBanned, + isModerator, + createdAt, + updatedAt); @override bool operator ==(Object other) => identical(this, other) || - (other is ChannelQueryEntity && - other.queryHash == this.queryHash && - other.channelCid == this.channelCid); + (other is MemberEntity && + other.userId == this.userId && + other.channelCid == this.channelCid && + other.channelRole == this.channelRole && + other.inviteAcceptedAt == this.inviteAcceptedAt && + other.inviteRejectedAt == this.inviteRejectedAt && + other.invited == this.invited && + other.banned == this.banned && + other.shadowBanned == this.shadowBanned && + other.isModerator == this.isModerator && + other.createdAt == this.createdAt && + other.updatedAt == this.updatedAt); } -class ChannelQueriesCompanion extends UpdateCompanion { - final Value queryHash; +class MembersCompanion extends UpdateCompanion { + final Value userId; final Value channelCid; + final Value channelRole; + final Value inviteAcceptedAt; + final Value inviteRejectedAt; + final Value invited; + final Value banned; + final Value shadowBanned; + final Value isModerator; + final Value createdAt; + final Value updatedAt; final Value rowid; - const ChannelQueriesCompanion({ - this.queryHash = const Value.absent(), + const MembersCompanion({ + this.userId = const Value.absent(), this.channelCid = const Value.absent(), + this.channelRole = const Value.absent(), + this.inviteAcceptedAt = const Value.absent(), + this.inviteRejectedAt = const Value.absent(), + this.invited = const Value.absent(), + this.banned = const Value.absent(), + this.shadowBanned = const Value.absent(), + this.isModerator = const Value.absent(), + this.createdAt = const Value.absent(), + this.updatedAt = const Value.absent(), this.rowid = const Value.absent(), }); - ChannelQueriesCompanion.insert({ - required String queryHash, + MembersCompanion.insert({ + required String userId, required String channelCid, + this.channelRole = const Value.absent(), + this.inviteAcceptedAt = const Value.absent(), + this.inviteRejectedAt = const Value.absent(), + this.invited = const Value.absent(), + this.banned = const Value.absent(), + this.shadowBanned = const Value.absent(), + this.isModerator = const Value.absent(), + this.createdAt = const Value.absent(), + this.updatedAt = const Value.absent(), this.rowid = const Value.absent(), - }) : queryHash = Value(queryHash), + }) : userId = Value(userId), channelCid = Value(channelCid); - static Insertable custom({ - Expression? queryHash, + static Insertable custom({ + Expression? userId, Expression? channelCid, + Expression? channelRole, + Expression? inviteAcceptedAt, + Expression? inviteRejectedAt, + Expression? invited, + Expression? banned, + Expression? shadowBanned, + Expression? isModerator, + Expression? createdAt, + Expression? updatedAt, Expression? rowid, }) { return RawValuesInsertable({ - if (queryHash != null) 'query_hash': queryHash, + if (userId != null) 'user_id': userId, if (channelCid != null) 'channel_cid': channelCid, - if (rowid != null) 'rowid': rowid, - }); - } - - ChannelQueriesCompanion copyWith( - {Value? queryHash, - Value? channelCid, + if (channelRole != null) 'channel_role': channelRole, + if (inviteAcceptedAt != null) 'invite_accepted_at': inviteAcceptedAt, + if (inviteRejectedAt != null) 'invite_rejected_at': inviteRejectedAt, + if (invited != null) 'invited': invited, + if (banned != null) 'banned': banned, + if (shadowBanned != null) 'shadow_banned': shadowBanned, + if (isModerator != null) 'is_moderator': isModerator, + if (createdAt != null) 'created_at': createdAt, + if (updatedAt != null) 'updated_at': updatedAt, + if (rowid != null) 'rowid': rowid, + }); + } + + MembersCompanion copyWith( + {Value? userId, + Value? channelCid, + Value? channelRole, + Value? inviteAcceptedAt, + Value? inviteRejectedAt, + Value? invited, + Value? banned, + Value? shadowBanned, + Value? isModerator, + Value? createdAt, + Value? updatedAt, Value? rowid}) { - return ChannelQueriesCompanion( - queryHash: queryHash ?? this.queryHash, + return MembersCompanion( + userId: userId ?? this.userId, channelCid: channelCid ?? this.channelCid, + channelRole: channelRole ?? this.channelRole, + inviteAcceptedAt: inviteAcceptedAt ?? this.inviteAcceptedAt, + inviteRejectedAt: inviteRejectedAt ?? this.inviteRejectedAt, + invited: invited ?? this.invited, + banned: banned ?? this.banned, + shadowBanned: shadowBanned ?? this.shadowBanned, + isModerator: isModerator ?? this.isModerator, + createdAt: createdAt ?? this.createdAt, + updatedAt: updatedAt ?? this.updatedAt, rowid: rowid ?? this.rowid, ); } @@ -5682,12 +6459,39 @@ class ChannelQueriesCompanion extends UpdateCompanion { @override Map toColumns(bool nullToAbsent) { final map = {}; - if (queryHash.present) { - map['query_hash'] = Variable(queryHash.value); + if (userId.present) { + map['user_id'] = Variable(userId.value); } if (channelCid.present) { map['channel_cid'] = Variable(channelCid.value); } + if (channelRole.present) { + map['channel_role'] = Variable(channelRole.value); + } + if (inviteAcceptedAt.present) { + map['invite_accepted_at'] = Variable(inviteAcceptedAt.value); + } + if (inviteRejectedAt.present) { + map['invite_rejected_at'] = Variable(inviteRejectedAt.value); + } + if (invited.present) { + map['invited'] = Variable(invited.value); + } + if (banned.present) { + map['banned'] = Variable(banned.value); + } + if (shadowBanned.present) { + map['shadow_banned'] = Variable(shadowBanned.value); + } + if (isModerator.present) { + map['is_moderator'] = Variable(isModerator.value); + } + if (createdAt.present) { + map['created_at'] = Variable(createdAt.value); + } + if (updatedAt.present) { + map['updated_at'] = Variable(updatedAt.value); + } if (rowid.present) { map['rowid'] = Variable(rowid.value); } @@ -5696,586 +6500,1670 @@ class ChannelQueriesCompanion extends UpdateCompanion { @override String toString() { - return (StringBuffer('ChannelQueriesCompanion(') - ..write('queryHash: $queryHash, ') + return (StringBuffer('MembersCompanion(') + ..write('userId: $userId, ') ..write('channelCid: $channelCid, ') + ..write('channelRole: $channelRole, ') + ..write('inviteAcceptedAt: $inviteAcceptedAt, ') + ..write('inviteRejectedAt: $inviteRejectedAt, ') + ..write('invited: $invited, ') + ..write('banned: $banned, ') + ..write('shadowBanned: $shadowBanned, ') + ..write('isModerator: $isModerator, ') + ..write('createdAt: $createdAt, ') + ..write('updatedAt: $updatedAt, ') ..write('rowid: $rowid') ..write(')')) .toString(); } } -class $ConnectionEventsTable extends ConnectionEvents - with TableInfo<$ConnectionEventsTable, ConnectionEventEntity> { +class $ReadsTable extends Reads with TableInfo<$ReadsTable, ReadEntity> { @override final GeneratedDatabase attachedDatabase; final String? _alias; - $ConnectionEventsTable(this.attachedDatabase, [this._alias]); - static const VerificationMeta _idMeta = const VerificationMeta('id'); + $ReadsTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _lastReadMeta = + const VerificationMeta('lastRead'); @override - late final GeneratedColumn id = GeneratedColumn( - 'id', aliasedName, false, - type: DriftSqlType.int, requiredDuringInsert: false); - static const VerificationMeta _typeMeta = const VerificationMeta('type'); + late final GeneratedColumn lastRead = GeneratedColumn( + 'last_read', aliasedName, false, + type: DriftSqlType.dateTime, requiredDuringInsert: true); + static const VerificationMeta _userIdMeta = const VerificationMeta('userId'); @override - late final GeneratedColumn type = GeneratedColumn( - 'type', aliasedName, false, + late final GeneratedColumn userId = GeneratedColumn( + 'user_id', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true); - static const VerificationMeta _ownUserMeta = - const VerificationMeta('ownUser'); - @override - late final GeneratedColumnWithTypeConverter?, String> - ownUser = GeneratedColumn('own_user', aliasedName, true, - type: DriftSqlType.string, requiredDuringInsert: false) - .withConverter?>( - $ConnectionEventsTable.$converterownUsern); - static const VerificationMeta _totalUnreadCountMeta = - const VerificationMeta('totalUnreadCount'); - @override - late final GeneratedColumn totalUnreadCount = GeneratedColumn( - 'total_unread_count', aliasedName, true, - type: DriftSqlType.int, requiredDuringInsert: false); - static const VerificationMeta _unreadChannelsMeta = - const VerificationMeta('unreadChannels'); + static const VerificationMeta _channelCidMeta = + const VerificationMeta('channelCid'); @override - late final GeneratedColumn unreadChannels = GeneratedColumn( - 'unread_channels', aliasedName, true, - type: DriftSqlType.int, requiredDuringInsert: false); - static const VerificationMeta _lastEventAtMeta = - const VerificationMeta('lastEventAt'); + late final GeneratedColumn channelCid = GeneratedColumn( + 'channel_cid', aliasedName, false, + type: DriftSqlType.string, + requiredDuringInsert: true, + defaultConstraints: GeneratedColumn.constraintIsAlways( + 'REFERENCES channels (cid) ON DELETE CASCADE')); + static const VerificationMeta _unreadMessagesMeta = + const VerificationMeta('unreadMessages'); @override - late final GeneratedColumn lastEventAt = GeneratedColumn( - 'last_event_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); - static const VerificationMeta _lastSyncAtMeta = - const VerificationMeta('lastSyncAt'); + late final GeneratedColumn unreadMessages = GeneratedColumn( + 'unread_messages', aliasedName, false, + type: DriftSqlType.int, + requiredDuringInsert: false, + defaultValue: const Constant(0)); + static const VerificationMeta _lastReadMessageIdMeta = + const VerificationMeta('lastReadMessageId'); @override - late final GeneratedColumn lastSyncAt = GeneratedColumn( - 'last_sync_at', aliasedName, true, - type: DriftSqlType.dateTime, requiredDuringInsert: false); + late final GeneratedColumn lastReadMessageId = + GeneratedColumn('last_read_message_id', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false); @override - List get $columns => [ - id, - type, - ownUser, - totalUnreadCount, - unreadChannels, - lastEventAt, - lastSyncAt - ]; + List get $columns => + [lastRead, userId, channelCid, unreadMessages, lastReadMessageId]; @override String get aliasedName => _alias ?? actualTableName; @override String get actualTableName => $name; - static const String $name = 'connection_events'; + static const String $name = 'reads'; @override - VerificationContext validateIntegrity( - Insertable instance, + VerificationContext validateIntegrity(Insertable instance, {bool isInserting = false}) { final context = VerificationContext(); final data = instance.toColumns(true); - if (data.containsKey('id')) { - context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); - } - if (data.containsKey('type')) { - context.handle( - _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); + if (data.containsKey('last_read')) { + context.handle(_lastReadMeta, + lastRead.isAcceptableOrUnknown(data['last_read']!, _lastReadMeta)); } else if (isInserting) { - context.missing(_typeMeta); + context.missing(_lastReadMeta); } - context.handle(_ownUserMeta, const VerificationResult.success()); - if (data.containsKey('total_unread_count')) { - context.handle( - _totalUnreadCountMeta, - totalUnreadCount.isAcceptableOrUnknown( - data['total_unread_count']!, _totalUnreadCountMeta)); + if (data.containsKey('user_id')) { + context.handle(_userIdMeta, + userId.isAcceptableOrUnknown(data['user_id']!, _userIdMeta)); + } else if (isInserting) { + context.missing(_userIdMeta); } - if (data.containsKey('unread_channels')) { + if (data.containsKey('channel_cid')) { context.handle( - _unreadChannelsMeta, - unreadChannels.isAcceptableOrUnknown( - data['unread_channels']!, _unreadChannelsMeta)); + _channelCidMeta, + channelCid.isAcceptableOrUnknown( + data['channel_cid']!, _channelCidMeta)); + } else if (isInserting) { + context.missing(_channelCidMeta); } - if (data.containsKey('last_event_at')) { + if (data.containsKey('unread_messages')) { context.handle( - _lastEventAtMeta, - lastEventAt.isAcceptableOrUnknown( - data['last_event_at']!, _lastEventAtMeta)); + _unreadMessagesMeta, + unreadMessages.isAcceptableOrUnknown( + data['unread_messages']!, _unreadMessagesMeta)); } - if (data.containsKey('last_sync_at')) { + if (data.containsKey('last_read_message_id')) { context.handle( - _lastSyncAtMeta, - lastSyncAt.isAcceptableOrUnknown( - data['last_sync_at']!, _lastSyncAtMeta)); + _lastReadMessageIdMeta, + lastReadMessageId.isAcceptableOrUnknown( + data['last_read_message_id']!, _lastReadMessageIdMeta)); } return context; } @override - Set get $primaryKey => {id}; + Set get $primaryKey => {userId, channelCid}; @override - ConnectionEventEntity map(Map data, {String? tablePrefix}) { + ReadEntity map(Map data, {String? tablePrefix}) { final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; - return ConnectionEventEntity( - id: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}id'])!, - type: attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}type'])!, - ownUser: $ConnectionEventsTable.$converterownUsern.fromSql( - attachedDatabase.typeMapping - .read(DriftSqlType.string, data['${effectivePrefix}own_user'])), - totalUnreadCount: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}total_unread_count']), - unreadChannels: attachedDatabase.typeMapping - .read(DriftSqlType.int, data['${effectivePrefix}unread_channels']), - lastEventAt: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}last_event_at']), - lastSyncAt: attachedDatabase.typeMapping - .read(DriftSqlType.dateTime, data['${effectivePrefix}last_sync_at']), + return ReadEntity( + lastRead: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}last_read'])!, + userId: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}user_id'])!, + channelCid: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}channel_cid'])!, + unreadMessages: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}unread_messages'])!, + lastReadMessageId: attachedDatabase.typeMapping.read( + DriftSqlType.string, data['${effectivePrefix}last_read_message_id']), ); } @override - $ConnectionEventsTable createAlias(String alias) { - return $ConnectionEventsTable(attachedDatabase, alias); + $ReadsTable createAlias(String alias) { + return $ReadsTable(attachedDatabase, alias); } - - static TypeConverter, String> $converterownUser = - MapConverter(); - static TypeConverter?, String?> $converterownUsern = - NullAwareTypeConverter.wrap($converterownUser); } -class ConnectionEventEntity extends DataClass - implements Insertable { - /// event id - final int id; - - /// event type - final String type; - - /// User object of the current user - final Map? ownUser; +class ReadEntity extends DataClass implements Insertable { + /// Date of the read event + final DateTime lastRead; - /// The number of unread messages for current user - final int? totalUnreadCount; + /// Id of the User who sent the event + final String userId; - /// User total unread channels for current user - final int? unreadChannels; + /// The channel cid of which this read belongs + final String channelCid; - /// DateTime of the last event - final DateTime? lastEventAt; + /// Number of unread messages + final int unreadMessages; - /// DateTime of the last sync - final DateTime? lastSyncAt; - const ConnectionEventEntity( - {required this.id, - required this.type, - this.ownUser, - this.totalUnreadCount, - this.unreadChannels, - this.lastEventAt, - this.lastSyncAt}); + /// Id of the last read message + final String? lastReadMessageId; + const ReadEntity( + {required this.lastRead, + required this.userId, + required this.channelCid, + required this.unreadMessages, + this.lastReadMessageId}); @override Map toColumns(bool nullToAbsent) { final map = {}; - map['id'] = Variable(id); - map['type'] = Variable(type); - if (!nullToAbsent || ownUser != null) { - map['own_user'] = Variable( - $ConnectionEventsTable.$converterownUsern.toSql(ownUser)); - } - if (!nullToAbsent || totalUnreadCount != null) { - map['total_unread_count'] = Variable(totalUnreadCount); - } - if (!nullToAbsent || unreadChannels != null) { - map['unread_channels'] = Variable(unreadChannels); - } - if (!nullToAbsent || lastEventAt != null) { - map['last_event_at'] = Variable(lastEventAt); - } - if (!nullToAbsent || lastSyncAt != null) { - map['last_sync_at'] = Variable(lastSyncAt); + map['last_read'] = Variable(lastRead); + map['user_id'] = Variable(userId); + map['channel_cid'] = Variable(channelCid); + map['unread_messages'] = Variable(unreadMessages); + if (!nullToAbsent || lastReadMessageId != null) { + map['last_read_message_id'] = Variable(lastReadMessageId); } return map; } - factory ConnectionEventEntity.fromJson(Map json, + factory ReadEntity.fromJson(Map json, {ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; - return ConnectionEventEntity( - id: serializer.fromJson(json['id']), - type: serializer.fromJson(json['type']), - ownUser: serializer.fromJson?>(json['ownUser']), - totalUnreadCount: serializer.fromJson(json['totalUnreadCount']), - unreadChannels: serializer.fromJson(json['unreadChannels']), - lastEventAt: serializer.fromJson(json['lastEventAt']), - lastSyncAt: serializer.fromJson(json['lastSyncAt']), + return ReadEntity( + lastRead: serializer.fromJson(json['lastRead']), + userId: serializer.fromJson(json['userId']), + channelCid: serializer.fromJson(json['channelCid']), + unreadMessages: serializer.fromJson(json['unreadMessages']), + lastReadMessageId: + serializer.fromJson(json['lastReadMessageId']), ); } @override Map toJson({ValueSerializer? serializer}) { serializer ??= driftRuntimeOptions.defaultSerializer; return { - 'id': serializer.toJson(id), - 'type': serializer.toJson(type), - 'ownUser': serializer.toJson?>(ownUser), - 'totalUnreadCount': serializer.toJson(totalUnreadCount), - 'unreadChannels': serializer.toJson(unreadChannels), - 'lastEventAt': serializer.toJson(lastEventAt), - 'lastSyncAt': serializer.toJson(lastSyncAt), + 'lastRead': serializer.toJson(lastRead), + 'userId': serializer.toJson(userId), + 'channelCid': serializer.toJson(channelCid), + 'unreadMessages': serializer.toJson(unreadMessages), + 'lastReadMessageId': serializer.toJson(lastReadMessageId), }; } - ConnectionEventEntity copyWith( - {int? id, - String? type, - Value?> ownUser = const Value.absent(), - Value totalUnreadCount = const Value.absent(), - Value unreadChannels = const Value.absent(), - Value lastEventAt = const Value.absent(), - Value lastSyncAt = const Value.absent()}) => - ConnectionEventEntity( - id: id ?? this.id, - type: type ?? this.type, - ownUser: ownUser.present ? ownUser.value : this.ownUser, - totalUnreadCount: totalUnreadCount.present - ? totalUnreadCount.value - : this.totalUnreadCount, - unreadChannels: - unreadChannels.present ? unreadChannels.value : this.unreadChannels, - lastEventAt: lastEventAt.present ? lastEventAt.value : this.lastEventAt, - lastSyncAt: lastSyncAt.present ? lastSyncAt.value : this.lastSyncAt, + ReadEntity copyWith( + {DateTime? lastRead, + String? userId, + String? channelCid, + int? unreadMessages, + Value lastReadMessageId = const Value.absent()}) => + ReadEntity( + lastRead: lastRead ?? this.lastRead, + userId: userId ?? this.userId, + channelCid: channelCid ?? this.channelCid, + unreadMessages: unreadMessages ?? this.unreadMessages, + lastReadMessageId: lastReadMessageId.present + ? lastReadMessageId.value + : this.lastReadMessageId, ); - ConnectionEventEntity copyWithCompanion(ConnectionEventsCompanion data) { - return ConnectionEventEntity( - id: data.id.present ? data.id.value : this.id, - type: data.type.present ? data.type.value : this.type, - ownUser: data.ownUser.present ? data.ownUser.value : this.ownUser, - totalUnreadCount: data.totalUnreadCount.present - ? data.totalUnreadCount.value - : this.totalUnreadCount, - unreadChannels: data.unreadChannels.present - ? data.unreadChannels.value - : this.unreadChannels, - lastEventAt: - data.lastEventAt.present ? data.lastEventAt.value : this.lastEventAt, - lastSyncAt: - data.lastSyncAt.present ? data.lastSyncAt.value : this.lastSyncAt, + ReadEntity copyWithCompanion(ReadsCompanion data) { + return ReadEntity( + lastRead: data.lastRead.present ? data.lastRead.value : this.lastRead, + userId: data.userId.present ? data.userId.value : this.userId, + channelCid: + data.channelCid.present ? data.channelCid.value : this.channelCid, + unreadMessages: data.unreadMessages.present + ? data.unreadMessages.value + : this.unreadMessages, + lastReadMessageId: data.lastReadMessageId.present + ? data.lastReadMessageId.value + : this.lastReadMessageId, ); } @override String toString() { - return (StringBuffer('ConnectionEventEntity(') - ..write('id: $id, ') - ..write('type: $type, ') - ..write('ownUser: $ownUser, ') - ..write('totalUnreadCount: $totalUnreadCount, ') - ..write('unreadChannels: $unreadChannels, ') - ..write('lastEventAt: $lastEventAt, ') - ..write('lastSyncAt: $lastSyncAt') + return (StringBuffer('ReadEntity(') + ..write('lastRead: $lastRead, ') + ..write('userId: $userId, ') + ..write('channelCid: $channelCid, ') + ..write('unreadMessages: $unreadMessages, ') + ..write('lastReadMessageId: $lastReadMessageId') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(id, type, ownUser, totalUnreadCount, - unreadChannels, lastEventAt, lastSyncAt); + int get hashCode => Object.hash( + lastRead, userId, channelCid, unreadMessages, lastReadMessageId); @override bool operator ==(Object other) => identical(this, other) || - (other is ConnectionEventEntity && - other.id == this.id && - other.type == this.type && - other.ownUser == this.ownUser && - other.totalUnreadCount == this.totalUnreadCount && - other.unreadChannels == this.unreadChannels && - other.lastEventAt == this.lastEventAt && - other.lastSyncAt == this.lastSyncAt); + (other is ReadEntity && + other.lastRead == this.lastRead && + other.userId == this.userId && + other.channelCid == this.channelCid && + other.unreadMessages == this.unreadMessages && + other.lastReadMessageId == this.lastReadMessageId); } -class ConnectionEventsCompanion extends UpdateCompanion { - final Value id; - final Value type; - final Value?> ownUser; - final Value totalUnreadCount; - final Value unreadChannels; - final Value lastEventAt; - final Value lastSyncAt; - const ConnectionEventsCompanion({ - this.id = const Value.absent(), - this.type = const Value.absent(), - this.ownUser = const Value.absent(), - this.totalUnreadCount = const Value.absent(), - this.unreadChannels = const Value.absent(), - this.lastEventAt = const Value.absent(), - this.lastSyncAt = const Value.absent(), +class ReadsCompanion extends UpdateCompanion { + final Value lastRead; + final Value userId; + final Value channelCid; + final Value unreadMessages; + final Value lastReadMessageId; + final Value rowid; + const ReadsCompanion({ + this.lastRead = const Value.absent(), + this.userId = const Value.absent(), + this.channelCid = const Value.absent(), + this.unreadMessages = const Value.absent(), + this.lastReadMessageId = const Value.absent(), + this.rowid = const Value.absent(), }); - ConnectionEventsCompanion.insert({ - this.id = const Value.absent(), - required String type, - this.ownUser = const Value.absent(), - this.totalUnreadCount = const Value.absent(), - this.unreadChannels = const Value.absent(), - this.lastEventAt = const Value.absent(), - this.lastSyncAt = const Value.absent(), - }) : type = Value(type); - static Insertable custom({ - Expression? id, - Expression? type, - Expression? ownUser, - Expression? totalUnreadCount, - Expression? unreadChannels, - Expression? lastEventAt, - Expression? lastSyncAt, + ReadsCompanion.insert({ + required DateTime lastRead, + required String userId, + required String channelCid, + this.unreadMessages = const Value.absent(), + this.lastReadMessageId = const Value.absent(), + this.rowid = const Value.absent(), + }) : lastRead = Value(lastRead), + userId = Value(userId), + channelCid = Value(channelCid); + static Insertable custom({ + Expression? lastRead, + Expression? userId, + Expression? channelCid, + Expression? unreadMessages, + Expression? lastReadMessageId, + Expression? rowid, }) { return RawValuesInsertable({ - if (id != null) 'id': id, - if (type != null) 'type': type, - if (ownUser != null) 'own_user': ownUser, - if (totalUnreadCount != null) 'total_unread_count': totalUnreadCount, - if (unreadChannels != null) 'unread_channels': unreadChannels, - if (lastEventAt != null) 'last_event_at': lastEventAt, - if (lastSyncAt != null) 'last_sync_at': lastSyncAt, + if (lastRead != null) 'last_read': lastRead, + if (userId != null) 'user_id': userId, + if (channelCid != null) 'channel_cid': channelCid, + if (unreadMessages != null) 'unread_messages': unreadMessages, + if (lastReadMessageId != null) 'last_read_message_id': lastReadMessageId, + if (rowid != null) 'rowid': rowid, }); } - ConnectionEventsCompanion copyWith( - {Value? id, - Value? type, - Value?>? ownUser, - Value? totalUnreadCount, - Value? unreadChannels, - Value? lastEventAt, - Value? lastSyncAt}) { - return ConnectionEventsCompanion( - id: id ?? this.id, - type: type ?? this.type, - ownUser: ownUser ?? this.ownUser, - totalUnreadCount: totalUnreadCount ?? this.totalUnreadCount, - unreadChannels: unreadChannels ?? this.unreadChannels, - lastEventAt: lastEventAt ?? this.lastEventAt, - lastSyncAt: lastSyncAt ?? this.lastSyncAt, + ReadsCompanion copyWith( + {Value? lastRead, + Value? userId, + Value? channelCid, + Value? unreadMessages, + Value? lastReadMessageId, + Value? rowid}) { + return ReadsCompanion( + lastRead: lastRead ?? this.lastRead, + userId: userId ?? this.userId, + channelCid: channelCid ?? this.channelCid, + unreadMessages: unreadMessages ?? this.unreadMessages, + lastReadMessageId: lastReadMessageId ?? this.lastReadMessageId, + rowid: rowid ?? this.rowid, ); } @override Map toColumns(bool nullToAbsent) { final map = {}; - if (id.present) { - map['id'] = Variable(id.value); - } - if (type.present) { - map['type'] = Variable(type.value); + if (lastRead.present) { + map['last_read'] = Variable(lastRead.value); } - if (ownUser.present) { - map['own_user'] = Variable( - $ConnectionEventsTable.$converterownUsern.toSql(ownUser.value)); + if (userId.present) { + map['user_id'] = Variable(userId.value); } - if (totalUnreadCount.present) { - map['total_unread_count'] = Variable(totalUnreadCount.value); + if (channelCid.present) { + map['channel_cid'] = Variable(channelCid.value); } - if (unreadChannels.present) { - map['unread_channels'] = Variable(unreadChannels.value); + if (unreadMessages.present) { + map['unread_messages'] = Variable(unreadMessages.value); } - if (lastEventAt.present) { - map['last_event_at'] = Variable(lastEventAt.value); + if (lastReadMessageId.present) { + map['last_read_message_id'] = Variable(lastReadMessageId.value); } - if (lastSyncAt.present) { - map['last_sync_at'] = Variable(lastSyncAt.value); + if (rowid.present) { + map['rowid'] = Variable(rowid.value); } return map; } @override String toString() { - return (StringBuffer('ConnectionEventsCompanion(') - ..write('id: $id, ') - ..write('type: $type, ') - ..write('ownUser: $ownUser, ') - ..write('totalUnreadCount: $totalUnreadCount, ') - ..write('unreadChannels: $unreadChannels, ') - ..write('lastEventAt: $lastEventAt, ') - ..write('lastSyncAt: $lastSyncAt') + return (StringBuffer('ReadsCompanion(') + ..write('lastRead: $lastRead, ') + ..write('userId: $userId, ') + ..write('channelCid: $channelCid, ') + ..write('unreadMessages: $unreadMessages, ') + ..write('lastReadMessageId: $lastReadMessageId, ') + ..write('rowid: $rowid') ..write(')')) .toString(); } } -abstract class _$DriftChatDatabase extends GeneratedDatabase { - _$DriftChatDatabase(QueryExecutor e) : super(e); - $DriftChatDatabaseManager get managers => $DriftChatDatabaseManager(this); - late final $ChannelsTable channels = $ChannelsTable(this); - late final $MessagesTable messages = $MessagesTable(this); - late final $PinnedMessagesTable pinnedMessages = $PinnedMessagesTable(this); - late final $PinnedMessageReactionsTable pinnedMessageReactions = - $PinnedMessageReactionsTable(this); - late final $ReactionsTable reactions = $ReactionsTable(this); - late final $UsersTable users = $UsersTable(this); - late final $MembersTable members = $MembersTable(this); - late final $ReadsTable reads = $ReadsTable(this); - late final $ChannelQueriesTable channelQueries = $ChannelQueriesTable(this); - late final $ConnectionEventsTable connectionEvents = - $ConnectionEventsTable(this); - late final UserDao userDao = UserDao(this as DriftChatDatabase); - late final ChannelDao channelDao = ChannelDao(this as DriftChatDatabase); - late final MessageDao messageDao = MessageDao(this as DriftChatDatabase); - late final PinnedMessageDao pinnedMessageDao = - PinnedMessageDao(this as DriftChatDatabase); - late final PinnedMessageReactionDao pinnedMessageReactionDao = - PinnedMessageReactionDao(this as DriftChatDatabase); - late final MemberDao memberDao = MemberDao(this as DriftChatDatabase); - late final ReactionDao reactionDao = ReactionDao(this as DriftChatDatabase); - late final ReadDao readDao = ReadDao(this as DriftChatDatabase); - late final ChannelQueryDao channelQueryDao = - ChannelQueryDao(this as DriftChatDatabase); - late final ConnectionEventDao connectionEventDao = - ConnectionEventDao(this as DriftChatDatabase); +class $ChannelQueriesTable extends ChannelQueries + with TableInfo<$ChannelQueriesTable, ChannelQueryEntity> { @override - Iterable> get allTables => - allSchemaEntities.whereType>(); + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ChannelQueriesTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _queryHashMeta = + const VerificationMeta('queryHash'); @override - List get allSchemaEntities => [ - channels, - messages, - pinnedMessages, - pinnedMessageReactions, - reactions, - users, - members, - reads, - channelQueries, - connectionEvents - ]; + late final GeneratedColumn queryHash = GeneratedColumn( + 'query_hash', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _channelCidMeta = + const VerificationMeta('channelCid'); @override - StreamQueryUpdateRules get streamUpdateRules => const StreamQueryUpdateRules( - [ - WritePropagation( - on: TableUpdateQuery.onTableName('channels', - limitUpdateKind: UpdateKind.delete), - result: [ - TableUpdate('messages', kind: UpdateKind.delete), - ], - ), - WritePropagation( - on: TableUpdateQuery.onTableName('pinned_messages', - limitUpdateKind: UpdateKind.delete), - result: [ - TableUpdate('pinned_message_reactions', kind: UpdateKind.delete), - ], - ), - WritePropagation( - on: TableUpdateQuery.onTableName('messages', - limitUpdateKind: UpdateKind.delete), - result: [ - TableUpdate('reactions', kind: UpdateKind.delete), - ], - ), - WritePropagation( - on: TableUpdateQuery.onTableName('channels', - limitUpdateKind: UpdateKind.delete), - result: [ - TableUpdate('members', kind: UpdateKind.delete), - ], - ), - WritePropagation( - on: TableUpdateQuery.onTableName('channels', - limitUpdateKind: UpdateKind.delete), - result: [ - TableUpdate('reads', kind: UpdateKind.delete), - ], - ), - ], - ); + late final GeneratedColumn channelCid = GeneratedColumn( + 'channel_cid', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); + @override + List get $columns => [queryHash, channelCid]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'channel_queries'; + @override + VerificationContext validateIntegrity(Insertable instance, + {bool isInserting = false}) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('query_hash')) { + context.handle(_queryHashMeta, + queryHash.isAcceptableOrUnknown(data['query_hash']!, _queryHashMeta)); + } else if (isInserting) { + context.missing(_queryHashMeta); + } + if (data.containsKey('channel_cid')) { + context.handle( + _channelCidMeta, + channelCid.isAcceptableOrUnknown( + data['channel_cid']!, _channelCidMeta)); + } else if (isInserting) { + context.missing(_channelCidMeta); + } + return context; + } + + @override + Set get $primaryKey => {queryHash, channelCid}; + @override + ChannelQueryEntity map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ChannelQueryEntity( + queryHash: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}query_hash'])!, + channelCid: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}channel_cid'])!, + ); + } + + @override + $ChannelQueriesTable createAlias(String alias) { + return $ChannelQueriesTable(attachedDatabase, alias); + } +} + +class ChannelQueryEntity extends DataClass + implements Insertable { + /// The unique hash of this query + final String queryHash; + + /// The channel cid of this query + final String channelCid; + const ChannelQueryEntity({required this.queryHash, required this.channelCid}); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['query_hash'] = Variable(queryHash); + map['channel_cid'] = Variable(channelCid); + return map; + } + + factory ChannelQueryEntity.fromJson(Map json, + {ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ChannelQueryEntity( + queryHash: serializer.fromJson(json['queryHash']), + channelCid: serializer.fromJson(json['channelCid']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'queryHash': serializer.toJson(queryHash), + 'channelCid': serializer.toJson(channelCid), + }; + } + + ChannelQueryEntity copyWith({String? queryHash, String? channelCid}) => + ChannelQueryEntity( + queryHash: queryHash ?? this.queryHash, + channelCid: channelCid ?? this.channelCid, + ); + ChannelQueryEntity copyWithCompanion(ChannelQueriesCompanion data) { + return ChannelQueryEntity( + queryHash: data.queryHash.present ? data.queryHash.value : this.queryHash, + channelCid: + data.channelCid.present ? data.channelCid.value : this.channelCid, + ); + } + + @override + String toString() { + return (StringBuffer('ChannelQueryEntity(') + ..write('queryHash: $queryHash, ') + ..write('channelCid: $channelCid') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(queryHash, channelCid); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ChannelQueryEntity && + other.queryHash == this.queryHash && + other.channelCid == this.channelCid); +} + +class ChannelQueriesCompanion extends UpdateCompanion { + final Value queryHash; + final Value channelCid; + final Value rowid; + const ChannelQueriesCompanion({ + this.queryHash = const Value.absent(), + this.channelCid = const Value.absent(), + this.rowid = const Value.absent(), + }); + ChannelQueriesCompanion.insert({ + required String queryHash, + required String channelCid, + this.rowid = const Value.absent(), + }) : queryHash = Value(queryHash), + channelCid = Value(channelCid); + static Insertable custom({ + Expression? queryHash, + Expression? channelCid, + Expression? rowid, + }) { + return RawValuesInsertable({ + if (queryHash != null) 'query_hash': queryHash, + if (channelCid != null) 'channel_cid': channelCid, + if (rowid != null) 'rowid': rowid, + }); + } + + ChannelQueriesCompanion copyWith( + {Value? queryHash, + Value? channelCid, + Value? rowid}) { + return ChannelQueriesCompanion( + queryHash: queryHash ?? this.queryHash, + channelCid: channelCid ?? this.channelCid, + rowid: rowid ?? this.rowid, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (queryHash.present) { + map['query_hash'] = Variable(queryHash.value); + } + if (channelCid.present) { + map['channel_cid'] = Variable(channelCid.value); + } + if (rowid.present) { + map['rowid'] = Variable(rowid.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ChannelQueriesCompanion(') + ..write('queryHash: $queryHash, ') + ..write('channelCid: $channelCid, ') + ..write('rowid: $rowid') + ..write(')')) + .toString(); + } +} + +class $ConnectionEventsTable extends ConnectionEvents + with TableInfo<$ConnectionEventsTable, ConnectionEventEntity> { + @override + final GeneratedDatabase attachedDatabase; + final String? _alias; + $ConnectionEventsTable(this.attachedDatabase, [this._alias]); + static const VerificationMeta _idMeta = const VerificationMeta('id'); + @override + late final GeneratedColumn id = GeneratedColumn( + 'id', aliasedName, false, + type: DriftSqlType.int, requiredDuringInsert: false); + static const VerificationMeta _typeMeta = const VerificationMeta('type'); + @override + late final GeneratedColumn type = GeneratedColumn( + 'type', aliasedName, false, + type: DriftSqlType.string, requiredDuringInsert: true); + static const VerificationMeta _ownUserMeta = + const VerificationMeta('ownUser'); + @override + late final GeneratedColumnWithTypeConverter?, String> + ownUser = GeneratedColumn('own_user', aliasedName, true, + type: DriftSqlType.string, requiredDuringInsert: false) + .withConverter?>( + $ConnectionEventsTable.$converterownUsern); + static const VerificationMeta _totalUnreadCountMeta = + const VerificationMeta('totalUnreadCount'); + @override + late final GeneratedColumn totalUnreadCount = GeneratedColumn( + 'total_unread_count', aliasedName, true, + type: DriftSqlType.int, requiredDuringInsert: false); + static const VerificationMeta _unreadChannelsMeta = + const VerificationMeta('unreadChannels'); + @override + late final GeneratedColumn unreadChannels = GeneratedColumn( + 'unread_channels', aliasedName, true, + type: DriftSqlType.int, requiredDuringInsert: false); + static const VerificationMeta _lastEventAtMeta = + const VerificationMeta('lastEventAt'); + @override + late final GeneratedColumn lastEventAt = GeneratedColumn( + 'last_event_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + static const VerificationMeta _lastSyncAtMeta = + const VerificationMeta('lastSyncAt'); + @override + late final GeneratedColumn lastSyncAt = GeneratedColumn( + 'last_sync_at', aliasedName, true, + type: DriftSqlType.dateTime, requiredDuringInsert: false); + @override + List get $columns => [ + id, + type, + ownUser, + totalUnreadCount, + unreadChannels, + lastEventAt, + lastSyncAt + ]; + @override + String get aliasedName => _alias ?? actualTableName; + @override + String get actualTableName => $name; + static const String $name = 'connection_events'; + @override + VerificationContext validateIntegrity( + Insertable instance, + {bool isInserting = false}) { + final context = VerificationContext(); + final data = instance.toColumns(true); + if (data.containsKey('id')) { + context.handle(_idMeta, id.isAcceptableOrUnknown(data['id']!, _idMeta)); + } + if (data.containsKey('type')) { + context.handle( + _typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta)); + } else if (isInserting) { + context.missing(_typeMeta); + } + context.handle(_ownUserMeta, const VerificationResult.success()); + if (data.containsKey('total_unread_count')) { + context.handle( + _totalUnreadCountMeta, + totalUnreadCount.isAcceptableOrUnknown( + data['total_unread_count']!, _totalUnreadCountMeta)); + } + if (data.containsKey('unread_channels')) { + context.handle( + _unreadChannelsMeta, + unreadChannels.isAcceptableOrUnknown( + data['unread_channels']!, _unreadChannelsMeta)); + } + if (data.containsKey('last_event_at')) { + context.handle( + _lastEventAtMeta, + lastEventAt.isAcceptableOrUnknown( + data['last_event_at']!, _lastEventAtMeta)); + } + if (data.containsKey('last_sync_at')) { + context.handle( + _lastSyncAtMeta, + lastSyncAt.isAcceptableOrUnknown( + data['last_sync_at']!, _lastSyncAtMeta)); + } + return context; + } + + @override + Set get $primaryKey => {id}; + @override + ConnectionEventEntity map(Map data, {String? tablePrefix}) { + final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : ''; + return ConnectionEventEntity( + id: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}id'])!, + type: attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}type'])!, + ownUser: $ConnectionEventsTable.$converterownUsern.fromSql( + attachedDatabase.typeMapping + .read(DriftSqlType.string, data['${effectivePrefix}own_user'])), + totalUnreadCount: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}total_unread_count']), + unreadChannels: attachedDatabase.typeMapping + .read(DriftSqlType.int, data['${effectivePrefix}unread_channels']), + lastEventAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}last_event_at']), + lastSyncAt: attachedDatabase.typeMapping + .read(DriftSqlType.dateTime, data['${effectivePrefix}last_sync_at']), + ); + } + + @override + $ConnectionEventsTable createAlias(String alias) { + return $ConnectionEventsTable(attachedDatabase, alias); + } + + static TypeConverter, String> $converterownUser = + MapConverter(); + static TypeConverter?, String?> $converterownUsern = + NullAwareTypeConverter.wrap($converterownUser); +} + +class ConnectionEventEntity extends DataClass + implements Insertable { + /// event id + final int id; + + /// event type + final String type; + + /// User object of the current user + final Map? ownUser; + + /// The number of unread messages for current user + final int? totalUnreadCount; + + /// User total unread channels for current user + final int? unreadChannels; + + /// DateTime of the last event + final DateTime? lastEventAt; + + /// DateTime of the last sync + final DateTime? lastSyncAt; + const ConnectionEventEntity( + {required this.id, + required this.type, + this.ownUser, + this.totalUnreadCount, + this.unreadChannels, + this.lastEventAt, + this.lastSyncAt}); + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + map['id'] = Variable(id); + map['type'] = Variable(type); + if (!nullToAbsent || ownUser != null) { + map['own_user'] = Variable( + $ConnectionEventsTable.$converterownUsern.toSql(ownUser)); + } + if (!nullToAbsent || totalUnreadCount != null) { + map['total_unread_count'] = Variable(totalUnreadCount); + } + if (!nullToAbsent || unreadChannels != null) { + map['unread_channels'] = Variable(unreadChannels); + } + if (!nullToAbsent || lastEventAt != null) { + map['last_event_at'] = Variable(lastEventAt); + } + if (!nullToAbsent || lastSyncAt != null) { + map['last_sync_at'] = Variable(lastSyncAt); + } + return map; + } + + factory ConnectionEventEntity.fromJson(Map json, + {ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return ConnectionEventEntity( + id: serializer.fromJson(json['id']), + type: serializer.fromJson(json['type']), + ownUser: serializer.fromJson?>(json['ownUser']), + totalUnreadCount: serializer.fromJson(json['totalUnreadCount']), + unreadChannels: serializer.fromJson(json['unreadChannels']), + lastEventAt: serializer.fromJson(json['lastEventAt']), + lastSyncAt: serializer.fromJson(json['lastSyncAt']), + ); + } + @override + Map toJson({ValueSerializer? serializer}) { + serializer ??= driftRuntimeOptions.defaultSerializer; + return { + 'id': serializer.toJson(id), + 'type': serializer.toJson(type), + 'ownUser': serializer.toJson?>(ownUser), + 'totalUnreadCount': serializer.toJson(totalUnreadCount), + 'unreadChannels': serializer.toJson(unreadChannels), + 'lastEventAt': serializer.toJson(lastEventAt), + 'lastSyncAt': serializer.toJson(lastSyncAt), + }; + } + + ConnectionEventEntity copyWith( + {int? id, + String? type, + Value?> ownUser = const Value.absent(), + Value totalUnreadCount = const Value.absent(), + Value unreadChannels = const Value.absent(), + Value lastEventAt = const Value.absent(), + Value lastSyncAt = const Value.absent()}) => + ConnectionEventEntity( + id: id ?? this.id, + type: type ?? this.type, + ownUser: ownUser.present ? ownUser.value : this.ownUser, + totalUnreadCount: totalUnreadCount.present + ? totalUnreadCount.value + : this.totalUnreadCount, + unreadChannels: + unreadChannels.present ? unreadChannels.value : this.unreadChannels, + lastEventAt: lastEventAt.present ? lastEventAt.value : this.lastEventAt, + lastSyncAt: lastSyncAt.present ? lastSyncAt.value : this.lastSyncAt, + ); + ConnectionEventEntity copyWithCompanion(ConnectionEventsCompanion data) { + return ConnectionEventEntity( + id: data.id.present ? data.id.value : this.id, + type: data.type.present ? data.type.value : this.type, + ownUser: data.ownUser.present ? data.ownUser.value : this.ownUser, + totalUnreadCount: data.totalUnreadCount.present + ? data.totalUnreadCount.value + : this.totalUnreadCount, + unreadChannels: data.unreadChannels.present + ? data.unreadChannels.value + : this.unreadChannels, + lastEventAt: + data.lastEventAt.present ? data.lastEventAt.value : this.lastEventAt, + lastSyncAt: + data.lastSyncAt.present ? data.lastSyncAt.value : this.lastSyncAt, + ); + } + + @override + String toString() { + return (StringBuffer('ConnectionEventEntity(') + ..write('id: $id, ') + ..write('type: $type, ') + ..write('ownUser: $ownUser, ') + ..write('totalUnreadCount: $totalUnreadCount, ') + ..write('unreadChannels: $unreadChannels, ') + ..write('lastEventAt: $lastEventAt, ') + ..write('lastSyncAt: $lastSyncAt') + ..write(')')) + .toString(); + } + + @override + int get hashCode => Object.hash(id, type, ownUser, totalUnreadCount, + unreadChannels, lastEventAt, lastSyncAt); + @override + bool operator ==(Object other) => + identical(this, other) || + (other is ConnectionEventEntity && + other.id == this.id && + other.type == this.type && + other.ownUser == this.ownUser && + other.totalUnreadCount == this.totalUnreadCount && + other.unreadChannels == this.unreadChannels && + other.lastEventAt == this.lastEventAt && + other.lastSyncAt == this.lastSyncAt); +} + +class ConnectionEventsCompanion extends UpdateCompanion { + final Value id; + final Value type; + final Value?> ownUser; + final Value totalUnreadCount; + final Value unreadChannels; + final Value lastEventAt; + final Value lastSyncAt; + const ConnectionEventsCompanion({ + this.id = const Value.absent(), + this.type = const Value.absent(), + this.ownUser = const Value.absent(), + this.totalUnreadCount = const Value.absent(), + this.unreadChannels = const Value.absent(), + this.lastEventAt = const Value.absent(), + this.lastSyncAt = const Value.absent(), + }); + ConnectionEventsCompanion.insert({ + this.id = const Value.absent(), + required String type, + this.ownUser = const Value.absent(), + this.totalUnreadCount = const Value.absent(), + this.unreadChannels = const Value.absent(), + this.lastEventAt = const Value.absent(), + this.lastSyncAt = const Value.absent(), + }) : type = Value(type); + static Insertable custom({ + Expression? id, + Expression? type, + Expression? ownUser, + Expression? totalUnreadCount, + Expression? unreadChannels, + Expression? lastEventAt, + Expression? lastSyncAt, + }) { + return RawValuesInsertable({ + if (id != null) 'id': id, + if (type != null) 'type': type, + if (ownUser != null) 'own_user': ownUser, + if (totalUnreadCount != null) 'total_unread_count': totalUnreadCount, + if (unreadChannels != null) 'unread_channels': unreadChannels, + if (lastEventAt != null) 'last_event_at': lastEventAt, + if (lastSyncAt != null) 'last_sync_at': lastSyncAt, + }); + } + + ConnectionEventsCompanion copyWith( + {Value? id, + Value? type, + Value?>? ownUser, + Value? totalUnreadCount, + Value? unreadChannels, + Value? lastEventAt, + Value? lastSyncAt}) { + return ConnectionEventsCompanion( + id: id ?? this.id, + type: type ?? this.type, + ownUser: ownUser ?? this.ownUser, + totalUnreadCount: totalUnreadCount ?? this.totalUnreadCount, + unreadChannels: unreadChannels ?? this.unreadChannels, + lastEventAt: lastEventAt ?? this.lastEventAt, + lastSyncAt: lastSyncAt ?? this.lastSyncAt, + ); + } + + @override + Map toColumns(bool nullToAbsent) { + final map = {}; + if (id.present) { + map['id'] = Variable(id.value); + } + if (type.present) { + map['type'] = Variable(type.value); + } + if (ownUser.present) { + map['own_user'] = Variable( + $ConnectionEventsTable.$converterownUsern.toSql(ownUser.value)); + } + if (totalUnreadCount.present) { + map['total_unread_count'] = Variable(totalUnreadCount.value); + } + if (unreadChannels.present) { + map['unread_channels'] = Variable(unreadChannels.value); + } + if (lastEventAt.present) { + map['last_event_at'] = Variable(lastEventAt.value); + } + if (lastSyncAt.present) { + map['last_sync_at'] = Variable(lastSyncAt.value); + } + return map; + } + + @override + String toString() { + return (StringBuffer('ConnectionEventsCompanion(') + ..write('id: $id, ') + ..write('type: $type, ') + ..write('ownUser: $ownUser, ') + ..write('totalUnreadCount: $totalUnreadCount, ') + ..write('unreadChannels: $unreadChannels, ') + ..write('lastEventAt: $lastEventAt, ') + ..write('lastSyncAt: $lastSyncAt') + ..write(')')) + .toString(); + } +} + +abstract class _$DriftChatDatabase extends GeneratedDatabase { + _$DriftChatDatabase(QueryExecutor e) : super(e); + $DriftChatDatabaseManager get managers => $DriftChatDatabaseManager(this); + late final $ChannelsTable channels = $ChannelsTable(this); + late final $MessagesTable messages = $MessagesTable(this); + late final $PinnedMessagesTable pinnedMessages = $PinnedMessagesTable(this); + late final $PollsTable polls = $PollsTable(this); + late final $PollVotesTable pollVotes = $PollVotesTable(this); + late final $PinnedMessageReactionsTable pinnedMessageReactions = + $PinnedMessageReactionsTable(this); + late final $ReactionsTable reactions = $ReactionsTable(this); + late final $UsersTable users = $UsersTable(this); + late final $MembersTable members = $MembersTable(this); + late final $ReadsTable reads = $ReadsTable(this); + late final $ChannelQueriesTable channelQueries = $ChannelQueriesTable(this); + late final $ConnectionEventsTable connectionEvents = + $ConnectionEventsTable(this); + late final UserDao userDao = UserDao(this as DriftChatDatabase); + late final ChannelDao channelDao = ChannelDao(this as DriftChatDatabase); + late final MessageDao messageDao = MessageDao(this as DriftChatDatabase); + late final PinnedMessageDao pinnedMessageDao = + PinnedMessageDao(this as DriftChatDatabase); + late final PinnedMessageReactionDao pinnedMessageReactionDao = + PinnedMessageReactionDao(this as DriftChatDatabase); + late final MemberDao memberDao = MemberDao(this as DriftChatDatabase); + late final PollDao pollDao = PollDao(this as DriftChatDatabase); + late final PollVoteDao pollVoteDao = PollVoteDao(this as DriftChatDatabase); + late final ReactionDao reactionDao = ReactionDao(this as DriftChatDatabase); + late final ReadDao readDao = ReadDao(this as DriftChatDatabase); + late final ChannelQueryDao channelQueryDao = + ChannelQueryDao(this as DriftChatDatabase); + late final ConnectionEventDao connectionEventDao = + ConnectionEventDao(this as DriftChatDatabase); + @override + Iterable> get allTables => + allSchemaEntities.whereType>(); + @override + List get allSchemaEntities => [ + channels, + messages, + pinnedMessages, + polls, + pollVotes, + pinnedMessageReactions, + reactions, + users, + members, + reads, + channelQueries, + connectionEvents + ]; + @override + StreamQueryUpdateRules get streamUpdateRules => const StreamQueryUpdateRules( + [ + WritePropagation( + on: TableUpdateQuery.onTableName('channels', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('messages', kind: UpdateKind.delete), + ], + ), + WritePropagation( + on: TableUpdateQuery.onTableName('polls', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('poll_votes', kind: UpdateKind.delete), + ], + ), + WritePropagation( + on: TableUpdateQuery.onTableName('pinned_messages', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('pinned_message_reactions', kind: UpdateKind.delete), + ], + ), + WritePropagation( + on: TableUpdateQuery.onTableName('messages', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('reactions', kind: UpdateKind.delete), + ], + ), + WritePropagation( + on: TableUpdateQuery.onTableName('channels', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('members', kind: UpdateKind.delete), + ], + ), + WritePropagation( + on: TableUpdateQuery.onTableName('channels', + limitUpdateKind: UpdateKind.delete), + result: [ + TableUpdate('reads', kind: UpdateKind.delete), + ], + ), + ], + ); +} + +typedef $$ChannelsTableCreateCompanionBuilder = ChannelsCompanion Function({ + required String id, + required String type, + required String cid, + Value?> ownCapabilities, + required Map config, + Value frozen, + Value lastMessageAt, + Value createdAt, + Value updatedAt, + Value deletedAt, + Value memberCount, + Value createdById, + Value?> extraData, + Value rowid, +}); +typedef $$ChannelsTableUpdateCompanionBuilder = ChannelsCompanion Function({ + Value id, + Value type, + Value cid, + Value?> ownCapabilities, + Value> config, + Value frozen, + Value lastMessageAt, + Value createdAt, + Value updatedAt, + Value deletedAt, + Value memberCount, + Value createdById, + Value?> extraData, + Value rowid, +}); + +final class $$ChannelsTableReferences + extends BaseReferences<_$DriftChatDatabase, $ChannelsTable, ChannelEntity> { + $$ChannelsTableReferences(super.$_db, super.$_table, super.$_typedResult); + + static MultiTypedResultKey<$MessagesTable, List> + _messagesRefsTable(_$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.messages, + aliasName: $_aliasNameGenerator( + db.channels.cid, db.messages.channelCid)); + + $$MessagesTableProcessedTableManager get messagesRefs { + final manager = $$MessagesTableTableManager($_db, $_db.messages) + .filter((f) => f.channelCid.cid($_item.cid)); + + final cache = $_typedResult.readTableOrNull(_messagesRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } + + static MultiTypedResultKey<$MembersTable, List> + _membersRefsTable(_$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.members, + aliasName: + $_aliasNameGenerator(db.channels.cid, db.members.channelCid)); + + $$MembersTableProcessedTableManager get membersRefs { + final manager = $$MembersTableTableManager($_db, $_db.members) + .filter((f) => f.channelCid.cid($_item.cid)); + + final cache = $_typedResult.readTableOrNull(_membersRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } + + static MultiTypedResultKey<$ReadsTable, List> _readsRefsTable( + _$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.reads, + aliasName: + $_aliasNameGenerator(db.channels.cid, db.reads.channelCid)); + + $$ReadsTableProcessedTableManager get readsRefs { + final manager = $$ReadsTableTableManager($_db, $_db.reads) + .filter((f) => f.channelCid.cid($_item.cid)); + + final cache = $_typedResult.readTableOrNull(_readsRefsTable($_db)); + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: cache)); + } +} + +class $$ChannelsTableFilterComposer + extends Composer<_$DriftChatDatabase, $ChannelsTable> { + $$ChannelsTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnFilters(column)); + + ColumnFilters get type => $composableBuilder( + column: $table.type, builder: (column) => ColumnFilters(column)); + + ColumnFilters get cid => $composableBuilder( + column: $table.cid, builder: (column) => ColumnFilters(column)); + + ColumnWithTypeConverterFilters?, List, String> + get ownCapabilities => $composableBuilder( + column: $table.ownCapabilities, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnWithTypeConverterFilters, Map, + String> + get config => $composableBuilder( + column: $table.config, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnFilters get frozen => $composableBuilder( + column: $table.frozen, builder: (column) => ColumnFilters(column)); + + ColumnFilters get lastMessageAt => $composableBuilder( + column: $table.lastMessageAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get deletedAt => $composableBuilder( + column: $table.deletedAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get memberCount => $composableBuilder( + column: $table.memberCount, builder: (column) => ColumnFilters(column)); + + ColumnFilters get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => ColumnFilters(column)); + + ColumnWithTypeConverterFilters?, Map, + String> + get extraData => $composableBuilder( + column: $table.extraData, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + Expression messagesRefs( + Expression Function($$MessagesTableFilterComposer f) f) { + final $$MessagesTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.messages, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$MessagesTableFilterComposer( + $db: $db, + $table: $db.messages, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + Expression membersRefs( + Expression Function($$MembersTableFilterComposer f) f) { + final $$MembersTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.members, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$MembersTableFilterComposer( + $db: $db, + $table: $db.members, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + Expression readsRefs( + Expression Function($$ReadsTableFilterComposer f) f) { + final $$ReadsTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.reads, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$ReadsTableFilterComposer( + $db: $db, + $table: $db.reads, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } +} + +class $$ChannelsTableOrderingComposer + extends Composer<_$DriftChatDatabase, $ChannelsTable> { + $$ChannelsTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get type => $composableBuilder( + column: $table.type, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get cid => $composableBuilder( + column: $table.cid, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get ownCapabilities => $composableBuilder( + column: $table.ownCapabilities, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get config => $composableBuilder( + column: $table.config, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get frozen => $composableBuilder( + column: $table.frozen, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get lastMessageAt => $composableBuilder( + column: $table.lastMessageAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get deletedAt => $composableBuilder( + column: $table.deletedAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get memberCount => $composableBuilder( + column: $table.memberCount, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get extraData => $composableBuilder( + column: $table.extraData, builder: (column) => ColumnOrderings(column)); +} + +class $$ChannelsTableAnnotationComposer + extends Composer<_$DriftChatDatabase, $ChannelsTable> { + $$ChannelsTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => + $composableBuilder(column: $table.id, builder: (column) => column); + + GeneratedColumn get type => + $composableBuilder(column: $table.type, builder: (column) => column); + + GeneratedColumn get cid => + $composableBuilder(column: $table.cid, builder: (column) => column); + + GeneratedColumnWithTypeConverter?, String> get ownCapabilities => + $composableBuilder( + column: $table.ownCapabilities, builder: (column) => column); + + GeneratedColumnWithTypeConverter, String> get config => + $composableBuilder(column: $table.config, builder: (column) => column); + + GeneratedColumn get frozen => + $composableBuilder(column: $table.frozen, builder: (column) => column); + + GeneratedColumn get lastMessageAt => $composableBuilder( + column: $table.lastMessageAt, builder: (column) => column); + + GeneratedColumn get createdAt => + $composableBuilder(column: $table.createdAt, builder: (column) => column); + + GeneratedColumn get updatedAt => + $composableBuilder(column: $table.updatedAt, builder: (column) => column); + + GeneratedColumn get deletedAt => + $composableBuilder(column: $table.deletedAt, builder: (column) => column); + + GeneratedColumn get memberCount => $composableBuilder( + column: $table.memberCount, builder: (column) => column); + + GeneratedColumn get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => column); + + GeneratedColumnWithTypeConverter?, String> + get extraData => $composableBuilder( + column: $table.extraData, builder: (column) => column); + + Expression messagesRefs( + Expression Function($$MessagesTableAnnotationComposer a) f) { + final $$MessagesTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.messages, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$MessagesTableAnnotationComposer( + $db: $db, + $table: $db.messages, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + Expression membersRefs( + Expression Function($$MembersTableAnnotationComposer a) f) { + final $$MembersTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.members, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$MembersTableAnnotationComposer( + $db: $db, + $table: $db.members, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } + + Expression readsRefs( + Expression Function($$ReadsTableAnnotationComposer a) f) { + final $$ReadsTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.cid, + referencedTable: $db.reads, + getReferencedColumn: (t) => t.channelCid, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$ReadsTableAnnotationComposer( + $db: $db, + $table: $db.reads, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } +} + +class $$ChannelsTableTableManager extends RootTableManager< + _$DriftChatDatabase, + $ChannelsTable, + ChannelEntity, + $$ChannelsTableFilterComposer, + $$ChannelsTableOrderingComposer, + $$ChannelsTableAnnotationComposer, + $$ChannelsTableCreateCompanionBuilder, + $$ChannelsTableUpdateCompanionBuilder, + (ChannelEntity, $$ChannelsTableReferences), + ChannelEntity, + PrefetchHooks Function( + {bool messagesRefs, bool membersRefs, bool readsRefs})> { + $$ChannelsTableTableManager(_$DriftChatDatabase db, $ChannelsTable table) + : super(TableManagerState( + db: db, + table: table, + createFilteringComposer: () => + $$ChannelsTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => + $$ChannelsTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$ChannelsTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: ({ + Value id = const Value.absent(), + Value type = const Value.absent(), + Value cid = const Value.absent(), + Value?> ownCapabilities = const Value.absent(), + Value> config = const Value.absent(), + Value frozen = const Value.absent(), + Value lastMessageAt = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), + Value deletedAt = const Value.absent(), + Value memberCount = const Value.absent(), + Value createdById = const Value.absent(), + Value?> extraData = const Value.absent(), + Value rowid = const Value.absent(), + }) => + ChannelsCompanion( + id: id, + type: type, + cid: cid, + ownCapabilities: ownCapabilities, + config: config, + frozen: frozen, + lastMessageAt: lastMessageAt, + createdAt: createdAt, + updatedAt: updatedAt, + deletedAt: deletedAt, + memberCount: memberCount, + createdById: createdById, + extraData: extraData, + rowid: rowid, + ), + createCompanionCallback: ({ + required String id, + required String type, + required String cid, + Value?> ownCapabilities = const Value.absent(), + required Map config, + Value frozen = const Value.absent(), + Value lastMessageAt = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), + Value deletedAt = const Value.absent(), + Value memberCount = const Value.absent(), + Value createdById = const Value.absent(), + Value?> extraData = const Value.absent(), + Value rowid = const Value.absent(), + }) => + ChannelsCompanion.insert( + id: id, + type: type, + cid: cid, + ownCapabilities: ownCapabilities, + config: config, + frozen: frozen, + lastMessageAt: lastMessageAt, + createdAt: createdAt, + updatedAt: updatedAt, + deletedAt: deletedAt, + memberCount: memberCount, + createdById: createdById, + extraData: extraData, + rowid: rowid, + ), + withReferenceMapper: (p0) => p0 + .map((e) => + (e.readTable(table), $$ChannelsTableReferences(db, table, e))) + .toList(), + prefetchHooksCallback: ( + {messagesRefs = false, membersRefs = false, readsRefs = false}) { + return PrefetchHooks( + db: db, + explicitlyWatchedTables: [ + if (messagesRefs) db.messages, + if (membersRefs) db.members, + if (readsRefs) db.reads + ], + addJoins: null, + getPrefetchedDataCallback: (items) async { + return [ + if (messagesRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: + $$ChannelsTableReferences._messagesRefsTable(db), + managerFromTypedResult: (p0) => + $$ChannelsTableReferences(db, table, p0) + .messagesRefs, + referencedItemsForCurrentItem: + (item, referencedItems) => referencedItems + .where((e) => e.channelCid == item.cid), + typedResults: items), + if (membersRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: + $$ChannelsTableReferences._membersRefsTable(db), + managerFromTypedResult: (p0) => + $$ChannelsTableReferences(db, table, p0) + .membersRefs, + referencedItemsForCurrentItem: + (item, referencedItems) => referencedItems + .where((e) => e.channelCid == item.cid), + typedResults: items), + if (readsRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: + $$ChannelsTableReferences._readsRefsTable(db), + managerFromTypedResult: (p0) => + $$ChannelsTableReferences(db, table, p0).readsRefs, + referencedItemsForCurrentItem: + (item, referencedItems) => referencedItems + .where((e) => e.channelCid == item.cid), + typedResults: items) + ]; + }, + ); + }, + )); } -typedef $$ChannelsTableCreateCompanionBuilder = ChannelsCompanion Function({ +typedef $$ChannelsTableProcessedTableManager = ProcessedTableManager< + _$DriftChatDatabase, + $ChannelsTable, + ChannelEntity, + $$ChannelsTableFilterComposer, + $$ChannelsTableOrderingComposer, + $$ChannelsTableAnnotationComposer, + $$ChannelsTableCreateCompanionBuilder, + $$ChannelsTableUpdateCompanionBuilder, + (ChannelEntity, $$ChannelsTableReferences), + ChannelEntity, + PrefetchHooks Function( + {bool messagesRefs, bool membersRefs, bool readsRefs})>; +typedef $$MessagesTableCreateCompanionBuilder = MessagesCompanion Function({ required String id, - required String type, - required String cid, - Value?> ownCapabilities, - required Map config, - Value frozen, - Value lastMessageAt, - Value createdAt, - Value updatedAt, - Value deletedAt, - Value memberCount, - Value createdById, + Value messageText, + required List attachments, + required String state, + Value type, + required List mentionedUsers, + Value?> reactionCounts, + Value?> reactionScores, + Value parentId, + Value quotedMessageId, + Value pollId, + Value replyCount, + Value showInChannel, + Value shadowed, + Value command, + Value localCreatedAt, + Value remoteCreatedAt, + Value localUpdatedAt, + Value remoteUpdatedAt, + Value localDeletedAt, + Value remoteDeletedAt, + Value messageTextUpdatedAt, + Value userId, + Value pinned, + Value pinnedAt, + Value pinExpires, + Value pinnedByUserId, + required String channelCid, + Value?> i18n, Value?> extraData, Value rowid, }); -typedef $$ChannelsTableUpdateCompanionBuilder = ChannelsCompanion Function({ +typedef $$MessagesTableUpdateCompanionBuilder = MessagesCompanion Function({ Value id, + Value messageText, + Value> attachments, + Value state, Value type, - Value cid, - Value?> ownCapabilities, - Value> config, - Value frozen, - Value lastMessageAt, - Value createdAt, - Value updatedAt, - Value deletedAt, - Value memberCount, - Value createdById, + Value> mentionedUsers, + Value?> reactionCounts, + Value?> reactionScores, + Value parentId, + Value quotedMessageId, + Value pollId, + Value replyCount, + Value showInChannel, + Value shadowed, + Value command, + Value localCreatedAt, + Value remoteCreatedAt, + Value localUpdatedAt, + Value remoteUpdatedAt, + Value localDeletedAt, + Value remoteDeletedAt, + Value messageTextUpdatedAt, + Value userId, + Value pinned, + Value pinnedAt, + Value pinExpires, + Value pinnedByUserId, + Value channelCid, + Value?> i18n, Value?> extraData, Value rowid, }); -final class $$ChannelsTableReferences - extends BaseReferences<_$DriftChatDatabase, $ChannelsTable, ChannelEntity> { - $$ChannelsTableReferences(super.$_db, super.$_table, super.$_typedResult); - - static MultiTypedResultKey<$MessagesTable, List> - _messagesRefsTable(_$DriftChatDatabase db) => - MultiTypedResultKey.fromTable(db.messages, - aliasName: $_aliasNameGenerator( - db.channels.cid, db.messages.channelCid)); +final class $$MessagesTableReferences + extends BaseReferences<_$DriftChatDatabase, $MessagesTable, MessageEntity> { + $$MessagesTableReferences(super.$_db, super.$_table, super.$_typedResult); - $$MessagesTableProcessedTableManager get messagesRefs { - final manager = $$MessagesTableTableManager($_db, $_db.messages) - .filter((f) => f.channelCid.cid($_item.cid)); + static $ChannelsTable _channelCidTable(_$DriftChatDatabase db) => + db.channels.createAlias( + $_aliasNameGenerator(db.messages.channelCid, db.channels.cid)); - final cache = $_typedResult.readTableOrNull(_messagesRefsTable($_db)); + $$ChannelsTableProcessedTableManager get channelCid { + final manager = $$ChannelsTableTableManager($_db, $_db.channels) + .filter((f) => f.cid($_item.channelCid!)); + final item = $_typedResult.readTableOrNull(_channelCidTable($_db)); + if (item == null) return manager; return ProcessedTableManager( - manager.$state.copyWith(prefetchedData: cache)); + manager.$state.copyWith(prefetchedData: [item])); } - static MultiTypedResultKey<$MembersTable, List> - _membersRefsTable(_$DriftChatDatabase db) => - MultiTypedResultKey.fromTable(db.members, + static MultiTypedResultKey<$ReactionsTable, List> + _reactionsRefsTable(_$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.reactions, aliasName: - $_aliasNameGenerator(db.channels.cid, db.members.channelCid)); - - $$MembersTableProcessedTableManager get membersRefs { - final manager = $$MembersTableTableManager($_db, $_db.members) - .filter((f) => f.channelCid.cid($_item.cid)); - - final cache = $_typedResult.readTableOrNull(_membersRefsTable($_db)); - return ProcessedTableManager( - manager.$state.copyWith(prefetchedData: cache)); - } - - static MultiTypedResultKey<$ReadsTable, List> _readsRefsTable( - _$DriftChatDatabase db) => - MultiTypedResultKey.fromTable(db.reads, - aliasName: - $_aliasNameGenerator(db.channels.cid, db.reads.channelCid)); + $_aliasNameGenerator(db.messages.id, db.reactions.messageId)); - $$ReadsTableProcessedTableManager get readsRefs { - final manager = $$ReadsTableTableManager($_db, $_db.reads) - .filter((f) => f.channelCid.cid($_item.cid)); + $$ReactionsTableProcessedTableManager get reactionsRefs { + final manager = $$ReactionsTableTableManager($_db, $_db.reactions) + .filter((f) => f.messageId.id($_item.id)); - final cache = $_typedResult.readTableOrNull(_readsRefsTable($_db)); + final cache = $_typedResult.readTableOrNull(_reactionsRefsTable($_db)); return ProcessedTableManager( manager.$state.copyWith(prefetchedData: cache)); } } -class $$ChannelsTableFilterComposer - extends Composer<_$DriftChatDatabase, $ChannelsTable> { - $$ChannelsTableFilterComposer({ +class $$MessagesTableFilterComposer + extends Composer<_$DriftChatDatabase, $MessagesTable> { + $$MessagesTableFilterComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -6285,43 +8173,106 @@ class $$ChannelsTableFilterComposer ColumnFilters get id => $composableBuilder( column: $table.id, builder: (column) => ColumnFilters(column)); + ColumnFilters get messageText => $composableBuilder( + column: $table.messageText, builder: (column) => ColumnFilters(column)); + + ColumnWithTypeConverterFilters, List, String> + get attachments => $composableBuilder( + column: $table.attachments, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnFilters get state => $composableBuilder( + column: $table.state, builder: (column) => ColumnFilters(column)); + ColumnFilters get type => $composableBuilder( column: $table.type, builder: (column) => ColumnFilters(column)); - ColumnFilters get cid => $composableBuilder( - column: $table.cid, builder: (column) => ColumnFilters(column)); + ColumnWithTypeConverterFilters, List, String> + get mentionedUsers => $composableBuilder( + column: $table.mentionedUsers, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnWithTypeConverterFilters?, Map, String> + get reactionCounts => $composableBuilder( + column: $table.reactionCounts, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnWithTypeConverterFilters?, Map, String> + get reactionScores => $composableBuilder( + column: $table.reactionScores, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnFilters get parentId => $composableBuilder( + column: $table.parentId, builder: (column) => ColumnFilters(column)); + + ColumnFilters get quotedMessageId => $composableBuilder( + column: $table.quotedMessageId, + builder: (column) => ColumnFilters(column)); + + ColumnFilters get pollId => $composableBuilder( + column: $table.pollId, builder: (column) => ColumnFilters(column)); + + ColumnFilters get replyCount => $composableBuilder( + column: $table.replyCount, builder: (column) => ColumnFilters(column)); + + ColumnFilters get showInChannel => $composableBuilder( + column: $table.showInChannel, builder: (column) => ColumnFilters(column)); + + ColumnFilters get shadowed => $composableBuilder( + column: $table.shadowed, builder: (column) => ColumnFilters(column)); + + ColumnFilters get command => $composableBuilder( + column: $table.command, builder: (column) => ColumnFilters(column)); + + ColumnFilters get localCreatedAt => $composableBuilder( + column: $table.localCreatedAt, + builder: (column) => ColumnFilters(column)); + + ColumnFilters get remoteCreatedAt => $composableBuilder( + column: $table.remoteCreatedAt, + builder: (column) => ColumnFilters(column)); + + ColumnFilters get localUpdatedAt => $composableBuilder( + column: $table.localUpdatedAt, + builder: (column) => ColumnFilters(column)); - ColumnWithTypeConverterFilters?, List, String> - get ownCapabilities => $composableBuilder( - column: $table.ownCapabilities, - builder: (column) => ColumnWithTypeConverterFilters(column)); + ColumnFilters get remoteUpdatedAt => $composableBuilder( + column: $table.remoteUpdatedAt, + builder: (column) => ColumnFilters(column)); - ColumnWithTypeConverterFilters, Map, - String> - get config => $composableBuilder( - column: $table.config, - builder: (column) => ColumnWithTypeConverterFilters(column)); + ColumnFilters get localDeletedAt => $composableBuilder( + column: $table.localDeletedAt, + builder: (column) => ColumnFilters(column)); - ColumnFilters get frozen => $composableBuilder( - column: $table.frozen, builder: (column) => ColumnFilters(column)); + ColumnFilters get remoteDeletedAt => $composableBuilder( + column: $table.remoteDeletedAt, + builder: (column) => ColumnFilters(column)); - ColumnFilters get lastMessageAt => $composableBuilder( - column: $table.lastMessageAt, builder: (column) => ColumnFilters(column)); + ColumnFilters get messageTextUpdatedAt => $composableBuilder( + column: $table.messageTextUpdatedAt, + builder: (column) => ColumnFilters(column)); - ColumnFilters get createdAt => $composableBuilder( - column: $table.createdAt, builder: (column) => ColumnFilters(column)); + ColumnFilters get userId => $composableBuilder( + column: $table.userId, builder: (column) => ColumnFilters(column)); - ColumnFilters get updatedAt => $composableBuilder( - column: $table.updatedAt, builder: (column) => ColumnFilters(column)); + ColumnFilters get pinned => $composableBuilder( + column: $table.pinned, builder: (column) => ColumnFilters(column)); - ColumnFilters get deletedAt => $composableBuilder( - column: $table.deletedAt, builder: (column) => ColumnFilters(column)); + ColumnFilters get pinnedAt => $composableBuilder( + column: $table.pinnedAt, builder: (column) => ColumnFilters(column)); - ColumnFilters get memberCount => $composableBuilder( - column: $table.memberCount, builder: (column) => ColumnFilters(column)); + ColumnFilters get pinExpires => $composableBuilder( + column: $table.pinExpires, builder: (column) => ColumnFilters(column)); - ColumnFilters get createdById => $composableBuilder( - column: $table.createdById, builder: (column) => ColumnFilters(column)); + ColumnFilters get pinnedByUserId => $composableBuilder( + column: $table.pinnedByUserId, + builder: (column) => ColumnFilters(column)); + + ColumnWithTypeConverterFilters?, Map, + String> + get i18n => $composableBuilder( + column: $table.i18n, + builder: (column) => ColumnWithTypeConverterFilters(column)); ColumnWithTypeConverterFilters?, Map, String> @@ -6329,40 +8280,39 @@ class $$ChannelsTableFilterComposer column: $table.extraData, builder: (column) => ColumnWithTypeConverterFilters(column)); - Expression messagesRefs( - Expression Function($$MessagesTableFilterComposer f) f) { - final $$MessagesTableFilterComposer composer = $composerBuilder( + $$ChannelsTableFilterComposer get channelCid { + final $$ChannelsTableFilterComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.messages, - getReferencedColumn: (t) => t.channelCid, + getCurrentColumn: (t) => t.channelCid, + referencedTable: $db.channels, + getReferencedColumn: (t) => t.cid, builder: (joinBuilder, {$addJoinBuilderToRootComposer, $removeJoinBuilderFromRootComposer}) => - $$MessagesTableFilterComposer( + $$ChannelsTableFilterComposer( $db: $db, - $table: $db.messages, + $table: $db.channels, $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, joinBuilder: joinBuilder, $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, )); - return f(composer); + return composer; } - Expression membersRefs( - Expression Function($$MembersTableFilterComposer f) f) { - final $$MembersTableFilterComposer composer = $composerBuilder( + Expression reactionsRefs( + Expression Function($$ReactionsTableFilterComposer f) f) { + final $$ReactionsTableFilterComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.members, - getReferencedColumn: (t) => t.channelCid, + getCurrentColumn: (t) => t.id, + referencedTable: $db.reactions, + getReferencedColumn: (t) => t.messageId, builder: (joinBuilder, {$addJoinBuilderToRootComposer, $removeJoinBuilderFromRootComposer}) => - $$MembersTableFilterComposer( + $$ReactionsTableFilterComposer( $db: $db, - $table: $db.members, + $table: $db.reactions, $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, joinBuilder: joinBuilder, $removeJoinBuilderFromRootComposer: @@ -6370,185 +8320,272 @@ class $$ChannelsTableFilterComposer )); return f(composer); } +} - Expression readsRefs( - Expression Function($$ReadsTableFilterComposer f) f) { - final $$ReadsTableFilterComposer composer = $composerBuilder( +class $$MessagesTableOrderingComposer + extends Composer<_$DriftChatDatabase, $MessagesTable> { + $$MessagesTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get messageText => $composableBuilder( + column: $table.messageText, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get attachments => $composableBuilder( + column: $table.attachments, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get state => $composableBuilder( + column: $table.state, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get type => $composableBuilder( + column: $table.type, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get mentionedUsers => $composableBuilder( + column: $table.mentionedUsers, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get reactionCounts => $composableBuilder( + column: $table.reactionCounts, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get reactionScores => $composableBuilder( + column: $table.reactionScores, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get parentId => $composableBuilder( + column: $table.parentId, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get quotedMessageId => $composableBuilder( + column: $table.quotedMessageId, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get pollId => $composableBuilder( + column: $table.pollId, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get replyCount => $composableBuilder( + column: $table.replyCount, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get showInChannel => $composableBuilder( + column: $table.showInChannel, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get shadowed => $composableBuilder( + column: $table.shadowed, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get command => $composableBuilder( + column: $table.command, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get localCreatedAt => $composableBuilder( + column: $table.localCreatedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get remoteCreatedAt => $composableBuilder( + column: $table.remoteCreatedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get localUpdatedAt => $composableBuilder( + column: $table.localUpdatedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get remoteUpdatedAt => $composableBuilder( + column: $table.remoteUpdatedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get localDeletedAt => $composableBuilder( + column: $table.localDeletedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get remoteDeletedAt => $composableBuilder( + column: $table.remoteDeletedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get messageTextUpdatedAt => $composableBuilder( + column: $table.messageTextUpdatedAt, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get userId => $composableBuilder( + column: $table.userId, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get pinned => $composableBuilder( + column: $table.pinned, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get pinnedAt => $composableBuilder( + column: $table.pinnedAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get pinExpires => $composableBuilder( + column: $table.pinExpires, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get pinnedByUserId => $composableBuilder( + column: $table.pinnedByUserId, + builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get i18n => $composableBuilder( + column: $table.i18n, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get extraData => $composableBuilder( + column: $table.extraData, builder: (column) => ColumnOrderings(column)); + + $$ChannelsTableOrderingComposer get channelCid { + final $$ChannelsTableOrderingComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.reads, - getReferencedColumn: (t) => t.channelCid, + getCurrentColumn: (t) => t.channelCid, + referencedTable: $db.channels, + getReferencedColumn: (t) => t.cid, builder: (joinBuilder, {$addJoinBuilderToRootComposer, $removeJoinBuilderFromRootComposer}) => - $$ReadsTableFilterComposer( + $$ChannelsTableOrderingComposer( $db: $db, - $table: $db.reads, + $table: $db.channels, $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, joinBuilder: joinBuilder, $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, )); - return f(composer); + return composer; } } -class $$ChannelsTableOrderingComposer - extends Composer<_$DriftChatDatabase, $ChannelsTable> { - $$ChannelsTableOrderingComposer({ +class $$MessagesTableAnnotationComposer + extends Composer<_$DriftChatDatabase, $MessagesTable> { + $$MessagesTableAnnotationComposer({ required super.$db, required super.$table, super.joinBuilder, super.$addJoinBuilderToRootComposer, super.$removeJoinBuilderFromRootComposer, }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get id => + $composableBuilder(column: $table.id, builder: (column) => column); - ColumnOrderings get type => $composableBuilder( - column: $table.type, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get messageText => $composableBuilder( + column: $table.messageText, builder: (column) => column); - ColumnOrderings get cid => $composableBuilder( - column: $table.cid, builder: (column) => ColumnOrderings(column)); + GeneratedColumnWithTypeConverter, String> get attachments => + $composableBuilder( + column: $table.attachments, builder: (column) => column); - ColumnOrderings get ownCapabilities => $composableBuilder( - column: $table.ownCapabilities, - builder: (column) => ColumnOrderings(column)); + GeneratedColumn get state => + $composableBuilder(column: $table.state, builder: (column) => column); - ColumnOrderings get config => $composableBuilder( - column: $table.config, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get type => + $composableBuilder(column: $table.type, builder: (column) => column); - ColumnOrderings get frozen => $composableBuilder( - column: $table.frozen, builder: (column) => ColumnOrderings(column)); + GeneratedColumnWithTypeConverter, String> get mentionedUsers => + $composableBuilder( + column: $table.mentionedUsers, builder: (column) => column); - ColumnOrderings get lastMessageAt => $composableBuilder( - column: $table.lastMessageAt, - builder: (column) => ColumnOrderings(column)); + GeneratedColumnWithTypeConverter?, String> + get reactionCounts => $composableBuilder( + column: $table.reactionCounts, builder: (column) => column); + + GeneratedColumnWithTypeConverter?, String> + get reactionScores => $composableBuilder( + column: $table.reactionScores, builder: (column) => column); + + GeneratedColumn get parentId => + $composableBuilder(column: $table.parentId, builder: (column) => column); - ColumnOrderings get createdAt => $composableBuilder( - column: $table.createdAt, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get quotedMessageId => $composableBuilder( + column: $table.quotedMessageId, builder: (column) => column); - ColumnOrderings get updatedAt => $composableBuilder( - column: $table.updatedAt, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get pollId => + $composableBuilder(column: $table.pollId, builder: (column) => column); - ColumnOrderings get deletedAt => $composableBuilder( - column: $table.deletedAt, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get replyCount => $composableBuilder( + column: $table.replyCount, builder: (column) => column); - ColumnOrderings get memberCount => $composableBuilder( - column: $table.memberCount, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get showInChannel => $composableBuilder( + column: $table.showInChannel, builder: (column) => column); - ColumnOrderings get createdById => $composableBuilder( - column: $table.createdById, builder: (column) => ColumnOrderings(column)); + GeneratedColumn get shadowed => + $composableBuilder(column: $table.shadowed, builder: (column) => column); - ColumnOrderings get extraData => $composableBuilder( - column: $table.extraData, builder: (column) => ColumnOrderings(column)); -} + GeneratedColumn get command => + $composableBuilder(column: $table.command, builder: (column) => column); -class $$ChannelsTableAnnotationComposer - extends Composer<_$DriftChatDatabase, $ChannelsTable> { - $$ChannelsTableAnnotationComposer({ - required super.$db, - required super.$table, - super.joinBuilder, - super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - GeneratedColumn get id => - $composableBuilder(column: $table.id, builder: (column) => column); + GeneratedColumn get localCreatedAt => $composableBuilder( + column: $table.localCreatedAt, builder: (column) => column); - GeneratedColumn get type => - $composableBuilder(column: $table.type, builder: (column) => column); + GeneratedColumn get remoteCreatedAt => $composableBuilder( + column: $table.remoteCreatedAt, builder: (column) => column); - GeneratedColumn get cid => - $composableBuilder(column: $table.cid, builder: (column) => column); + GeneratedColumn get localUpdatedAt => $composableBuilder( + column: $table.localUpdatedAt, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> get ownCapabilities => - $composableBuilder( - column: $table.ownCapabilities, builder: (column) => column); + GeneratedColumn get remoteUpdatedAt => $composableBuilder( + column: $table.remoteUpdatedAt, builder: (column) => column); - GeneratedColumnWithTypeConverter, String> get config => - $composableBuilder(column: $table.config, builder: (column) => column); + GeneratedColumn get localDeletedAt => $composableBuilder( + column: $table.localDeletedAt, builder: (column) => column); - GeneratedColumn get frozen => - $composableBuilder(column: $table.frozen, builder: (column) => column); + GeneratedColumn get remoteDeletedAt => $composableBuilder( + column: $table.remoteDeletedAt, builder: (column) => column); - GeneratedColumn get lastMessageAt => $composableBuilder( - column: $table.lastMessageAt, builder: (column) => column); + GeneratedColumn get messageTextUpdatedAt => $composableBuilder( + column: $table.messageTextUpdatedAt, builder: (column) => column); - GeneratedColumn get createdAt => - $composableBuilder(column: $table.createdAt, builder: (column) => column); + GeneratedColumn get userId => + $composableBuilder(column: $table.userId, builder: (column) => column); - GeneratedColumn get updatedAt => - $composableBuilder(column: $table.updatedAt, builder: (column) => column); + GeneratedColumn get pinned => + $composableBuilder(column: $table.pinned, builder: (column) => column); - GeneratedColumn get deletedAt => - $composableBuilder(column: $table.deletedAt, builder: (column) => column); + GeneratedColumn get pinnedAt => + $composableBuilder(column: $table.pinnedAt, builder: (column) => column); - GeneratedColumn get memberCount => $composableBuilder( - column: $table.memberCount, builder: (column) => column); + GeneratedColumn get pinExpires => $composableBuilder( + column: $table.pinExpires, builder: (column) => column); - GeneratedColumn get createdById => $composableBuilder( - column: $table.createdById, builder: (column) => column); + GeneratedColumn get pinnedByUserId => $composableBuilder( + column: $table.pinnedByUserId, builder: (column) => column); + + GeneratedColumnWithTypeConverter?, String> get i18n => + $composableBuilder(column: $table.i18n, builder: (column) => column); GeneratedColumnWithTypeConverter?, String> get extraData => $composableBuilder( column: $table.extraData, builder: (column) => column); - Expression messagesRefs( - Expression Function($$MessagesTableAnnotationComposer a) f) { - final $$MessagesTableAnnotationComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.messages, - getReferencedColumn: (t) => t.channelCid, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$MessagesTableAnnotationComposer( - $db: $db, - $table: $db.messages, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); - return f(composer); - } - - Expression membersRefs( - Expression Function($$MembersTableAnnotationComposer a) f) { - final $$MembersTableAnnotationComposer composer = $composerBuilder( + $$ChannelsTableAnnotationComposer get channelCid { + final $$ChannelsTableAnnotationComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.members, - getReferencedColumn: (t) => t.channelCid, + getCurrentColumn: (t) => t.channelCid, + referencedTable: $db.channels, + getReferencedColumn: (t) => t.cid, builder: (joinBuilder, {$addJoinBuilderToRootComposer, $removeJoinBuilderFromRootComposer}) => - $$MembersTableAnnotationComposer( + $$ChannelsTableAnnotationComposer( $db: $db, - $table: $db.members, + $table: $db.channels, $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, joinBuilder: joinBuilder, $removeJoinBuilderFromRootComposer: $removeJoinBuilderFromRootComposer, )); - return f(composer); + return composer; } - Expression readsRefs( - Expression Function($$ReadsTableAnnotationComposer a) f) { - final $$ReadsTableAnnotationComposer composer = $composerBuilder( + Expression reactionsRefs( + Expression Function($$ReactionsTableAnnotationComposer a) f) { + final $$ReactionsTableAnnotationComposer composer = $composerBuilder( composer: this, - getCurrentColumn: (t) => t.cid, - referencedTable: $db.reads, - getReferencedColumn: (t) => t.channelCid, + getCurrentColumn: (t) => t.id, + referencedTable: $db.reactions, + getReferencedColumn: (t) => t.messageId, builder: (joinBuilder, {$addJoinBuilderToRootComposer, $removeJoinBuilderFromRootComposer}) => - $$ReadsTableAnnotationComposer( + $$ReactionsTableAnnotationComposer( $db: $db, - $table: $db.reads, + $table: $db.reactions, $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, joinBuilder: joinBuilder, $removeJoinBuilderFromRootComposer: @@ -6558,143 +8595,207 @@ class $$ChannelsTableAnnotationComposer } } -class $$ChannelsTableTableManager extends RootTableManager< +class $$MessagesTableTableManager extends RootTableManager< _$DriftChatDatabase, - $ChannelsTable, - ChannelEntity, - $$ChannelsTableFilterComposer, - $$ChannelsTableOrderingComposer, - $$ChannelsTableAnnotationComposer, - $$ChannelsTableCreateCompanionBuilder, - $$ChannelsTableUpdateCompanionBuilder, - (ChannelEntity, $$ChannelsTableReferences), - ChannelEntity, - PrefetchHooks Function( - {bool messagesRefs, bool membersRefs, bool readsRefs})> { - $$ChannelsTableTableManager(_$DriftChatDatabase db, $ChannelsTable table) + $MessagesTable, + MessageEntity, + $$MessagesTableFilterComposer, + $$MessagesTableOrderingComposer, + $$MessagesTableAnnotationComposer, + $$MessagesTableCreateCompanionBuilder, + $$MessagesTableUpdateCompanionBuilder, + (MessageEntity, $$MessagesTableReferences), + MessageEntity, + PrefetchHooks Function({bool channelCid, bool reactionsRefs})> { + $$MessagesTableTableManager(_$DriftChatDatabase db, $MessagesTable table) : super(TableManagerState( db: db, table: table, createFilteringComposer: () => - $$ChannelsTableFilterComposer($db: db, $table: table), + $$MessagesTableFilterComposer($db: db, $table: table), createOrderingComposer: () => - $$ChannelsTableOrderingComposer($db: db, $table: table), + $$MessagesTableOrderingComposer($db: db, $table: table), createComputedFieldComposer: () => - $$ChannelsTableAnnotationComposer($db: db, $table: table), + $$MessagesTableAnnotationComposer($db: db, $table: table), updateCompanionCallback: ({ Value id = const Value.absent(), + Value messageText = const Value.absent(), + Value> attachments = const Value.absent(), + Value state = const Value.absent(), Value type = const Value.absent(), - Value cid = const Value.absent(), - Value?> ownCapabilities = const Value.absent(), - Value> config = const Value.absent(), - Value frozen = const Value.absent(), - Value lastMessageAt = const Value.absent(), - Value createdAt = const Value.absent(), - Value updatedAt = const Value.absent(), - Value deletedAt = const Value.absent(), - Value memberCount = const Value.absent(), - Value createdById = const Value.absent(), + Value> mentionedUsers = const Value.absent(), + Value?> reactionCounts = const Value.absent(), + Value?> reactionScores = const Value.absent(), + Value parentId = const Value.absent(), + Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), + Value replyCount = const Value.absent(), + Value showInChannel = const Value.absent(), + Value shadowed = const Value.absent(), + Value command = const Value.absent(), + Value localCreatedAt = const Value.absent(), + Value remoteCreatedAt = const Value.absent(), + Value localUpdatedAt = const Value.absent(), + Value remoteUpdatedAt = const Value.absent(), + Value localDeletedAt = const Value.absent(), + Value remoteDeletedAt = const Value.absent(), + Value messageTextUpdatedAt = const Value.absent(), + Value userId = const Value.absent(), + Value pinned = const Value.absent(), + Value pinnedAt = const Value.absent(), + Value pinExpires = const Value.absent(), + Value pinnedByUserId = const Value.absent(), + Value channelCid = const Value.absent(), + Value?> i18n = const Value.absent(), Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - ChannelsCompanion( + MessagesCompanion( id: id, + messageText: messageText, + attachments: attachments, + state: state, type: type, - cid: cid, - ownCapabilities: ownCapabilities, - config: config, - frozen: frozen, - lastMessageAt: lastMessageAt, - createdAt: createdAt, - updatedAt: updatedAt, - deletedAt: deletedAt, - memberCount: memberCount, - createdById: createdById, - extraData: extraData, - rowid: rowid, - ), - createCompanionCallback: ({ - required String id, - required String type, - required String cid, - Value?> ownCapabilities = const Value.absent(), - required Map config, - Value frozen = const Value.absent(), - Value lastMessageAt = const Value.absent(), - Value createdAt = const Value.absent(), - Value updatedAt = const Value.absent(), - Value deletedAt = const Value.absent(), - Value memberCount = const Value.absent(), - Value createdById = const Value.absent(), + mentionedUsers: mentionedUsers, + reactionCounts: reactionCounts, + reactionScores: reactionScores, + parentId: parentId, + quotedMessageId: quotedMessageId, + pollId: pollId, + replyCount: replyCount, + showInChannel: showInChannel, + shadowed: shadowed, + command: command, + localCreatedAt: localCreatedAt, + remoteCreatedAt: remoteCreatedAt, + localUpdatedAt: localUpdatedAt, + remoteUpdatedAt: remoteUpdatedAt, + localDeletedAt: localDeletedAt, + remoteDeletedAt: remoteDeletedAt, + messageTextUpdatedAt: messageTextUpdatedAt, + userId: userId, + pinned: pinned, + pinnedAt: pinnedAt, + pinExpires: pinExpires, + pinnedByUserId: pinnedByUserId, + channelCid: channelCid, + i18n: i18n, + extraData: extraData, + rowid: rowid, + ), + createCompanionCallback: ({ + required String id, + Value messageText = const Value.absent(), + required List attachments, + required String state, + Value type = const Value.absent(), + required List mentionedUsers, + Value?> reactionCounts = const Value.absent(), + Value?> reactionScores = const Value.absent(), + Value parentId = const Value.absent(), + Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), + Value replyCount = const Value.absent(), + Value showInChannel = const Value.absent(), + Value shadowed = const Value.absent(), + Value command = const Value.absent(), + Value localCreatedAt = const Value.absent(), + Value remoteCreatedAt = const Value.absent(), + Value localUpdatedAt = const Value.absent(), + Value remoteUpdatedAt = const Value.absent(), + Value localDeletedAt = const Value.absent(), + Value remoteDeletedAt = const Value.absent(), + Value messageTextUpdatedAt = const Value.absent(), + Value userId = const Value.absent(), + Value pinned = const Value.absent(), + Value pinnedAt = const Value.absent(), + Value pinExpires = const Value.absent(), + Value pinnedByUserId = const Value.absent(), + required String channelCid, + Value?> i18n = const Value.absent(), Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - ChannelsCompanion.insert( + MessagesCompanion.insert( id: id, + messageText: messageText, + attachments: attachments, + state: state, type: type, - cid: cid, - ownCapabilities: ownCapabilities, - config: config, - frozen: frozen, - lastMessageAt: lastMessageAt, - createdAt: createdAt, - updatedAt: updatedAt, - deletedAt: deletedAt, - memberCount: memberCount, - createdById: createdById, + mentionedUsers: mentionedUsers, + reactionCounts: reactionCounts, + reactionScores: reactionScores, + parentId: parentId, + quotedMessageId: quotedMessageId, + pollId: pollId, + replyCount: replyCount, + showInChannel: showInChannel, + shadowed: shadowed, + command: command, + localCreatedAt: localCreatedAt, + remoteCreatedAt: remoteCreatedAt, + localUpdatedAt: localUpdatedAt, + remoteUpdatedAt: remoteUpdatedAt, + localDeletedAt: localDeletedAt, + remoteDeletedAt: remoteDeletedAt, + messageTextUpdatedAt: messageTextUpdatedAt, + userId: userId, + pinned: pinned, + pinnedAt: pinnedAt, + pinExpires: pinExpires, + pinnedByUserId: pinnedByUserId, + channelCid: channelCid, + i18n: i18n, extraData: extraData, rowid: rowid, ), withReferenceMapper: (p0) => p0 .map((e) => - (e.readTable(table), $$ChannelsTableReferences(db, table, e))) + (e.readTable(table), $$MessagesTableReferences(db, table, e))) .toList(), - prefetchHooksCallback: ( - {messagesRefs = false, membersRefs = false, readsRefs = false}) { + prefetchHooksCallback: ({channelCid = false, reactionsRefs = false}) { return PrefetchHooks( db: db, - explicitlyWatchedTables: [ - if (messagesRefs) db.messages, - if (membersRefs) db.members, - if (readsRefs) db.reads - ], - addJoins: null, + explicitlyWatchedTables: [if (reactionsRefs) db.reactions], + addJoins: < + T extends TableManagerState< + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic>>(state) { + if (channelCid) { + state = state.withJoin( + currentTable: table, + currentColumn: table.channelCid, + referencedTable: + $$MessagesTableReferences._channelCidTable(db), + referencedColumn: + $$MessagesTableReferences._channelCidTable(db).cid, + ) as T; + } + + return state; + }, getPrefetchedDataCallback: (items) async { return [ - if (messagesRefs) - await $_getPrefetchedData( - currentTable: table, - referencedTable: - $$ChannelsTableReferences._messagesRefsTable(db), - managerFromTypedResult: (p0) => - $$ChannelsTableReferences(db, table, p0) - .messagesRefs, - referencedItemsForCurrentItem: - (item, referencedItems) => referencedItems - .where((e) => e.channelCid == item.cid), - typedResults: items), - if (membersRefs) - await $_getPrefetchedData( - currentTable: table, - referencedTable: - $$ChannelsTableReferences._membersRefsTable(db), - managerFromTypedResult: (p0) => - $$ChannelsTableReferences(db, table, p0) - .membersRefs, - referencedItemsForCurrentItem: - (item, referencedItems) => referencedItems - .where((e) => e.channelCid == item.cid), - typedResults: items), - if (readsRefs) + if (reactionsRefs) await $_getPrefetchedData( currentTable: table, referencedTable: - $$ChannelsTableReferences._readsRefsTable(db), + $$MessagesTableReferences._reactionsRefsTable(db), managerFromTypedResult: (p0) => - $$ChannelsTableReferences(db, table, p0).readsRefs, + $$MessagesTableReferences(db, table, p0) + .reactionsRefs, referencedItemsForCurrentItem: (item, referencedItems) => referencedItems - .where((e) => e.channelCid == item.cid), + .where((e) => e.messageId == item.id), typedResults: items) ]; }, @@ -6703,20 +8804,20 @@ class $$ChannelsTableTableManager extends RootTableManager< )); } -typedef $$ChannelsTableProcessedTableManager = ProcessedTableManager< +typedef $$MessagesTableProcessedTableManager = ProcessedTableManager< _$DriftChatDatabase, - $ChannelsTable, - ChannelEntity, - $$ChannelsTableFilterComposer, - $$ChannelsTableOrderingComposer, - $$ChannelsTableAnnotationComposer, - $$ChannelsTableCreateCompanionBuilder, - $$ChannelsTableUpdateCompanionBuilder, - (ChannelEntity, $$ChannelsTableReferences), - ChannelEntity, - PrefetchHooks Function( - {bool messagesRefs, bool membersRefs, bool readsRefs})>; -typedef $$MessagesTableCreateCompanionBuilder = MessagesCompanion Function({ + $MessagesTable, + MessageEntity, + $$MessagesTableFilterComposer, + $$MessagesTableOrderingComposer, + $$MessagesTableAnnotationComposer, + $$MessagesTableCreateCompanionBuilder, + $$MessagesTableUpdateCompanionBuilder, + (MessageEntity, $$MessagesTableReferences), + MessageEntity, + PrefetchHooks Function({bool channelCid, bool reactionsRefs})>; +typedef $$PinnedMessagesTableCreateCompanionBuilder = PinnedMessagesCompanion + Function({ required String id, Value messageText, required List attachments, @@ -6727,6 +8828,7 @@ typedef $$MessagesTableCreateCompanionBuilder = MessagesCompanion Function({ Value?> reactionScores, Value parentId, Value quotedMessageId, + Value pollId, Value replyCount, Value showInChannel, Value shadowed, @@ -6748,7 +8850,8 @@ typedef $$MessagesTableCreateCompanionBuilder = MessagesCompanion Function({ Value?> extraData, Value rowid, }); -typedef $$MessagesTableUpdateCompanionBuilder = MessagesCompanion Function({ +typedef $$PinnedMessagesTableUpdateCompanionBuilder = PinnedMessagesCompanion + Function({ Value id, Value messageText, Value> attachments, @@ -6759,6 +8862,7 @@ typedef $$MessagesTableUpdateCompanionBuilder = MessagesCompanion Function({ Value?> reactionScores, Value parentId, Value quotedMessageId, + Value pollId, Value replyCount, Value showInChannel, Value shadowed, @@ -6781,42 +8885,34 @@ typedef $$MessagesTableUpdateCompanionBuilder = MessagesCompanion Function({ Value rowid, }); -final class $$MessagesTableReferences - extends BaseReferences<_$DriftChatDatabase, $MessagesTable, MessageEntity> { - $$MessagesTableReferences(super.$_db, super.$_table, super.$_typedResult); - - static $ChannelsTable _channelCidTable(_$DriftChatDatabase db) => - db.channels.createAlias( - $_aliasNameGenerator(db.messages.channelCid, db.channels.cid)); - - $$ChannelsTableProcessedTableManager get channelCid { - final manager = $$ChannelsTableTableManager($_db, $_db.channels) - .filter((f) => f.cid($_item.channelCid!)); - final item = $_typedResult.readTableOrNull(_channelCidTable($_db)); - if (item == null) return manager; - return ProcessedTableManager( - manager.$state.copyWith(prefetchedData: [item])); - } +final class $$PinnedMessagesTableReferences extends BaseReferences< + _$DriftChatDatabase, $PinnedMessagesTable, PinnedMessageEntity> { + $$PinnedMessagesTableReferences( + super.$_db, super.$_table, super.$_typedResult); - static MultiTypedResultKey<$ReactionsTable, List> - _reactionsRefsTable(_$DriftChatDatabase db) => - MultiTypedResultKey.fromTable(db.reactions, - aliasName: - $_aliasNameGenerator(db.messages.id, db.reactions.messageId)); + static MultiTypedResultKey<$PinnedMessageReactionsTable, + List> _pinnedMessageReactionsRefsTable( + _$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.pinnedMessageReactions, + aliasName: $_aliasNameGenerator( + db.pinnedMessages.id, db.pinnedMessageReactions.messageId)); - $$ReactionsTableProcessedTableManager get reactionsRefs { - final manager = $$ReactionsTableTableManager($_db, $_db.reactions) + $$PinnedMessageReactionsTableProcessedTableManager + get pinnedMessageReactionsRefs { + final manager = $$PinnedMessageReactionsTableTableManager( + $_db, $_db.pinnedMessageReactions) .filter((f) => f.messageId.id($_item.id)); - final cache = $_typedResult.readTableOrNull(_reactionsRefsTable($_db)); + final cache = + $_typedResult.readTableOrNull(_pinnedMessageReactionsRefsTable($_db)); return ProcessedTableManager( manager.$state.copyWith(prefetchedData: cache)); } } -class $$MessagesTableFilterComposer - extends Composer<_$DriftChatDatabase, $MessagesTable> { - $$MessagesTableFilterComposer({ +class $$PinnedMessagesTableFilterComposer + extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { + $$PinnedMessagesTableFilterComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -6862,6 +8958,9 @@ class $$MessagesTableFilterComposer column: $table.quotedMessageId, builder: (column) => ColumnFilters(column)); + ColumnFilters get pollId => $composableBuilder( + column: $table.pollId, builder: (column) => ColumnFilters(column)); + ColumnFilters get replyCount => $composableBuilder( column: $table.replyCount, builder: (column) => ColumnFilters(column)); @@ -6914,67 +9013,52 @@ class $$MessagesTableFilterComposer ColumnFilters get pinExpires => $composableBuilder( column: $table.pinExpires, builder: (column) => ColumnFilters(column)); - ColumnFilters get pinnedByUserId => $composableBuilder( - column: $table.pinnedByUserId, - builder: (column) => ColumnFilters(column)); - - ColumnWithTypeConverterFilters?, Map, - String> - get i18n => $composableBuilder( - column: $table.i18n, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - ColumnWithTypeConverterFilters?, Map, - String> - get extraData => $composableBuilder( - column: $table.extraData, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - $$ChannelsTableFilterComposer get channelCid { - final $$ChannelsTableFilterComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.channelCid, - referencedTable: $db.channels, - getReferencedColumn: (t) => t.cid, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$ChannelsTableFilterComposer( - $db: $db, - $table: $db.channels, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); - return composer; - } - - Expression reactionsRefs( - Expression Function($$ReactionsTableFilterComposer f) f) { - final $$ReactionsTableFilterComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.id, - referencedTable: $db.reactions, - getReferencedColumn: (t) => t.messageId, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$ReactionsTableFilterComposer( - $db: $db, - $table: $db.reactions, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); + ColumnFilters get pinnedByUserId => $composableBuilder( + column: $table.pinnedByUserId, + builder: (column) => ColumnFilters(column)); + + ColumnFilters get channelCid => $composableBuilder( + column: $table.channelCid, builder: (column) => ColumnFilters(column)); + + ColumnWithTypeConverterFilters?, Map, + String> + get i18n => $composableBuilder( + column: $table.i18n, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + ColumnWithTypeConverterFilters?, Map, + String> + get extraData => $composableBuilder( + column: $table.extraData, + builder: (column) => ColumnWithTypeConverterFilters(column)); + + Expression pinnedMessageReactionsRefs( + Expression Function($$PinnedMessageReactionsTableFilterComposer f) + f) { + final $$PinnedMessageReactionsTableFilterComposer composer = + $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.pinnedMessageReactions, + getReferencedColumn: (t) => t.messageId, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PinnedMessageReactionsTableFilterComposer( + $db: $db, + $table: $db.pinnedMessageReactions, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); return f(composer); } } -class $$MessagesTableOrderingComposer - extends Composer<_$DriftChatDatabase, $MessagesTable> { - $$MessagesTableOrderingComposer({ +class $$PinnedMessagesTableOrderingComposer + extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { + $$PinnedMessagesTableOrderingComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -7015,6 +9099,9 @@ class $$MessagesTableOrderingComposer column: $table.quotedMessageId, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get pollId => $composableBuilder( + column: $table.pollId, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get replyCount => $composableBuilder( column: $table.replyCount, builder: (column) => ColumnOrderings(column)); @@ -7072,36 +9159,19 @@ class $$MessagesTableOrderingComposer column: $table.pinnedByUserId, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get channelCid => $composableBuilder( + column: $table.channelCid, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get i18n => $composableBuilder( column: $table.i18n, builder: (column) => ColumnOrderings(column)); ColumnOrderings get extraData => $composableBuilder( column: $table.extraData, builder: (column) => ColumnOrderings(column)); - - $$ChannelsTableOrderingComposer get channelCid { - final $$ChannelsTableOrderingComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.channelCid, - referencedTable: $db.channels, - getReferencedColumn: (t) => t.cid, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$ChannelsTableOrderingComposer( - $db: $db, - $table: $db.channels, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); - return composer; - } } -class $$MessagesTableAnnotationComposer - extends Composer<_$DriftChatDatabase, $MessagesTable> { - $$MessagesTableAnnotationComposer({ +class $$PinnedMessagesTableAnnotationComposer + extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { + $$PinnedMessagesTableAnnotationComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -7142,6 +9212,9 @@ class $$MessagesTableAnnotationComposer GeneratedColumn get quotedMessageId => $composableBuilder( column: $table.quotedMessageId, builder: (column) => column); + GeneratedColumn get pollId => + $composableBuilder(column: $table.pollId, builder: (column) => column); + GeneratedColumn get replyCount => $composableBuilder( column: $table.replyCount, builder: (column) => column); @@ -7190,6 +9263,9 @@ class $$MessagesTableAnnotationComposer GeneratedColumn get pinnedByUserId => $composableBuilder( column: $table.pinnedByUserId, builder: (column) => column); + GeneratedColumn get channelCid => $composableBuilder( + column: $table.channelCid, builder: (column) => column); + GeneratedColumnWithTypeConverter?, String> get i18n => $composableBuilder(column: $table.i18n, builder: (column) => column); @@ -7197,70 +9273,53 @@ class $$MessagesTableAnnotationComposer get extraData => $composableBuilder( column: $table.extraData, builder: (column) => column); - $$ChannelsTableAnnotationComposer get channelCid { - final $$ChannelsTableAnnotationComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.channelCid, - referencedTable: $db.channels, - getReferencedColumn: (t) => t.cid, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$ChannelsTableAnnotationComposer( - $db: $db, - $table: $db.channels, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); - return composer; - } - - Expression reactionsRefs( - Expression Function($$ReactionsTableAnnotationComposer a) f) { - final $$ReactionsTableAnnotationComposer composer = $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.id, - referencedTable: $db.reactions, - getReferencedColumn: (t) => t.messageId, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$ReactionsTableAnnotationComposer( - $db: $db, - $table: $db.reactions, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); + Expression pinnedMessageReactionsRefs( + Expression Function($$PinnedMessageReactionsTableAnnotationComposer a) + f) { + final $$PinnedMessageReactionsTableAnnotationComposer composer = + $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.pinnedMessageReactions, + getReferencedColumn: (t) => t.messageId, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PinnedMessageReactionsTableAnnotationComposer( + $db: $db, + $table: $db.pinnedMessageReactions, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); return f(composer); } } -class $$MessagesTableTableManager extends RootTableManager< +class $$PinnedMessagesTableTableManager extends RootTableManager< _$DriftChatDatabase, - $MessagesTable, - MessageEntity, - $$MessagesTableFilterComposer, - $$MessagesTableOrderingComposer, - $$MessagesTableAnnotationComposer, - $$MessagesTableCreateCompanionBuilder, - $$MessagesTableUpdateCompanionBuilder, - (MessageEntity, $$MessagesTableReferences), - MessageEntity, - PrefetchHooks Function({bool channelCid, bool reactionsRefs})> { - $$MessagesTableTableManager(_$DriftChatDatabase db, $MessagesTable table) + $PinnedMessagesTable, + PinnedMessageEntity, + $$PinnedMessagesTableFilterComposer, + $$PinnedMessagesTableOrderingComposer, + $$PinnedMessagesTableAnnotationComposer, + $$PinnedMessagesTableCreateCompanionBuilder, + $$PinnedMessagesTableUpdateCompanionBuilder, + (PinnedMessageEntity, $$PinnedMessagesTableReferences), + PinnedMessageEntity, + PrefetchHooks Function({bool pinnedMessageReactionsRefs})> { + $$PinnedMessagesTableTableManager( + _$DriftChatDatabase db, $PinnedMessagesTable table) : super(TableManagerState( db: db, table: table, createFilteringComposer: () => - $$MessagesTableFilterComposer($db: db, $table: table), + $$PinnedMessagesTableFilterComposer($db: db, $table: table), createOrderingComposer: () => - $$MessagesTableOrderingComposer($db: db, $table: table), + $$PinnedMessagesTableOrderingComposer($db: db, $table: table), createComputedFieldComposer: () => - $$MessagesTableAnnotationComposer($db: db, $table: table), + $$PinnedMessagesTableAnnotationComposer($db: db, $table: table), updateCompanionCallback: ({ Value id = const Value.absent(), Value messageText = const Value.absent(), @@ -7272,6 +9331,7 @@ class $$MessagesTableTableManager extends RootTableManager< Value?> reactionScores = const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), Value replyCount = const Value.absent(), Value showInChannel = const Value.absent(), Value shadowed = const Value.absent(), @@ -7293,7 +9353,7 @@ class $$MessagesTableTableManager extends RootTableManager< Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - MessagesCompanion( + PinnedMessagesCompanion( id: id, messageText: messageText, attachments: attachments, @@ -7304,6 +9364,7 @@ class $$MessagesTableTableManager extends RootTableManager< reactionScores: reactionScores, parentId: parentId, quotedMessageId: quotedMessageId, + pollId: pollId, replyCount: replyCount, showInChannel: showInChannel, shadowed: shadowed, @@ -7336,6 +9397,7 @@ class $$MessagesTableTableManager extends RootTableManager< Value?> reactionScores = const Value.absent(), Value parentId = const Value.absent(), Value quotedMessageId = const Value.absent(), + Value pollId = const Value.absent(), Value replyCount = const Value.absent(), Value showInChannel = const Value.absent(), Value shadowed = const Value.absent(), @@ -7357,7 +9419,7 @@ class $$MessagesTableTableManager extends RootTableManager< Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - MessagesCompanion.insert( + PinnedMessagesCompanion.insert( id: id, messageText: messageText, attachments: attachments, @@ -7368,6 +9430,7 @@ class $$MessagesTableTableManager extends RootTableManager< reactionScores: reactionScores, parentId: parentId, quotedMessageId: quotedMessageId, + pollId: pollId, replyCount: replyCount, showInChannel: showInChannel, shadowed: shadowed, @@ -7390,49 +9453,28 @@ class $$MessagesTableTableManager extends RootTableManager< rowid: rowid, ), withReferenceMapper: (p0) => p0 - .map((e) => - (e.readTable(table), $$MessagesTableReferences(db, table, e))) + .map((e) => ( + e.readTable(table), + $$PinnedMessagesTableReferences(db, table, e) + )) .toList(), - prefetchHooksCallback: ({channelCid = false, reactionsRefs = false}) { + prefetchHooksCallback: ({pinnedMessageReactionsRefs = false}) { return PrefetchHooks( db: db, - explicitlyWatchedTables: [if (reactionsRefs) db.reactions], - addJoins: < - T extends TableManagerState< - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic, - dynamic>>(state) { - if (channelCid) { - state = state.withJoin( - currentTable: table, - currentColumn: table.channelCid, - referencedTable: - $$MessagesTableReferences._channelCidTable(db), - referencedColumn: - $$MessagesTableReferences._channelCidTable(db).cid, - ) as T; - } - - return state; - }, + explicitlyWatchedTables: [ + if (pinnedMessageReactionsRefs) db.pinnedMessageReactions + ], + addJoins: null, getPrefetchedDataCallback: (items) async { return [ - if (reactionsRefs) + if (pinnedMessageReactionsRefs) await $_getPrefetchedData( currentTable: table, - referencedTable: - $$MessagesTableReferences._reactionsRefsTable(db), + referencedTable: $$PinnedMessagesTableReferences + ._pinnedMessageReactionsRefsTable(db), managerFromTypedResult: (p0) => - $$MessagesTableReferences(db, table, p0) - .reactionsRefs, + $$PinnedMessagesTableReferences(db, table, p0) + .pinnedMessageReactionsRefs, referencedItemsForCurrentItem: (item, referencedItems) => referencedItems .where((e) => e.messageId == item.id), @@ -7444,113 +9486,82 @@ class $$MessagesTableTableManager extends RootTableManager< )); } -typedef $$MessagesTableProcessedTableManager = ProcessedTableManager< +typedef $$PinnedMessagesTableProcessedTableManager = ProcessedTableManager< _$DriftChatDatabase, - $MessagesTable, - MessageEntity, - $$MessagesTableFilterComposer, - $$MessagesTableOrderingComposer, - $$MessagesTableAnnotationComposer, - $$MessagesTableCreateCompanionBuilder, - $$MessagesTableUpdateCompanionBuilder, - (MessageEntity, $$MessagesTableReferences), - MessageEntity, - PrefetchHooks Function({bool channelCid, bool reactionsRefs})>; -typedef $$PinnedMessagesTableCreateCompanionBuilder = PinnedMessagesCompanion - Function({ + $PinnedMessagesTable, + PinnedMessageEntity, + $$PinnedMessagesTableFilterComposer, + $$PinnedMessagesTableOrderingComposer, + $$PinnedMessagesTableAnnotationComposer, + $$PinnedMessagesTableCreateCompanionBuilder, + $$PinnedMessagesTableUpdateCompanionBuilder, + (PinnedMessageEntity, $$PinnedMessagesTableReferences), + PinnedMessageEntity, + PrefetchHooks Function({bool pinnedMessageReactionsRefs})>; +typedef $$PollsTableCreateCompanionBuilder = PollsCompanion Function({ required String id, - Value messageText, - required List attachments, - required String state, - Value type, - required List mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, - Value parentId, - Value quotedMessageId, - Value replyCount, - Value showInChannel, - Value shadowed, - Value command, - Value localCreatedAt, - Value remoteCreatedAt, - Value localUpdatedAt, - Value remoteUpdatedAt, - Value localDeletedAt, - Value remoteDeletedAt, - Value messageTextUpdatedAt, - Value userId, - Value pinned, - Value pinnedAt, - Value pinExpires, - Value pinnedByUserId, - required String channelCid, - Value?> i18n, + required String name, + Value description, + required List options, + Value votingVisibility, + Value enforceUniqueVote, + Value maxVotesAllowed, + Value allowUserSuggestedOptions, + Value allowAnswers, + Value isClosed, + Value answersCount, + required Map voteCountsByOption, + Value voteCount, + Value createdById, + Value createdAt, + Value updatedAt, Value?> extraData, Value rowid, }); -typedef $$PinnedMessagesTableUpdateCompanionBuilder = PinnedMessagesCompanion - Function({ +typedef $$PollsTableUpdateCompanionBuilder = PollsCompanion Function({ Value id, - Value messageText, - Value> attachments, - Value state, - Value type, - Value> mentionedUsers, - Value?> reactionCounts, - Value?> reactionScores, - Value parentId, - Value quotedMessageId, - Value replyCount, - Value showInChannel, - Value shadowed, - Value command, - Value localCreatedAt, - Value remoteCreatedAt, - Value localUpdatedAt, - Value remoteUpdatedAt, - Value localDeletedAt, - Value remoteDeletedAt, - Value messageTextUpdatedAt, - Value userId, - Value pinned, - Value pinnedAt, - Value pinExpires, - Value pinnedByUserId, - Value channelCid, - Value?> i18n, + Value name, + Value description, + Value> options, + Value votingVisibility, + Value enforceUniqueVote, + Value maxVotesAllowed, + Value allowUserSuggestedOptions, + Value allowAnswers, + Value isClosed, + Value answersCount, + Value> voteCountsByOption, + Value voteCount, + Value createdById, + Value createdAt, + Value updatedAt, Value?> extraData, Value rowid, }); -final class $$PinnedMessagesTableReferences extends BaseReferences< - _$DriftChatDatabase, $PinnedMessagesTable, PinnedMessageEntity> { - $$PinnedMessagesTableReferences( - super.$_db, super.$_table, super.$_typedResult); +final class $$PollsTableReferences + extends BaseReferences<_$DriftChatDatabase, $PollsTable, PollEntity> { + $$PollsTableReferences(super.$_db, super.$_table, super.$_typedResult); - static MultiTypedResultKey<$PinnedMessageReactionsTable, - List> _pinnedMessageReactionsRefsTable( - _$DriftChatDatabase db) => - MultiTypedResultKey.fromTable(db.pinnedMessageReactions, - aliasName: $_aliasNameGenerator( - db.pinnedMessages.id, db.pinnedMessageReactions.messageId)); + static MultiTypedResultKey<$PollVotesTable, List> + _pollVotesRefsTable(_$DriftChatDatabase db) => + MultiTypedResultKey.fromTable(db.pollVotes, + aliasName: + $_aliasNameGenerator(db.polls.id, db.pollVotes.pollId)); - $$PinnedMessageReactionsTableProcessedTableManager - get pinnedMessageReactionsRefs { - final manager = $$PinnedMessageReactionsTableTableManager( - $_db, $_db.pinnedMessageReactions) - .filter((f) => f.messageId.id($_item.id)); + $$PollVotesTableProcessedTableManager get pollVotesRefs { + final manager = $$PollVotesTableTableManager($_db, $_db.pollVotes) + .filter((f) => f.pollId.id($_item.id)); - final cache = - $_typedResult.readTableOrNull(_pinnedMessageReactionsRefsTable($_db)); + final cache = $_typedResult.readTableOrNull(_pollVotesRefsTable($_db)); return ProcessedTableManager( manager.$state.copyWith(prefetchedData: cache)); } } -class $$PinnedMessagesTableFilterComposer - extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { - $$PinnedMessagesTableFilterComposer({ +class $$PollsTableFilterComposer + extends Composer<_$DriftChatDatabase, $PollsTable> { + $$PollsTableFilterComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -7560,106 +9571,59 @@ class $$PinnedMessagesTableFilterComposer ColumnFilters get id => $composableBuilder( column: $table.id, builder: (column) => ColumnFilters(column)); - ColumnFilters get messageText => $composableBuilder( - column: $table.messageText, builder: (column) => ColumnFilters(column)); - - ColumnWithTypeConverterFilters, List, String> - get attachments => $composableBuilder( - column: $table.attachments, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - ColumnFilters get state => $composableBuilder( - column: $table.state, builder: (column) => ColumnFilters(column)); + ColumnFilters get name => $composableBuilder( + column: $table.name, builder: (column) => ColumnFilters(column)); - ColumnFilters get type => $composableBuilder( - column: $table.type, builder: (column) => ColumnFilters(column)); + ColumnFilters get description => $composableBuilder( + column: $table.description, builder: (column) => ColumnFilters(column)); ColumnWithTypeConverterFilters, List, String> - get mentionedUsers => $composableBuilder( - column: $table.mentionedUsers, + get options => $composableBuilder( + column: $table.options, builder: (column) => ColumnWithTypeConverterFilters(column)); - ColumnWithTypeConverterFilters?, Map, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnWithTypeConverterFilters(column)); - - ColumnWithTypeConverterFilters?, Map, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, + ColumnWithTypeConverterFilters + get votingVisibility => $composableBuilder( + column: $table.votingVisibility, builder: (column) => ColumnWithTypeConverterFilters(column)); - ColumnFilters get parentId => $composableBuilder( - column: $table.parentId, builder: (column) => ColumnFilters(column)); - - ColumnFilters get quotedMessageId => $composableBuilder( - column: $table.quotedMessageId, - builder: (column) => ColumnFilters(column)); - - ColumnFilters get replyCount => $composableBuilder( - column: $table.replyCount, builder: (column) => ColumnFilters(column)); - - ColumnFilters get showInChannel => $composableBuilder( - column: $table.showInChannel, builder: (column) => ColumnFilters(column)); - - ColumnFilters get shadowed => $composableBuilder( - column: $table.shadowed, builder: (column) => ColumnFilters(column)); - - ColumnFilters get command => $composableBuilder( - column: $table.command, builder: (column) => ColumnFilters(column)); - - ColumnFilters get localCreatedAt => $composableBuilder( - column: $table.localCreatedAt, - builder: (column) => ColumnFilters(column)); - - ColumnFilters get remoteCreatedAt => $composableBuilder( - column: $table.remoteCreatedAt, - builder: (column) => ColumnFilters(column)); - - ColumnFilters get localUpdatedAt => $composableBuilder( - column: $table.localUpdatedAt, - builder: (column) => ColumnFilters(column)); - - ColumnFilters get remoteUpdatedAt => $composableBuilder( - column: $table.remoteUpdatedAt, + ColumnFilters get enforceUniqueVote => $composableBuilder( + column: $table.enforceUniqueVote, builder: (column) => ColumnFilters(column)); - ColumnFilters get localDeletedAt => $composableBuilder( - column: $table.localDeletedAt, + ColumnFilters get maxVotesAllowed => $composableBuilder( + column: $table.maxVotesAllowed, builder: (column) => ColumnFilters(column)); - ColumnFilters get remoteDeletedAt => $composableBuilder( - column: $table.remoteDeletedAt, + ColumnFilters get allowUserSuggestedOptions => $composableBuilder( + column: $table.allowUserSuggestedOptions, builder: (column) => ColumnFilters(column)); - ColumnFilters get messageTextUpdatedAt => $composableBuilder( - column: $table.messageTextUpdatedAt, - builder: (column) => ColumnFilters(column)); + ColumnFilters get allowAnswers => $composableBuilder( + column: $table.allowAnswers, builder: (column) => ColumnFilters(column)); - ColumnFilters get userId => $composableBuilder( - column: $table.userId, builder: (column) => ColumnFilters(column)); + ColumnFilters get isClosed => $composableBuilder( + column: $table.isClosed, builder: (column) => ColumnFilters(column)); - ColumnFilters get pinned => $composableBuilder( - column: $table.pinned, builder: (column) => ColumnFilters(column)); + ColumnFilters get answersCount => $composableBuilder( + column: $table.answersCount, builder: (column) => ColumnFilters(column)); - ColumnFilters get pinnedAt => $composableBuilder( - column: $table.pinnedAt, builder: (column) => ColumnFilters(column)); + ColumnWithTypeConverterFilters, Map, String> + get voteCountsByOption => $composableBuilder( + column: $table.voteCountsByOption, + builder: (column) => ColumnWithTypeConverterFilters(column)); - ColumnFilters get pinExpires => $composableBuilder( - column: $table.pinExpires, builder: (column) => ColumnFilters(column)); + ColumnFilters get voteCount => $composableBuilder( + column: $table.voteCount, builder: (column) => ColumnFilters(column)); - ColumnFilters get pinnedByUserId => $composableBuilder( - column: $table.pinnedByUserId, - builder: (column) => ColumnFilters(column)); + ColumnFilters get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => ColumnFilters(column)); - ColumnFilters get channelCid => $composableBuilder( - column: $table.channelCid, builder: (column) => ColumnFilters(column)); + ColumnFilters get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnFilters(column)); - ColumnWithTypeConverterFilters?, Map, - String> - get i18n => $composableBuilder( - column: $table.i18n, - builder: (column) => ColumnWithTypeConverterFilters(column)); + ColumnFilters get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnFilters(column)); ColumnWithTypeConverterFilters?, Map, String> @@ -7667,143 +9631,99 @@ class $$PinnedMessagesTableFilterComposer column: $table.extraData, builder: (column) => ColumnWithTypeConverterFilters(column)); - Expression pinnedMessageReactionsRefs( - Expression Function($$PinnedMessageReactionsTableFilterComposer f) - f) { - final $$PinnedMessageReactionsTableFilterComposer composer = - $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.id, - referencedTable: $db.pinnedMessageReactions, - getReferencedColumn: (t) => t.messageId, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$PinnedMessageReactionsTableFilterComposer( - $db: $db, - $table: $db.pinnedMessageReactions, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); + Expression pollVotesRefs( + Expression Function($$PollVotesTableFilterComposer f) f) { + final $$PollVotesTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.pollVotes, + getReferencedColumn: (t) => t.pollId, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PollVotesTableFilterComposer( + $db: $db, + $table: $db.pollVotes, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); return f(composer); } } -class $$PinnedMessagesTableOrderingComposer - extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { - $$PinnedMessagesTableOrderingComposer({ +class $$PollsTableOrderingComposer + extends Composer<_$DriftChatDatabase, $PollsTable> { + $$PollsTableOrderingComposer({ required super.$db, required super.$table, super.joinBuilder, super.$addJoinBuilderToRootComposer, - super.$removeJoinBuilderFromRootComposer, - }); - ColumnOrderings get id => $composableBuilder( - column: $table.id, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get messageText => $composableBuilder( - column: $table.messageText, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get attachments => $composableBuilder( - column: $table.attachments, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get state => $composableBuilder( - column: $table.state, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get type => $composableBuilder( - column: $table.type, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get mentionedUsers => $composableBuilder( - column: $table.mentionedUsers, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get reactionCounts => $composableBuilder( - column: $table.reactionCounts, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get reactionScores => $composableBuilder( - column: $table.reactionScores, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get parentId => $composableBuilder( - column: $table.parentId, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get quotedMessageId => $composableBuilder( - column: $table.quotedMessageId, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get replyCount => $composableBuilder( - column: $table.replyCount, builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get showInChannel => $composableBuilder( - column: $table.showInChannel, - builder: (column) => ColumnOrderings(column)); - - ColumnOrderings get shadowed => $composableBuilder( - column: $table.shadowed, builder: (column) => ColumnOrderings(column)); + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get command => $composableBuilder( - column: $table.command, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get name => $composableBuilder( + column: $table.name, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get localCreatedAt => $composableBuilder( - column: $table.localCreatedAt, - builder: (column) => ColumnOrderings(column)); + ColumnOrderings get description => $composableBuilder( + column: $table.description, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get remoteCreatedAt => $composableBuilder( - column: $table.remoteCreatedAt, - builder: (column) => ColumnOrderings(column)); + ColumnOrderings get options => $composableBuilder( + column: $table.options, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get localUpdatedAt => $composableBuilder( - column: $table.localUpdatedAt, + ColumnOrderings get votingVisibility => $composableBuilder( + column: $table.votingVisibility, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get remoteUpdatedAt => $composableBuilder( - column: $table.remoteUpdatedAt, + ColumnOrderings get enforceUniqueVote => $composableBuilder( + column: $table.enforceUniqueVote, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get localDeletedAt => $composableBuilder( - column: $table.localDeletedAt, + ColumnOrderings get maxVotesAllowed => $composableBuilder( + column: $table.maxVotesAllowed, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get remoteDeletedAt => $composableBuilder( - column: $table.remoteDeletedAt, + ColumnOrderings get allowUserSuggestedOptions => $composableBuilder( + column: $table.allowUserSuggestedOptions, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get messageTextUpdatedAt => $composableBuilder( - column: $table.messageTextUpdatedAt, + ColumnOrderings get allowAnswers => $composableBuilder( + column: $table.allowAnswers, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get userId => $composableBuilder( - column: $table.userId, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get isClosed => $composableBuilder( + column: $table.isClosed, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get pinned => $composableBuilder( - column: $table.pinned, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get answersCount => $composableBuilder( + column: $table.answersCount, + builder: (column) => ColumnOrderings(column)); - ColumnOrderings get pinnedAt => $composableBuilder( - column: $table.pinnedAt, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get voteCountsByOption => $composableBuilder( + column: $table.voteCountsByOption, + builder: (column) => ColumnOrderings(column)); - ColumnOrderings get pinExpires => $composableBuilder( - column: $table.pinExpires, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get voteCount => $composableBuilder( + column: $table.voteCount, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get pinnedByUserId => $composableBuilder( - column: $table.pinnedByUserId, - builder: (column) => ColumnOrderings(column)); + ColumnOrderings get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get channelCid => $composableBuilder( - column: $table.channelCid, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnOrderings(column)); - ColumnOrderings get i18n => $composableBuilder( - column: $table.i18n, builder: (column) => ColumnOrderings(column)); + ColumnOrderings get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnOrderings(column)); ColumnOrderings get extraData => $composableBuilder( column: $table.extraData, builder: (column) => ColumnOrderings(column)); } -class $$PinnedMessagesTableAnnotationComposer - extends Composer<_$DriftChatDatabase, $PinnedMessagesTable> { - $$PinnedMessagesTableAnnotationComposer({ +class $$PollsTableAnnotationComposer + extends Composer<_$DriftChatDatabase, $PollsTable> { + $$PollsTableAnnotationComposer({ required super.$db, required super.$table, super.joinBuilder, @@ -7813,316 +9733,523 @@ class $$PinnedMessagesTableAnnotationComposer GeneratedColumn get id => $composableBuilder(column: $table.id, builder: (column) => column); - GeneratedColumn get messageText => $composableBuilder( - column: $table.messageText, builder: (column) => column); + GeneratedColumn get name => + $composableBuilder(column: $table.name, builder: (column) => column); - GeneratedColumnWithTypeConverter, String> get attachments => - $composableBuilder( - column: $table.attachments, builder: (column) => column); + GeneratedColumn get description => $composableBuilder( + column: $table.description, builder: (column) => column); - GeneratedColumn get state => - $composableBuilder(column: $table.state, builder: (column) => column); + GeneratedColumnWithTypeConverter, String> get options => + $composableBuilder(column: $table.options, builder: (column) => column); - GeneratedColumn get type => - $composableBuilder(column: $table.type, builder: (column) => column); + GeneratedColumnWithTypeConverter + get votingVisibility => $composableBuilder( + column: $table.votingVisibility, builder: (column) => column); - GeneratedColumnWithTypeConverter, String> get mentionedUsers => - $composableBuilder( - column: $table.mentionedUsers, builder: (column) => column); + GeneratedColumn get enforceUniqueVote => $composableBuilder( + column: $table.enforceUniqueVote, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> - get reactionCounts => $composableBuilder( - column: $table.reactionCounts, builder: (column) => column); + GeneratedColumn get maxVotesAllowed => $composableBuilder( + column: $table.maxVotesAllowed, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> - get reactionScores => $composableBuilder( - column: $table.reactionScores, builder: (column) => column); + GeneratedColumn get allowUserSuggestedOptions => $composableBuilder( + column: $table.allowUserSuggestedOptions, builder: (column) => column); - GeneratedColumn get parentId => - $composableBuilder(column: $table.parentId, builder: (column) => column); + GeneratedColumn get allowAnswers => $composableBuilder( + column: $table.allowAnswers, builder: (column) => column); - GeneratedColumn get quotedMessageId => $composableBuilder( - column: $table.quotedMessageId, builder: (column) => column); + GeneratedColumn get isClosed => + $composableBuilder(column: $table.isClosed, builder: (column) => column); - GeneratedColumn get replyCount => $composableBuilder( - column: $table.replyCount, builder: (column) => column); + GeneratedColumn get answersCount => $composableBuilder( + column: $table.answersCount, builder: (column) => column); - GeneratedColumn get showInChannel => $composableBuilder( - column: $table.showInChannel, builder: (column) => column); + GeneratedColumnWithTypeConverter, String> + get voteCountsByOption => $composableBuilder( + column: $table.voteCountsByOption, builder: (column) => column); - GeneratedColumn get shadowed => - $composableBuilder(column: $table.shadowed, builder: (column) => column); + GeneratedColumn get voteCount => + $composableBuilder(column: $table.voteCount, builder: (column) => column); - GeneratedColumn get command => - $composableBuilder(column: $table.command, builder: (column) => column); + GeneratedColumn get createdById => $composableBuilder( + column: $table.createdById, builder: (column) => column); - GeneratedColumn get localCreatedAt => $composableBuilder( - column: $table.localCreatedAt, builder: (column) => column); + GeneratedColumn get createdAt => + $composableBuilder(column: $table.createdAt, builder: (column) => column); - GeneratedColumn get remoteCreatedAt => $composableBuilder( - column: $table.remoteCreatedAt, builder: (column) => column); + GeneratedColumn get updatedAt => + $composableBuilder(column: $table.updatedAt, builder: (column) => column); - GeneratedColumn get localUpdatedAt => $composableBuilder( - column: $table.localUpdatedAt, builder: (column) => column); + GeneratedColumnWithTypeConverter?, String> + get extraData => $composableBuilder( + column: $table.extraData, builder: (column) => column); - GeneratedColumn get remoteUpdatedAt => $composableBuilder( - column: $table.remoteUpdatedAt, builder: (column) => column); + Expression pollVotesRefs( + Expression Function($$PollVotesTableAnnotationComposer a) f) { + final $$PollVotesTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.id, + referencedTable: $db.pollVotes, + getReferencedColumn: (t) => t.pollId, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PollVotesTableAnnotationComposer( + $db: $db, + $table: $db.pollVotes, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return f(composer); + } +} - GeneratedColumn get localDeletedAt => $composableBuilder( - column: $table.localDeletedAt, builder: (column) => column); +class $$PollsTableTableManager extends RootTableManager< + _$DriftChatDatabase, + $PollsTable, + PollEntity, + $$PollsTableFilterComposer, + $$PollsTableOrderingComposer, + $$PollsTableAnnotationComposer, + $$PollsTableCreateCompanionBuilder, + $$PollsTableUpdateCompanionBuilder, + (PollEntity, $$PollsTableReferences), + PollEntity, + PrefetchHooks Function({bool pollVotesRefs})> { + $$PollsTableTableManager(_$DriftChatDatabase db, $PollsTable table) + : super(TableManagerState( + db: db, + table: table, + createFilteringComposer: () => + $$PollsTableFilterComposer($db: db, $table: table), + createOrderingComposer: () => + $$PollsTableOrderingComposer($db: db, $table: table), + createComputedFieldComposer: () => + $$PollsTableAnnotationComposer($db: db, $table: table), + updateCompanionCallback: ({ + Value id = const Value.absent(), + Value name = const Value.absent(), + Value description = const Value.absent(), + Value> options = const Value.absent(), + Value votingVisibility = const Value.absent(), + Value enforceUniqueVote = const Value.absent(), + Value maxVotesAllowed = const Value.absent(), + Value allowUserSuggestedOptions = const Value.absent(), + Value allowAnswers = const Value.absent(), + Value isClosed = const Value.absent(), + Value answersCount = const Value.absent(), + Value> voteCountsByOption = const Value.absent(), + Value voteCount = const Value.absent(), + Value createdById = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), + Value?> extraData = const Value.absent(), + Value rowid = const Value.absent(), + }) => + PollsCompanion( + id: id, + name: name, + description: description, + options: options, + votingVisibility: votingVisibility, + enforceUniqueVote: enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed, + allowUserSuggestedOptions: allowUserSuggestedOptions, + allowAnswers: allowAnswers, + isClosed: isClosed, + answersCount: answersCount, + voteCountsByOption: voteCountsByOption, + voteCount: voteCount, + createdById: createdById, + createdAt: createdAt, + updatedAt: updatedAt, + extraData: extraData, + rowid: rowid, + ), + createCompanionCallback: ({ + required String id, + required String name, + Value description = const Value.absent(), + required List options, + Value votingVisibility = const Value.absent(), + Value enforceUniqueVote = const Value.absent(), + Value maxVotesAllowed = const Value.absent(), + Value allowUserSuggestedOptions = const Value.absent(), + Value allowAnswers = const Value.absent(), + Value isClosed = const Value.absent(), + Value answersCount = const Value.absent(), + required Map voteCountsByOption, + Value voteCount = const Value.absent(), + Value createdById = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), + Value?> extraData = const Value.absent(), + Value rowid = const Value.absent(), + }) => + PollsCompanion.insert( + id: id, + name: name, + description: description, + options: options, + votingVisibility: votingVisibility, + enforceUniqueVote: enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed, + allowUserSuggestedOptions: allowUserSuggestedOptions, + allowAnswers: allowAnswers, + isClosed: isClosed, + answersCount: answersCount, + voteCountsByOption: voteCountsByOption, + voteCount: voteCount, + createdById: createdById, + createdAt: createdAt, + updatedAt: updatedAt, + extraData: extraData, + rowid: rowid, + ), + withReferenceMapper: (p0) => p0 + .map((e) => + (e.readTable(table), $$PollsTableReferences(db, table, e))) + .toList(), + prefetchHooksCallback: ({pollVotesRefs = false}) { + return PrefetchHooks( + db: db, + explicitlyWatchedTables: [if (pollVotesRefs) db.pollVotes], + addJoins: null, + getPrefetchedDataCallback: (items) async { + return [ + if (pollVotesRefs) + await $_getPrefetchedData( + currentTable: table, + referencedTable: + $$PollsTableReferences._pollVotesRefsTable(db), + managerFromTypedResult: (p0) => + $$PollsTableReferences(db, table, p0).pollVotesRefs, + referencedItemsForCurrentItem: (item, + referencedItems) => + referencedItems.where((e) => e.pollId == item.id), + typedResults: items) + ]; + }, + ); + }, + )); +} - GeneratedColumn get remoteDeletedAt => $composableBuilder( - column: $table.remoteDeletedAt, builder: (column) => column); +typedef $$PollsTableProcessedTableManager = ProcessedTableManager< + _$DriftChatDatabase, + $PollsTable, + PollEntity, + $$PollsTableFilterComposer, + $$PollsTableOrderingComposer, + $$PollsTableAnnotationComposer, + $$PollsTableCreateCompanionBuilder, + $$PollsTableUpdateCompanionBuilder, + (PollEntity, $$PollsTableReferences), + PollEntity, + PrefetchHooks Function({bool pollVotesRefs})>; +typedef $$PollVotesTableCreateCompanionBuilder = PollVotesCompanion Function({ + Value id, + Value pollId, + Value optionId, + Value answerText, + Value createdAt, + Value updatedAt, + Value userId, + Value rowid, +}); +typedef $$PollVotesTableUpdateCompanionBuilder = PollVotesCompanion Function({ + Value id, + Value pollId, + Value optionId, + Value answerText, + Value createdAt, + Value updatedAt, + Value userId, + Value rowid, +}); - GeneratedColumn get messageTextUpdatedAt => $composableBuilder( - column: $table.messageTextUpdatedAt, builder: (column) => column); +final class $$PollVotesTableReferences extends BaseReferences< + _$DriftChatDatabase, $PollVotesTable, PollVoteEntity> { + $$PollVotesTableReferences(super.$_db, super.$_table, super.$_typedResult); - GeneratedColumn get userId => - $composableBuilder(column: $table.userId, builder: (column) => column); + static $PollsTable _pollIdTable(_$DriftChatDatabase db) => db.polls + .createAlias($_aliasNameGenerator(db.pollVotes.pollId, db.polls.id)); - GeneratedColumn get pinned => - $composableBuilder(column: $table.pinned, builder: (column) => column); + $$PollsTableProcessedTableManager? get pollId { + if ($_item.pollId == null) return null; + final manager = $$PollsTableTableManager($_db, $_db.polls) + .filter((f) => f.id($_item.pollId!)); + final item = $_typedResult.readTableOrNull(_pollIdTable($_db)); + if (item == null) return manager; + return ProcessedTableManager( + manager.$state.copyWith(prefetchedData: [item])); + } +} + +class $$PollVotesTableFilterComposer + extends Composer<_$DriftChatDatabase, $PollVotesTable> { + $$PollVotesTableFilterComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnFilters get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnFilters(column)); + + ColumnFilters get optionId => $composableBuilder( + column: $table.optionId, builder: (column) => ColumnFilters(column)); + + ColumnFilters get answerText => $composableBuilder( + column: $table.answerText, builder: (column) => ColumnFilters(column)); + + ColumnFilters get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnFilters(column)); + + ColumnFilters get userId => $composableBuilder( + column: $table.userId, builder: (column) => ColumnFilters(column)); + + $$PollsTableFilterComposer get pollId { + final $$PollsTableFilterComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.pollId, + referencedTable: $db.polls, + getReferencedColumn: (t) => t.id, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PollsTableFilterComposer( + $db: $db, + $table: $db.polls, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return composer; + } +} + +class $$PollVotesTableOrderingComposer + extends Composer<_$DriftChatDatabase, $PollVotesTable> { + $$PollVotesTableOrderingComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + ColumnOrderings get id => $composableBuilder( + column: $table.id, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get optionId => $composableBuilder( + column: $table.optionId, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get answerText => $composableBuilder( + column: $table.answerText, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get createdAt => $composableBuilder( + column: $table.createdAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get updatedAt => $composableBuilder( + column: $table.updatedAt, builder: (column) => ColumnOrderings(column)); + + ColumnOrderings get userId => $composableBuilder( + column: $table.userId, builder: (column) => ColumnOrderings(column)); + + $$PollsTableOrderingComposer get pollId { + final $$PollsTableOrderingComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.pollId, + referencedTable: $db.polls, + getReferencedColumn: (t) => t.id, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PollsTableOrderingComposer( + $db: $db, + $table: $db.polls, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return composer; + } +} - GeneratedColumn get pinnedAt => - $composableBuilder(column: $table.pinnedAt, builder: (column) => column); +class $$PollVotesTableAnnotationComposer + extends Composer<_$DriftChatDatabase, $PollVotesTable> { + $$PollVotesTableAnnotationComposer({ + required super.$db, + required super.$table, + super.joinBuilder, + super.$addJoinBuilderToRootComposer, + super.$removeJoinBuilderFromRootComposer, + }); + GeneratedColumn get id => + $composableBuilder(column: $table.id, builder: (column) => column); - GeneratedColumn get pinExpires => $composableBuilder( - column: $table.pinExpires, builder: (column) => column); + GeneratedColumn get optionId => + $composableBuilder(column: $table.optionId, builder: (column) => column); - GeneratedColumn get pinnedByUserId => $composableBuilder( - column: $table.pinnedByUserId, builder: (column) => column); + GeneratedColumn get answerText => $composableBuilder( + column: $table.answerText, builder: (column) => column); - GeneratedColumn get channelCid => $composableBuilder( - column: $table.channelCid, builder: (column) => column); + GeneratedColumn get createdAt => + $composableBuilder(column: $table.createdAt, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> get i18n => - $composableBuilder(column: $table.i18n, builder: (column) => column); + GeneratedColumn get updatedAt => + $composableBuilder(column: $table.updatedAt, builder: (column) => column); - GeneratedColumnWithTypeConverter?, String> - get extraData => $composableBuilder( - column: $table.extraData, builder: (column) => column); + GeneratedColumn get userId => + $composableBuilder(column: $table.userId, builder: (column) => column); - Expression pinnedMessageReactionsRefs( - Expression Function($$PinnedMessageReactionsTableAnnotationComposer a) - f) { - final $$PinnedMessageReactionsTableAnnotationComposer composer = - $composerBuilder( - composer: this, - getCurrentColumn: (t) => t.id, - referencedTable: $db.pinnedMessageReactions, - getReferencedColumn: (t) => t.messageId, - builder: (joinBuilder, - {$addJoinBuilderToRootComposer, - $removeJoinBuilderFromRootComposer}) => - $$PinnedMessageReactionsTableAnnotationComposer( - $db: $db, - $table: $db.pinnedMessageReactions, - $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, - joinBuilder: joinBuilder, - $removeJoinBuilderFromRootComposer: - $removeJoinBuilderFromRootComposer, - )); - return f(composer); + $$PollsTableAnnotationComposer get pollId { + final $$PollsTableAnnotationComposer composer = $composerBuilder( + composer: this, + getCurrentColumn: (t) => t.pollId, + referencedTable: $db.polls, + getReferencedColumn: (t) => t.id, + builder: (joinBuilder, + {$addJoinBuilderToRootComposer, + $removeJoinBuilderFromRootComposer}) => + $$PollsTableAnnotationComposer( + $db: $db, + $table: $db.polls, + $addJoinBuilderToRootComposer: $addJoinBuilderToRootComposer, + joinBuilder: joinBuilder, + $removeJoinBuilderFromRootComposer: + $removeJoinBuilderFromRootComposer, + )); + return composer; } } -class $$PinnedMessagesTableTableManager extends RootTableManager< +class $$PollVotesTableTableManager extends RootTableManager< _$DriftChatDatabase, - $PinnedMessagesTable, - PinnedMessageEntity, - $$PinnedMessagesTableFilterComposer, - $$PinnedMessagesTableOrderingComposer, - $$PinnedMessagesTableAnnotationComposer, - $$PinnedMessagesTableCreateCompanionBuilder, - $$PinnedMessagesTableUpdateCompanionBuilder, - (PinnedMessageEntity, $$PinnedMessagesTableReferences), - PinnedMessageEntity, - PrefetchHooks Function({bool pinnedMessageReactionsRefs})> { - $$PinnedMessagesTableTableManager( - _$DriftChatDatabase db, $PinnedMessagesTable table) + $PollVotesTable, + PollVoteEntity, + $$PollVotesTableFilterComposer, + $$PollVotesTableOrderingComposer, + $$PollVotesTableAnnotationComposer, + $$PollVotesTableCreateCompanionBuilder, + $$PollVotesTableUpdateCompanionBuilder, + (PollVoteEntity, $$PollVotesTableReferences), + PollVoteEntity, + PrefetchHooks Function({bool pollId})> { + $$PollVotesTableTableManager(_$DriftChatDatabase db, $PollVotesTable table) : super(TableManagerState( db: db, table: table, createFilteringComposer: () => - $$PinnedMessagesTableFilterComposer($db: db, $table: table), + $$PollVotesTableFilterComposer($db: db, $table: table), createOrderingComposer: () => - $$PinnedMessagesTableOrderingComposer($db: db, $table: table), + $$PollVotesTableOrderingComposer($db: db, $table: table), createComputedFieldComposer: () => - $$PinnedMessagesTableAnnotationComposer($db: db, $table: table), + $$PollVotesTableAnnotationComposer($db: db, $table: table), updateCompanionCallback: ({ - Value id = const Value.absent(), - Value messageText = const Value.absent(), - Value> attachments = const Value.absent(), - Value state = const Value.absent(), - Value type = const Value.absent(), - Value> mentionedUsers = const Value.absent(), - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), - Value parentId = const Value.absent(), - Value quotedMessageId = const Value.absent(), - Value replyCount = const Value.absent(), - Value showInChannel = const Value.absent(), - Value shadowed = const Value.absent(), - Value command = const Value.absent(), - Value localCreatedAt = const Value.absent(), - Value remoteCreatedAt = const Value.absent(), - Value localUpdatedAt = const Value.absent(), - Value remoteUpdatedAt = const Value.absent(), - Value localDeletedAt = const Value.absent(), - Value remoteDeletedAt = const Value.absent(), - Value messageTextUpdatedAt = const Value.absent(), + Value id = const Value.absent(), + Value pollId = const Value.absent(), + Value optionId = const Value.absent(), + Value answerText = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), Value userId = const Value.absent(), - Value pinned = const Value.absent(), - Value pinnedAt = const Value.absent(), - Value pinExpires = const Value.absent(), - Value pinnedByUserId = const Value.absent(), - Value channelCid = const Value.absent(), - Value?> i18n = const Value.absent(), - Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - PinnedMessagesCompanion( + PollVotesCompanion( id: id, - messageText: messageText, - attachments: attachments, - state: state, - type: type, - mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, - parentId: parentId, - quotedMessageId: quotedMessageId, - replyCount: replyCount, - showInChannel: showInChannel, - shadowed: shadowed, - command: command, - localCreatedAt: localCreatedAt, - remoteCreatedAt: remoteCreatedAt, - localUpdatedAt: localUpdatedAt, - remoteUpdatedAt: remoteUpdatedAt, - localDeletedAt: localDeletedAt, - remoteDeletedAt: remoteDeletedAt, - messageTextUpdatedAt: messageTextUpdatedAt, + pollId: pollId, + optionId: optionId, + answerText: answerText, + createdAt: createdAt, + updatedAt: updatedAt, userId: userId, - pinned: pinned, - pinnedAt: pinnedAt, - pinExpires: pinExpires, - pinnedByUserId: pinnedByUserId, - channelCid: channelCid, - i18n: i18n, - extraData: extraData, rowid: rowid, ), createCompanionCallback: ({ - required String id, - Value messageText = const Value.absent(), - required List attachments, - required String state, - Value type = const Value.absent(), - required List mentionedUsers, - Value?> reactionCounts = const Value.absent(), - Value?> reactionScores = const Value.absent(), - Value parentId = const Value.absent(), - Value quotedMessageId = const Value.absent(), - Value replyCount = const Value.absent(), - Value showInChannel = const Value.absent(), - Value shadowed = const Value.absent(), - Value command = const Value.absent(), - Value localCreatedAt = const Value.absent(), - Value remoteCreatedAt = const Value.absent(), - Value localUpdatedAt = const Value.absent(), - Value remoteUpdatedAt = const Value.absent(), - Value localDeletedAt = const Value.absent(), - Value remoteDeletedAt = const Value.absent(), - Value messageTextUpdatedAt = const Value.absent(), + Value id = const Value.absent(), + Value pollId = const Value.absent(), + Value optionId = const Value.absent(), + Value answerText = const Value.absent(), + Value createdAt = const Value.absent(), + Value updatedAt = const Value.absent(), Value userId = const Value.absent(), - Value pinned = const Value.absent(), - Value pinnedAt = const Value.absent(), - Value pinExpires = const Value.absent(), - Value pinnedByUserId = const Value.absent(), - required String channelCid, - Value?> i18n = const Value.absent(), - Value?> extraData = const Value.absent(), Value rowid = const Value.absent(), }) => - PinnedMessagesCompanion.insert( + PollVotesCompanion.insert( id: id, - messageText: messageText, - attachments: attachments, - state: state, - type: type, - mentionedUsers: mentionedUsers, - reactionCounts: reactionCounts, - reactionScores: reactionScores, - parentId: parentId, - quotedMessageId: quotedMessageId, - replyCount: replyCount, - showInChannel: showInChannel, - shadowed: shadowed, - command: command, - localCreatedAt: localCreatedAt, - remoteCreatedAt: remoteCreatedAt, - localUpdatedAt: localUpdatedAt, - remoteUpdatedAt: remoteUpdatedAt, - localDeletedAt: localDeletedAt, - remoteDeletedAt: remoteDeletedAt, - messageTextUpdatedAt: messageTextUpdatedAt, + pollId: pollId, + optionId: optionId, + answerText: answerText, + createdAt: createdAt, + updatedAt: updatedAt, userId: userId, - pinned: pinned, - pinnedAt: pinnedAt, - pinExpires: pinExpires, - pinnedByUserId: pinnedByUserId, - channelCid: channelCid, - i18n: i18n, - extraData: extraData, rowid: rowid, ), withReferenceMapper: (p0) => p0 .map((e) => ( e.readTable(table), - $$PinnedMessagesTableReferences(db, table, e) + $$PollVotesTableReferences(db, table, e) )) .toList(), - prefetchHooksCallback: ({pinnedMessageReactionsRefs = false}) { + prefetchHooksCallback: ({pollId = false}) { return PrefetchHooks( db: db, - explicitlyWatchedTables: [ - if (pinnedMessageReactionsRefs) db.pinnedMessageReactions - ], - addJoins: null, + explicitlyWatchedTables: [], + addJoins: < + T extends TableManagerState< + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic, + dynamic>>(state) { + if (pollId) { + state = state.withJoin( + currentTable: table, + currentColumn: table.pollId, + referencedTable: + $$PollVotesTableReferences._pollIdTable(db), + referencedColumn: + $$PollVotesTableReferences._pollIdTable(db).id, + ) as T; + } + + return state; + }, getPrefetchedDataCallback: (items) async { - return [ - if (pinnedMessageReactionsRefs) - await $_getPrefetchedData( - currentTable: table, - referencedTable: $$PinnedMessagesTableReferences - ._pinnedMessageReactionsRefsTable(db), - managerFromTypedResult: (p0) => - $$PinnedMessagesTableReferences(db, table, p0) - .pinnedMessageReactionsRefs, - referencedItemsForCurrentItem: - (item, referencedItems) => referencedItems - .where((e) => e.messageId == item.id), - typedResults: items) - ]; + return []; }, ); }, )); } -typedef $$PinnedMessagesTableProcessedTableManager = ProcessedTableManager< +typedef $$PollVotesTableProcessedTableManager = ProcessedTableManager< _$DriftChatDatabase, - $PinnedMessagesTable, - PinnedMessageEntity, - $$PinnedMessagesTableFilterComposer, - $$PinnedMessagesTableOrderingComposer, - $$PinnedMessagesTableAnnotationComposer, - $$PinnedMessagesTableCreateCompanionBuilder, - $$PinnedMessagesTableUpdateCompanionBuilder, - (PinnedMessageEntity, $$PinnedMessagesTableReferences), - PinnedMessageEntity, - PrefetchHooks Function({bool pinnedMessageReactionsRefs})>; + $PollVotesTable, + PollVoteEntity, + $$PollVotesTableFilterComposer, + $$PollVotesTableOrderingComposer, + $$PollVotesTableAnnotationComposer, + $$PollVotesTableCreateCompanionBuilder, + $$PollVotesTableUpdateCompanionBuilder, + (PollVoteEntity, $$PollVotesTableReferences), + PollVoteEntity, + PrefetchHooks Function({bool pollId})>; typedef $$PinnedMessageReactionsTableCreateCompanionBuilder = PinnedMessageReactionsCompanion Function({ required String userId, @@ -9927,6 +12054,10 @@ class $DriftChatDatabaseManager { $$MessagesTableTableManager(_db, _db.messages); $$PinnedMessagesTableTableManager get pinnedMessages => $$PinnedMessagesTableTableManager(_db, _db.pinnedMessages); + $$PollsTableTableManager get polls => + $$PollsTableTableManager(_db, _db.polls); + $$PollVotesTableTableManager get pollVotes => + $$PollVotesTableTableManager(_db, _db.pollVotes); $$PinnedMessageReactionsTableTableManager get pinnedMessageReactions => $$PinnedMessageReactionsTableTableManager( _db, _db.pinnedMessageReactions); diff --git a/packages/stream_chat_persistence/lib/src/entity/entity.dart b/packages/stream_chat_persistence/lib/src/entity/entity.dart index 736fe4058..41778641d 100644 --- a/packages/stream_chat_persistence/lib/src/entity/entity.dart +++ b/packages/stream_chat_persistence/lib/src/entity/entity.dart @@ -5,6 +5,8 @@ export 'members.dart'; export 'messages.dart'; export 'pinned_message_reactions.dart'; export 'pinned_messages.dart'; +export 'poll_votes.dart'; +export 'polls.dart'; export 'reactions.dart'; export 'reads.dart'; export 'users.dart'; diff --git a/packages/stream_chat_persistence/lib/src/entity/messages.dart b/packages/stream_chat_persistence/lib/src/entity/messages.dart index fb60d9151..69c38f0c8 100644 --- a/packages/stream_chat_persistence/lib/src/entity/messages.dart +++ b/packages/stream_chat_persistence/lib/src/entity/messages.dart @@ -38,6 +38,9 @@ class Messages extends Table { /// The ID of the quoted message, if the message is a quoted reply. TextColumn get quotedMessageId => text().nullable()(); + /// The ID of the poll, if the message is a poll. + TextColumn get pollId => text().nullable()(); + /// Number of replies for this message. IntColumn get replyCount => integer().nullable()(); diff --git a/packages/stream_chat_persistence/lib/src/entity/poll_votes.dart b/packages/stream_chat_persistence/lib/src/entity/poll_votes.dart new file mode 100644 index 000000000..5087b5a0d --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/entity/poll_votes.dart @@ -0,0 +1,38 @@ +// coverage:ignore-file +import 'package:drift/drift.dart'; +import 'package:stream_chat_persistence/src/entity/entity.dart'; + +/// Represents a [PollVotes] table in [MoorChatDatabase]. +@DataClassName('PollVoteEntity') +class PollVotes extends Table { + /// The unique identifier of the poll vote. + TextColumn get id => text().nullable()(); + + /// The unique identifier of the poll the vote belongs to. + TextColumn get pollId => + text().nullable().references(Polls, #id, onDelete: KeyAction.cascade)(); + + /// The unique identifier of the option selected in the poll. + /// + /// Nullable if the user provided an answer. + TextColumn get optionId => text().nullable()(); + + /// The text of the answer provided in the poll. + /// + /// Nullable if the user selected an option. + TextColumn get answerText => text().nullable()(); + + /// The date when the poll vote was created. + DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)(); + + /// The date when the poll vote was last updated. + DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)(); + + /// The unique identifier of the user who voted. + /// + /// Nullable if the poll is anonymous. + TextColumn get userId => text().nullable()(); + + @override + Set get primaryKey => {id, pollId}; +} diff --git a/packages/stream_chat_persistence/lib/src/entity/polls.dart b/packages/stream_chat_persistence/lib/src/entity/polls.dart new file mode 100644 index 000000000..f377301db --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/entity/polls.dart @@ -0,0 +1,75 @@ +// coverage:ignore-file +import 'package:drift/drift.dart'; +import 'package:stream_chat_persistence/src/converter/list_converter.dart'; +import 'package:stream_chat_persistence/src/converter/map_converter.dart'; +import 'package:stream_chat_persistence/src/converter/voting_visibility_converter.dart'; + +/// Represents a [Polls] table in [MoorChatDatabase]. +@DataClassName('PollEntity') +class Polls extends Table { + /// The unique identifier of the poll. + TextColumn get id => text()(); + + /// The name of the poll. + TextColumn get name => text()(); + + /// The description of the poll. + TextColumn get description => text().nullable()(); + + /// The list of options available for the poll. + TextColumn get options => text().map(ListConverter())(); + + /// Represents the visibility of the voting process. + /// + /// Defaults to 'public'. + TextColumn get votingVisibility => text() + .map(const VotingVisibilityConverter()) + .withDefault(const Constant('public'))(); + + /// If true, only unique votes are allowed. + /// + /// Defaults to false. + BoolColumn get enforceUniqueVote => + boolean().withDefault(const Constant(false))(); + + /// The maximum number of votes allowed per user. + IntColumn get maxVotesAllowed => integer().nullable()(); + + /// If true, users can suggest their own options. + /// + /// Defaults to false. + BoolColumn get allowUserSuggestedOptions => + boolean().withDefault(const Constant(false))(); + + /// If true, users can provide their own answers/comments. + /// + /// Defaults to false. + BoolColumn get allowAnswers => boolean().withDefault(const Constant(false))(); + + /// Indicates if the poll is closed. + BoolColumn get isClosed => boolean().withDefault(const Constant(false))(); + + /// The total number of answers received by the poll. + IntColumn get answersCount => integer().withDefault(const Constant(0))(); + + /// Map of vote counts by option. + TextColumn get voteCountsByOption => text().map(MapConverter())(); + + /// The total number of votes received by the poll. + IntColumn get voteCount => integer().withDefault(const Constant(0))(); + + /// The id of the user who created the poll. + TextColumn get createdById => text().nullable()(); + + /// The date when the poll was created. + DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)(); + + /// The date when the poll was last updated. + DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)(); + + /// Map of custom poll extraData + TextColumn get extraData => text().nullable().map(MapConverter())(); + + @override + Set get primaryKey => {id}; +} diff --git a/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart index 84804b880..33e307141 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/message_mapper.dart @@ -12,6 +12,7 @@ extension MessageEntityX on MessageEntity { List? latestReactions, List? ownReactions, Message? quotedMessage, + Poll? poll, }) => Message( shadowed: shadowed, @@ -36,6 +37,8 @@ extension MessageEntityX on MessageEntity { parentId: parentId, quotedMessageId: quotedMessageId, quotedMessage: quotedMessage, + pollId: pollId, + poll: poll, reactionCounts: reactionCounts, reactionScores: reactionScores, replyCount: replyCount, @@ -62,6 +65,7 @@ extension MessageX on Message { type: type, parentId: parentId, quotedMessageId: quotedMessageId, + pollId: pollId, command: command, remoteCreatedAt: remoteCreatedAt, localCreatedAt: localCreatedAt, diff --git a/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart index 1993218f3..1f0b8d4fb 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/pinned_message_mapper.dart @@ -12,6 +12,7 @@ extension PinnedMessageEntityX on PinnedMessageEntity { List? latestReactions, List? ownReactions, Message? quotedMessage, + Poll? poll, }) => Message( shadowed: shadowed, @@ -36,6 +37,8 @@ extension PinnedMessageEntityX on PinnedMessageEntity { parentId: parentId, quotedMessageId: quotedMessageId, quotedMessage: quotedMessage, + pollId: pollId, + poll: poll, reactionCounts: reactionCounts, reactionScores: reactionScores, replyCount: replyCount, @@ -63,6 +66,7 @@ extension PMessageX on Message { type: type, parentId: parentId, quotedMessageId: quotedMessageId, + pollId: pollId, command: command, remoteCreatedAt: remoteCreatedAt, localCreatedAt: localCreatedAt, diff --git a/packages/stream_chat_persistence/lib/src/mapper/poll_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/poll_mapper.dart new file mode 100644 index 000000000..451b5e853 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/mapper/poll_mapper.dart @@ -0,0 +1,66 @@ +import 'dart:convert'; + +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; + +/// Useful mapping functions for [PollEntity] +extension PollEntityX on PollEntity { + /// Maps a [PollEntity] into [Poll] + Poll toPoll({ + User? createdBy, + List latestAnswers = const [], + List ownVotesAndAnswers = const [], + Map> latestVotesByOption = const {}, + }) { + return Poll( + id: id, + name: name, + description: description, + options: options.map((it) { + final json = jsonDecode(it); + return PollOption.fromJson(json); + }).toList(), + votingVisibility: votingVisibility, + enforceUniqueVote: enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed, + allowAnswers: allowAnswers, + latestAnswers: latestAnswers, + answersCount: answersCount, + allowUserSuggestedOptions: allowUserSuggestedOptions, + isClosed: isClosed, + createdAt: createdAt, + updatedAt: updatedAt, + voteCountsByOption: voteCountsByOption, + voteCount: voteCount, + latestVotesByOption: latestVotesByOption, + createdById: createdById, + createdBy: createdBy, + ownVotesAndAnswers: ownVotesAndAnswers, + extraData: extraData ?? {}, + ); + } +} + +/// Useful mapping functions for [Poll] +extension PollX on Poll { + /// Maps a [Poll] into [PollEntity] + PollEntity toEntity() => PollEntity( + id: id, + name: name, + description: description, + options: options.map(jsonEncode).toList(), + votingVisibility: votingVisibility, + enforceUniqueVote: enforceUniqueVote, + maxVotesAllowed: maxVotesAllowed, + allowAnswers: allowAnswers, + answersCount: answersCount, + allowUserSuggestedOptions: allowUserSuggestedOptions, + isClosed: isClosed, + createdAt: createdAt, + updatedAt: updatedAt, + voteCountsByOption: voteCountsByOption, + voteCount: voteCount, + createdById: createdById, + extraData: extraData, + ); +} diff --git a/packages/stream_chat_persistence/lib/src/mapper/poll_vote_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/poll_vote_mapper.dart new file mode 100644 index 000000000..25fa23ab3 --- /dev/null +++ b/packages/stream_chat_persistence/lib/src/mapper/poll_vote_mapper.dart @@ -0,0 +1,34 @@ +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; + +/// Useful mapping functions for [PollVoteEntity] +extension PollVoteEntityX on PollVoteEntity { + /// Maps a [PollVoteEntity] into [PollVote] + PollVote toPollVote({ + User? user, + }) => + PollVote( + id: id, + pollId: pollId, + optionId: optionId, + answerText: answerText, + createdAt: createdAt, + updatedAt: updatedAt, + userId: userId, + user: user, + ); +} + +/// Useful mapping functions for [PollVote] +extension PollVoteX on PollVote { + /// Maps a [PollVote] into [PollVoteEntity] + PollVoteEntity toEntity() => PollVoteEntity( + id: id, + pollId: pollId, + optionId: optionId, + answerText: answerText, + createdAt: createdAt, + updatedAt: updatedAt, + userId: userId, + ); +} diff --git a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart index 8b20715e8..089b1544c 100644 --- a/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart +++ b/packages/stream_chat_persistence/lib/src/stream_chat_persistence_client.dart @@ -315,6 +315,20 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { return db!.channelDao.updateChannels(channels); } + @override + Future updatePolls(List polls) { + assert(_debugIsConnected, ''); + _logger.info('updatePolls'); + return db!.pollDao.updatePolls(polls); + } + + @override + Future deletePollsByIds(List pollIds) { + assert(_debugIsConnected, ''); + _logger.info('deletePollsByIds'); + return db!.pollDao.deletePollsByIds(pollIds); + } + @override Future bulkUpdateMembers(Map?> members) { assert(_debugIsConnected, ''); @@ -336,6 +350,13 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { return db!.pinnedMessageDao.bulkUpdateMessages(messages); } + @override + Future updatePollVotes(List pollVotes) { + assert(_debugIsConnected, ''); + _logger.info('updatePollVotes'); + return db!.pollVoteDao.updatePollVotes(pollVotes); + } + @override Future updatePinnedMessageReactions(List reactions) { assert(_debugIsConnected, ''); @@ -380,6 +401,13 @@ class StreamChatPersistenceClient extends ChatPersistenceClient { return db!.reactionDao.deleteReactionsByMessageIds(messageIds); } + @override + Future deletePollVotesByPollIds(List pollIds) { + assert(_debugIsConnected, ''); + _logger.info('deletePollVotesByPollIds'); + return db!.pollVoteDao.deletePollVotesByPollIds(pollIds); + } + @override Future deleteMembersByCids(List cids) { assert(_debugIsConnected, ''); diff --git a/packages/stream_chat_persistence/pubspec.yaml b/packages/stream_chat_persistence/pubspec.yaml index a84b9da6a..8f2b7a6e8 100644 --- a/packages/stream_chat_persistence/pubspec.yaml +++ b/packages/stream_chat_persistence/pubspec.yaml @@ -29,7 +29,7 @@ dependencies: meta: ^1.9.1 path: ^1.8.3 path_provider: ^2.1.3 - sqlite3_flutter_libs: ^0.5.24 + sqlite3_flutter_libs: ^0.5.26 stream_chat: ^8.3.0 dev_dependencies: diff --git a/packages/stream_chat_persistence/test/mock_chat_database.dart b/packages/stream_chat_persistence/test/mock_chat_database.dart index 196c85738..1bd48f5f9 100644 --- a/packages/stream_chat_persistence/test/mock_chat_database.dart +++ b/packages/stream_chat_persistence/test/mock_chat_database.dart @@ -3,59 +3,57 @@ import 'package:stream_chat_persistence/src/dao/dao.dart'; import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; class MockChatDatabase extends Mock implements DriftChatDatabase { - UserDao? _userDao; - @override UserDao get userDao => _userDao ??= MockUserDao(); - - ChannelDao? _channelDao; + UserDao? _userDao; @override ChannelDao get channelDao => _channelDao ??= MockChannelDao(); - - MessageDao? _messageDao; + ChannelDao? _channelDao; @override MessageDao get messageDao => _messageDao ??= MockMessageDao(); - - PinnedMessageDao? _pinnedMessageDao; + MessageDao? _messageDao; @override PinnedMessageDao get pinnedMessageDao => _pinnedMessageDao ??= MockPinnedMessageDao(); - - MemberDao? _memberDao; + PinnedMessageDao? _pinnedMessageDao; @override MemberDao get memberDao => _memberDao ??= MockMemberDao(); - - ReactionDao? _reactionDao; + MemberDao? _memberDao; @override ReactionDao get reactionDao => _reactionDao ??= MockReactionDao(); - - PinnedMessageReactionDao? _pinnedMessageReactionDao; + ReactionDao? _reactionDao; @override PinnedMessageReactionDao get pinnedMessageReactionDao => _pinnedMessageReactionDao ??= MockPinnedMessageReactionDao(); - - ReadDao? _readDao; + PinnedMessageReactionDao? _pinnedMessageReactionDao; @override ReadDao get readDao => _readDao ??= MockReadDao(); - - ChannelQueryDao? _channelQueryDao; + ReadDao? _readDao; @override ChannelQueryDao get channelQueryDao => _channelQueryDao ??= MockChannelQueryDao(); - - ConnectionEventDao? _connectionEventDao; + ChannelQueryDao? _channelQueryDao; @override ConnectionEventDao get connectionEventDao => _connectionEventDao ??= MockConnectionEventDao(); + ConnectionEventDao? _connectionEventDao; + + @override + PollDao get pollDao => _pollDao ??= MockPollDao(); + PollDao? _pollDao; + + @override + PollVoteDao get pollVoteDao => _pollVoteDao ??= MockPollVoteDao(); + PollVoteDao? _pollVoteDao; @override Future flush() => Future.value(); @@ -84,3 +82,7 @@ class MockReadDao extends Mock implements ReadDao {} class MockChannelQueryDao extends Mock implements ChannelQueryDao {} class MockConnectionEventDao extends Mock implements ConnectionEventDao {} + +class MockPollDao extends Mock implements PollDao {} + +class MockPollVoteDao extends Mock implements PollVoteDao {} diff --git a/packages/stream_chat_persistence/test/src/converter/voting_visibility_converter_test.dart b/packages/stream_chat_persistence/test/src/converter/voting_visibility_converter_test.dart new file mode 100644 index 000000000..f99a44e70 --- /dev/null +++ b/packages/stream_chat_persistence/test/src/converter/voting_visibility_converter_test.dart @@ -0,0 +1,26 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/converter/voting_visibility_converter.dart'; + +void main() { + group('VotingVisibilityConverter', () { + const converter = VotingVisibilityConverter(); + + test('toSql converts VotingVisibility to String', () { + expect(converter.toSql(VotingVisibility.anonymous), 'anonymous'); + expect(converter.toSql(VotingVisibility.public), 'public'); + }); + + test('fromSql converts String to VotingVisibility', () { + expect(converter.fromSql('anonymous'), VotingVisibility.anonymous); + expect(converter.fromSql('public'), VotingVisibility.public); + }); + + test('fromSql throws ArgumentError for invalid String', () { + expect( + () => converter.fromSql('invalid_value'), + throwsA(isA()), + ); + }); + }); +} diff --git a/packages/stream_chat_persistence/test/src/dao/poll_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/poll_dao_test.dart new file mode 100644 index 000000000..3f0b55167 --- /dev/null +++ b/packages/stream_chat_persistence/test/src/dao/poll_dao_test.dart @@ -0,0 +1,170 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/dao/dao.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; + +import '../../stream_chat_persistence_client_test.dart'; + +void main() { + late PollDao pollDao; + late DriftChatDatabase database; + + setUp(() { + database = testDatabaseProvider('testUserId'); + pollDao = database.pollDao; + }); + + List _expandPollVotes(Poll poll) { + final latestAnswers = poll.latestAnswers; + final latestVotes = poll.latestVotesByOption.values; + final ownVotesAndAnswers = poll.ownVotesAndAnswers; + return [ + ...latestAnswers, + ...latestVotes.expand((it) => it), + ...ownVotesAndAnswers, + ]; + } + + Future> _preparePollData({int count = 3}) async { + final polls = []; + + for (var i = 0; i < count; i++) { + final pollId = 'poll-$i'; + + final createdBy = User(id: 'user-$i', name: 'User $i'); + + const options = [ + PollOption(id: 'option-1', text: 'Red'), + PollOption(id: 'option-2', text: 'Blue'), + PollOption(id: 'option-3', text: 'Green'), + ]; + + final latestVotesByOption = { + for (final option in options) + option.id!: [ + for (var i = 0; i < count; i++) + PollVote( + id: 'pollVote-$i', + pollId: pollId, + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: option.id, + createdAt: DateTime.now(), + ), + ], + }; + + final voteCountsByOption = latestVotesByOption.map( + (key, value) => MapEntry(key, value.length), + ); + + final poll = Poll( + id: pollId, + name: 'testQuestion', + createdBy: createdBy, + createdById: createdBy.id, + options: options, + latestVotesByOption: latestVotesByOption, + voteCount: voteCountsByOption.values.reduce((a, b) => a + b), + voteCountsByOption: voteCountsByOption, + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + enforceUniqueVote: false, + extraData: const {'test_extra_data': 'extraData'}, + ); + + polls.add(poll); + } + + final users = polls.map((it) => it.createdBy!).toList(); + final pollVotes = polls.expand(_expandPollVotes).toList(); + + await database.userDao.updateUsers(users); + await pollDao.updatePolls(polls); + await database.pollVoteDao.updatePollVotes(pollVotes); + + return polls; + } + + test('getPolls', () async { + // Should be empty initially + final polls = await pollDao.getPolls(); + expect(polls, isEmpty); + + // Adding sample polls + final insertedPolls = await _preparePollData(); + expect(insertedPolls, isNotEmpty); + + // Fetched polls length should match inserted polls length. + final fetchedPollVotes = await pollDao.getPolls(); + expect(fetchedPollVotes.length, insertedPolls.length); + }); + + test('updatePolls', () async { + // Preparing test data + final insertedPolls = await _preparePollData(); + + // Adding a new poll + final newPoll = insertedPolls.first.copyWith(id: 'newPollId'); + + await pollDao.updatePolls([newPoll]); + + // Fetched users length should be one more than inserted users. + // Fetched users should contain the newUser. + final fetchedPolls = await pollDao.getPolls(); + expect(fetchedPolls.length, insertedPolls.length + 1); + expect(fetchedPolls.any((it) => it.id == newPoll.id), isTrue); + }); + + test('getPollById', () async { + // Preparing test data + final insertedPolls = await _preparePollData(); + + // Fetched poll should not be null + final pollToFetch = insertedPolls.first; + final fetchedPoll = await pollDao.getPollById(pollToFetch.id); + expect(fetchedPoll!.id, pollToFetch.id); + }); + + test('deletePollsByIds', () async { + // Preparing test data + final insertedPolls = await _preparePollData(); + + // Deleting the first poll + final pollToDelete = insertedPolls.first; + await pollDao.deletePollsByIds([pollToDelete.id]); + + // Fetched poll list should be one less than inserted polls. + final fetchedPolls = await pollDao.getPolls(); + expect(fetchedPolls.length, insertedPolls.length - 1); + expect(fetchedPolls.any((it) => it.id == pollToDelete.id), isFalse); + }); + + test('deleting a poll should also delete its votes', () async { + // Preparing test data + final insertedPolls = await _preparePollData(); + + // Verify that the poll has votes + final pollToDelete = insertedPolls.first; + final pollVotes = await database.pollVoteDao.getPollVotes(pollToDelete.id); + expect(pollVotes, isNotEmpty); + + // Delete the poll + await pollDao.deletePollsByIds([pollToDelete.id]); + + // Fetched poll list should be one less than inserted polls. + final fetchedPolls = await pollDao.getPolls(); + expect(fetchedPolls.length, insertedPolls.length - 1); + expect(fetchedPolls.any((it) => it.id == pollToDelete.id), isFalse); + + // Fetched poll votes should be empty + final fetchedPollVotes = await database.pollVoteDao.getPollVotes( + pollToDelete.id, + ); + expect(fetchedPollVotes, isEmpty); + }); + + tearDown(() async { + await database.disconnect(); + }); +} diff --git a/packages/stream_chat_persistence/test/src/dao/poll_vote_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/poll_vote_dao_test.dart new file mode 100644 index 000000000..093aac84b --- /dev/null +++ b/packages/stream_chat_persistence/test/src/dao/poll_vote_dao_test.dart @@ -0,0 +1,177 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/dao/poll_vote_dao.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; + +import '../../stream_chat_persistence_client_test.dart'; + +void main() { + late PollVoteDao pollVoteDao; + late DriftChatDatabase database; + + setUp(() { + database = testDatabaseProvider('testUserId'); + pollVoteDao = database.pollVoteDao; + }); + + Future> _preparePollVoteData( + String pollId, { + String? userId, + int count = 3, + }) async { + const options = [ + PollOption(id: 'option-1', text: 'Red'), + PollOption(id: 'option-2', text: 'Blue'), + PollOption(id: 'option-3', text: 'Green'), + ]; + + final latestVotesByOption = { + for (final option in options) + option.id!: [ + for (var i = 0; i < count; i++) + PollVote( + id: '${option.id}-pollVote-$i', + pollId: pollId, + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: option.id, + createdAt: DateTime.now(), + ), + ], + }; + + final voteCountsByOption = latestVotesByOption.map( + (key, value) => MapEntry(key, value.length), + ); + + final users = latestVotesByOption.values + .expand((it) => it.map((it) => it.user!)) + .toList(); + + final poll = Poll( + id: pollId, + name: 'testQuestion', + createdById: userId ?? users.first.id, + votingVisibility: VotingVisibility.anonymous, + allowUserSuggestedOptions: true, + options: options, + voteCount: voteCountsByOption.values.reduce((a, b) => a + b), + voteCountsByOption: voteCountsByOption, + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + enforceUniqueVote: false, + allowAnswers: true, + extraData: const {'test_extra_data': 'extraData'}, + ); + + final votes = latestVotesByOption.values.expand((it) => it).toList(); + + await database.userDao.updateUsers(users); + await database.pollDao.updatePolls([poll]); + await pollVoteDao.updatePollVotes(votes); + + return votes; + } + + test('getPollVotes', () async { + const pollId = 'testPollId'; + + // Should be empty initially + final pollVotes = await pollVoteDao.getPollVotes(pollId); + expect(pollVotes, isEmpty); + + // Adding sample poll votes + final insertedPollVotes = await _preparePollVoteData(pollId); + expect(insertedPollVotes, isNotEmpty); + + // Fetched pollVote length should match inserted pollVote length. + // Every pollVote pollId should match the provided pollId. + final fetchedPollVotes = await pollVoteDao.getPollVotes(pollId); + expect(fetchedPollVotes.length, insertedPollVotes.length); + expect(fetchedPollVotes.every((it) => it.pollId == pollId), true); + }); + + test('updatePollVotes', () async { + const pollId = 'testPollId'; + + // Preparing test data + final pollVotes = await _preparePollVoteData(pollId); + + // Adding a new pollVote + final newPollVote = PollVote( + id: 'pollVote-4', + pollId: pollId, + userId: 'user-3', + user: User(id: 'user-3', name: 'User 3'), + optionId: 'option-4', + createdAt: DateTime.now(), + ); + + await pollVoteDao.updatePollVotes([newPollVote]); + + // Fetched pollVote length should be one more than inserted pollVotes. + // Fetched pollVote should contain the newPollVote. + final fetchedPollVotes = await pollVoteDao.getPollVotes(pollId); + expect(fetchedPollVotes.length, pollVotes.length + 1); + expect( + fetchedPollVotes.any((it) => + it.id == newPollVote.id && + it.pollId == newPollVote.pollId && + it.optionId == newPollVote.optionId && + it.answerText == newPollVote.answerText), + true, + ); + }); + + group('deletePollVotesByPollIds', () { + const pollId1 = 'testPollId1'; + const pollId2 = 'testPollId2'; + test('should delete all the pollVotes of first poll', () async { + // Preparing test data + final insertedPollVotes1 = await _preparePollVoteData(pollId1); + final insertedPollVotes2 = await _preparePollVoteData(pollId2); + + // Fetched pollVote list length should match + // the inserted pollVote list length + final pollVotes1 = await pollVoteDao.getPollVotes(pollId1); + final pollVotes2 = await pollVoteDao.getPollVotes(pollId2); + expect(pollVotes1.length, insertedPollVotes1.length); + expect(pollVotes2.length, insertedPollVotes2.length); + + // Deleting all the pollVotes of messageId1 + await pollVoteDao.deletePollVotesByPollIds([pollId1]); + + // Fetched pollVotes length of only pollId1 should be empty + final fetchedPollVotes1 = await pollVoteDao.getPollVotes(pollId1); + final fetchedPollVotes2 = await pollVoteDao.getPollVotes(pollId2); + expect(fetchedPollVotes1, isEmpty); + expect(fetchedPollVotes2, isNotEmpty); + }); + + test('should delete all the pollVotes of both polls', () async { + // Preparing test data + final insertedPollVotes1 = await _preparePollVoteData(pollId1); + final insertedPollVotes2 = await _preparePollVoteData(pollId2); + + // Fetched pollVote list length should match + // the inserted pollVote list length + final pollVotes1 = await pollVoteDao.getPollVotes(pollId1); + final pollVotes2 = await pollVoteDao.getPollVotes(pollId2); + expect(pollVotes1.length, insertedPollVotes1.length); + expect(pollVotes2.length, insertedPollVotes2.length); + + // Deleting all the pollVotes of messageId1 + await pollVoteDao.deletePollVotesByPollIds([pollId1, pollId2]); + + // Fetched pollVotes length of only pollId1 should be empty + final fetchedPollVotes1 = await pollVoteDao.getPollVotes(pollId1); + final fetchedPollVotes2 = await pollVoteDao.getPollVotes(pollId2); + expect(fetchedPollVotes1, isEmpty); + expect(fetchedPollVotes2, isEmpty); + }); + }); + + tearDown(() async { + await database.disconnect(); + }); +} diff --git a/packages/stream_chat_persistence/test/src/dao/reaction_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/reaction_dao_test.dart index 932a555e5..7fa3569e4 100644 --- a/packages/stream_chat_persistence/test/src/dao/reaction_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/reaction_dao_test.dart @@ -164,7 +164,7 @@ void main() { expect(fetchedReactions1, isEmpty); expect(fetchedReactions2, isNotEmpty); }); - test('should delete all the messages of both message', () async { + test('should delete all the reactions of both message', () async { // Preparing test data final insertedReactions1 = await _prepareReactionData(messageId1); final insertedReactions2 = await _prepareReactionData(messageId2); diff --git a/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart index b81fbe038..76dc763fc 100644 --- a/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/message_mapper_test.dart @@ -30,6 +30,16 @@ void main() { assetUrl: 'testAssetUrl', ), ); + final poll = Poll( + id: 'testPollId', + name: 'testQuestion', + options: const [ + PollOption( + id: 'testOptionId', + text: 'testOptionText', + ), + ], + ); final entity = MessageEntity( id: 'testMessageId', attachments: attachments.map((it) => jsonEncode(it.toData())).toList(), @@ -37,6 +47,7 @@ void main() { type: 'testType', parentId: 'testParentId', quotedMessageId: quotedMessage.id, + pollId: poll.id, command: 'testCommand', localCreatedAt: DateTime.now(), remoteCreatedAt: DateTime.now().add(const Duration(seconds: 1)), @@ -77,6 +88,7 @@ void main() { latestReactions: reactions, ownReactions: reactions, quotedMessage: quotedMessage, + poll: poll, ); expect(message, isA()); @@ -84,6 +96,7 @@ void main() { expect(message.type, entity.type); expect(message.parentId, entity.parentId); expect(message.quotedMessageId, entity.quotedMessageId); + expect(message.pollId, entity.pollId); expect(message.command, entity.command); expect(message.localCreatedAt, isSameDateAs(entity.localCreatedAt)); expect(message.remoteCreatedAt, isSameDateAs(entity.remoteCreatedAt)); @@ -148,12 +161,23 @@ void main() { assetUrl: 'testAssetUrl', ), ); + final poll = Poll( + id: 'testPollId', + name: 'testQuestion', + options: const [ + PollOption( + id: 'testOptionId', + text: 'testOptionText', + ), + ], + ); final message = Message( id: 'testMessageId', attachments: attachments, type: 'testType', parentId: 'testParentId', quotedMessageId: quotedMessage.id, + pollId: poll.id, command: 'testCommand', localCreatedAt: DateTime.now(), createdAt: DateTime.now().add(const Duration(seconds: 1)), @@ -193,6 +217,7 @@ void main() { expect(entity.type, message.type); expect(entity.parentId, message.parentId); expect(entity.quotedMessageId, message.quotedMessageId); + expect(entity.pollId, message.pollId); expect(entity.command, message.command); expect(entity.localCreatedAt, isSameDateAs(message.localCreatedAt)); expect(entity.remoteCreatedAt, isSameDateAs(message.remoteCreatedAt)); diff --git a/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart index d5d3debef..9d54faea5 100644 --- a/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/pinned_message_mapper_test.dart @@ -30,6 +30,16 @@ void main() { assetUrl: 'testAssetUrl', ), ); + final poll = Poll( + id: 'testPollId', + name: 'testQuestion', + options: const [ + PollOption( + id: 'testOptionId', + text: 'testOptionText', + ), + ], + ); final entity = PinnedMessageEntity( id: 'testMessageId', attachments: attachments.map((it) => jsonEncode(it.toData())).toList(), @@ -37,6 +47,7 @@ void main() { type: 'testType', parentId: 'testParentId', quotedMessageId: quotedMessage.id, + pollId: poll.id, command: 'testCommand', localCreatedAt: DateTime.now(), remoteCreatedAt: DateTime.now().add(const Duration(seconds: 1)), @@ -77,6 +88,7 @@ void main() { latestReactions: reactions, ownReactions: reactions, quotedMessage: quotedMessage, + poll: poll, ); expect(message, isA()); @@ -84,6 +96,7 @@ void main() { expect(message.type, entity.type); expect(message.parentId, entity.parentId); expect(message.quotedMessageId, entity.quotedMessageId); + expect(message.pollId, entity.pollId); expect(message.command, entity.command); expect(message.localCreatedAt, isSameDateAs(entity.localCreatedAt)); expect(message.remoteCreatedAt, isSameDateAs(entity.remoteCreatedAt)); @@ -148,12 +161,23 @@ void main() { assetUrl: 'testAssetUrl', ), ); + final poll = Poll( + id: 'testPollId', + name: 'testQuestion', + options: const [ + PollOption( + id: 'testOptionId', + text: 'testOptionText', + ), + ], + ); final message = Message( id: 'testMessageId', attachments: attachments, type: 'testType', parentId: 'testParentId', quotedMessageId: quotedMessage.id, + pollId: poll.id, command: 'testCommand', localCreatedAt: DateTime.now(), createdAt: DateTime.now().add(const Duration(seconds: 1)), @@ -193,6 +217,7 @@ void main() { expect(entity.type, message.type); expect(entity.parentId, message.parentId); expect(entity.quotedMessageId, message.quotedMessageId); + expect(entity.pollId, message.pollId); expect(entity.command, message.command); expect(entity.localCreatedAt, isSameDateAs(message.localCreatedAt)); expect(entity.remoteCreatedAt, isSameDateAs(message.remoteCreatedAt)); diff --git a/packages/stream_chat_persistence/test/src/mapper/poll_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/poll_mapper_test.dart new file mode 100644 index 000000000..a4f4ef64d --- /dev/null +++ b/packages/stream_chat_persistence/test/src/mapper/poll_mapper_test.dart @@ -0,0 +1,193 @@ +import 'dart:convert'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; +import 'package:stream_chat_persistence/src/mapper/poll_mapper.dart'; + +import '../utils/date_matcher.dart'; + +void main() { + test('toPoll should map entity into Poll', () { + final currentUser = User(id: 'curr-user', name: 'Current User'); + final latestVotesByOption = { + 'option-1': [ + for (var i = 0; i < 5; i++) + PollVote( + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: 'option-1', + createdAt: DateTime.now(), + ), + ], + 'option-2': [ + for (var i = 0; i < 2; i++) + PollVote( + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: 'option-2', + createdAt: DateTime.now(), + ), + ], + 'option-3': [ + PollVote( + user: currentUser, + userId: currentUser.id, + optionId: 'option-3', + createdAt: DateTime.now(), + ), + ], + }; + final voteCountsByOption = latestVotesByOption.map( + (key, value) => MapEntry(key, value.length), + ); + final latestAnswers = [ + PollVote( + user: currentUser, + userId: currentUser.id, + answerText: 'I also like yellow', + createdAt: DateTime.now(), + ), + ]; + final entity = PollEntity( + id: 'poll-1', + name: 'testQuestion', + createdById: currentUser.id, + votingVisibility: VotingVisibility.public, + allowUserSuggestedOptions: true, + options: const [ + PollOption(id: 'option-1', text: 'Red'), + PollOption(id: 'option-2', text: 'Blue'), + PollOption(id: 'option-3', text: 'Green'), + ].map(jsonEncode).toList(), + voteCount: voteCountsByOption.values.reduce((a, b) => a + b), + voteCountsByOption: voteCountsByOption, + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + enforceUniqueVote: false, + isClosed: false, + allowAnswers: true, + answersCount: latestAnswers.length, + extraData: {'test_extra_data': 'extraData'}, + ); + final poll = entity.toPoll( + createdBy: currentUser, + latestAnswers: latestAnswers, + latestVotesByOption: latestVotesByOption, + ownVotesAndAnswers: [ + ...latestAnswers, + ...latestVotesByOption.values.expand((it) => it), + ].where((it) => it.userId == currentUser.id).toList(), + ); + + expect(poll, isA()); + expect(poll.id, entity.id); + expect(poll.name, entity.name); + expect(poll.createdById, entity.createdById); + expect(poll.votingVisibility, entity.votingVisibility); + expect(poll.enforceUniqueVote, entity.enforceUniqueVote); + expect(poll.maxVotesAllowed, entity.maxVotesAllowed); + expect(poll.allowUserSuggestedOptions, entity.allowUserSuggestedOptions); + for (var i = 0; i < poll.options.length; i++) { + final pollOption = poll.options[i]; + final entityOptionJson = jsonDecode(entity.options[i]); + final entityOption = PollOption.fromJson(entityOptionJson); + expect(pollOption.id, entityOption.id); + expect(pollOption.text, entityOption.text); + expect(pollOption.extraData, entityOption.extraData); + } + expect(poll.allowAnswers, entity.allowAnswers); + expect(poll.answersCount, entity.answersCount); + expect(poll.isClosed, entity.isClosed); + expect(poll.createdAt, isSameDateAs(entity.createdAt)); + expect(poll.updatedAt, isSameDateAs(entity.updatedAt)); + expect(poll.voteCountsByOption, entity.voteCountsByOption); + expect(poll.voteCount, entity.voteCount); + expect(poll.createdById, entity.createdById); + expect(poll.extraData, entity.extraData); + }); + + test('toEntity should map poll into PollEntity', () { + final currentUser = User(id: 'curr-user', name: 'Current User'); + final latestVotesByOption = { + 'option-1': [ + for (var i = 0; i < 5; i++) + PollVote( + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: 'option-1', + createdAt: DateTime.now(), + ), + ], + 'option-2': [ + for (var i = 0; i < 2; i++) + PollVote( + userId: 'user-$i', + user: User(id: 'user-$i', name: 'User $i'), + optionId: 'option-2', + createdAt: DateTime.now(), + ), + ], + 'option-3': [ + PollVote( + user: currentUser, + userId: currentUser.id, + optionId: 'option-3', + createdAt: DateTime.now(), + ), + ], + }; + final voteCountsByOption = latestVotesByOption.map( + (key, value) => MapEntry(key, value.length), + ); + final latestAnswers = [ + PollVote( + user: currentUser, + userId: currentUser.id, + answerText: 'I also like yellow', + createdAt: DateTime.now(), + ), + ]; + final poll = Poll( + id: 'poll-1', + name: 'testQuestion', + createdById: currentUser.id, + allowUserSuggestedOptions: true, + options: const [ + PollOption(id: 'option-1', text: 'Red'), + PollOption(id: 'option-2', text: 'Blue'), + PollOption(id: 'option-3', text: 'Green'), + ], + voteCount: voteCountsByOption.values.reduce((a, b) => a + b), + voteCountsByOption: voteCountsByOption, + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + enforceUniqueVote: false, + allowAnswers: true, + answersCount: latestAnswers.length, + extraData: const {'test_extra_data': 'extraData'}, + ); + final entity = poll.toEntity(); + expect(entity, isA()); + expect(entity.id, poll.id); + expect(entity.name, poll.name); + expect(entity.createdById, poll.createdById); + expect(entity.votingVisibility, poll.votingVisibility); + expect(entity.enforceUniqueVote, poll.enforceUniqueVote); + expect(entity.maxVotesAllowed, poll.maxVotesAllowed); + expect(entity.allowUserSuggestedOptions, poll.allowUserSuggestedOptions); + expect( + entity.options, + poll.options.map((it) => jsonEncode(it.toJson())).toList(), + ); + expect(entity.allowAnswers, poll.allowAnswers); + expect(entity.answersCount, poll.answersCount); + expect(entity.isClosed, poll.isClosed); + expect(entity.createdAt, isSameDateAs(poll.createdAt)); + expect(entity.updatedAt, isSameDateAs(poll.updatedAt)); + expect(entity.voteCountsByOption, poll.voteCountsByOption); + expect(entity.voteCount, poll.voteCount); + expect(entity.createdById, poll.createdById); + expect(entity.extraData, poll.extraData); + }); +} diff --git a/packages/stream_chat_persistence/test/src/mapper/poll_vote_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/poll_vote_mapper_test.dart new file mode 100644 index 000000000..d6af413e3 --- /dev/null +++ b/packages/stream_chat_persistence/test/src/mapper/poll_vote_mapper_test.dart @@ -0,0 +1,52 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:stream_chat/stream_chat.dart'; +import 'package:stream_chat_persistence/src/db/drift_chat_database.dart'; +import 'package:stream_chat_persistence/src/mapper/poll_vote_mapper.dart'; + +import '../utils/date_matcher.dart'; + +void main() { + test('toPollVote should map entity into PollVote', () { + final currentUser = User(id: 'curr-user', name: 'Current User'); + final entity = PollVoteEntity( + id: 'poll-vote-1', + pollId: 'poll-1', + optionId: 'option-1', + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + userId: currentUser.id, + ); + final pollVote = entity.toPollVote(user: currentUser); + + expect(pollVote, isA()); + expect(pollVote.id, entity.id); + expect(pollVote.pollId, entity.pollId); + expect(pollVote.optionId, entity.optionId); + expect(pollVote.answerText, entity.answerText); + expect(pollVote.createdAt, isSameDateAs(entity.createdAt)); + expect(pollVote.updatedAt, isSameDateAs(entity.updatedAt)); + expect(pollVote.userId, entity.userId); + }); + + test('toEntity should map pollVote into PollVote', () { + final currentUser = User(id: 'curr-user', name: 'Current User'); + final pollVote = PollVote( + id: 'poll-vote-1', + pollId: 'poll-1', + optionId: 'option-1', + createdAt: DateTime.now(), + updatedAt: DateTime.now(), + userId: currentUser.id, + user: currentUser, + ); + final entity = pollVote.toEntity(); + expect(entity, isA()); + expect(entity.id, pollVote.id); + expect(entity.pollId, pollVote.pollId); + expect(entity.optionId, pollVote.optionId); + expect(entity.answerText, pollVote.answerText); + expect(entity.createdAt, isSameDateAs(pollVote.createdAt)); + expect(entity.updatedAt, isSameDateAs(pollVote.updatedAt)); + expect(entity.userId, pollVote.userId); + }); +} diff --git a/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart b/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart index 3c0d859bf..efb5608c7 100644 --- a/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart +++ b/packages/stream_chat_persistence/test/stream_chat_persistence_client_test.dart @@ -489,6 +489,48 @@ void main() { verify(() => mockDatabase.channelDao.updateChannels(channels)).called(1); }); + test('updatePolls', () async { + const name = 'testPollName'; + final options = List.generate(3, (index) => PollOption(text: '$index')); + final polls = + List.generate(3, (index) => Poll(name: name, options: options)); + when(() => mockDatabase.pollDao.updatePolls(polls)) + .thenAnswer((_) => Future.value()); + + await client.updatePolls(polls); + verify(() => mockDatabase.pollDao.updatePolls(polls)).called(1); + }); + + test('deletePollsByIds', () async { + final pollIds = ['testPollId']; + when(() => mockDatabase.pollDao.deletePollsByIds(pollIds)) + .thenAnswer((_) => Future.value()); + + await client.deletePollsByIds(pollIds); + verify(() => mockDatabase.pollDao.deletePollsByIds(pollIds)).called(1); + }); + + test('updatePollVotes', () async { + final pollVotes = List.generate( + 3, (index) => PollVote(id: '$index', optionId: 'testOptionId$index')); + when(() => mockDatabase.pollVoteDao.updatePollVotes(pollVotes)) + .thenAnswer((_) => Future.value()); + + await client.updatePollVotes(pollVotes); + verify(() => mockDatabase.pollVoteDao.updatePollVotes(pollVotes)) + .called(1); + }); + + test('deletePollVotesByPollIds', () async { + final pollIds = ['testPollId']; + when(() => mockDatabase.pollVoteDao.deletePollVotesByPollIds(pollIds)) + .thenAnswer((_) => Future.value()); + + await client.deletePollVotesByPollIds(pollIds); + verify(() => mockDatabase.pollVoteDao.deletePollVotesByPollIds(pollIds)) + .called(1); + }); + test('updateMembers', () async { const cid = 'testCid'; final members = List.generate(3, (index) => Member());