modify entities according to NNBD models

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-04-20 15:37:12 +05:30
parent 271dad7f0c
commit e3589a3030
8 changed files with 1323 additions and 1459 deletions
File diff suppressed because it is too large Load Diff
@@ -24,16 +24,16 @@ class Channels extends Table {
DateTimeColumn get lastMessageAt => dateTime().nullable()(); DateTimeColumn get lastMessageAt => dateTime().nullable()();
/// The date of channel creation /// The date of channel creation
DateTimeColumn get createdAt => dateTime().nullable()(); DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
/// The date of the last channel update /// The date of the last channel update
DateTimeColumn get updatedAt => dateTime().nullable()(); DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
/// The date of channel deletion /// The date of channel deletion
DateTimeColumn get deletedAt => dateTime().nullable()(); DateTimeColumn get deletedAt => dateTime().nullable()();
/// The count of this channel members /// The count of this channel members
IntColumn get memberCount => integer().nullable()(); IntColumn get memberCount => integer().withDefault(const Constant(0))();
/// The id of the user that created this channel /// The id of the user that created this channel
TextColumn get createdById => text().nullable()(); TextColumn get createdById => text().nullable()();
@@ -21,22 +21,22 @@ class Members extends Table {
DateTimeColumn get inviteRejectedAt => dateTime().nullable()(); DateTimeColumn get inviteRejectedAt => dateTime().nullable()();
/// True if the user has been invited to the channel /// True if the user has been invited to the channel
BoolColumn get invited => boolean().nullable()(); BoolColumn get invited => boolean().withDefault(const Constant(false))();
/// True if the member is banned from the channel /// True if the member is banned from the channel
BoolColumn get banned => boolean().nullable()(); BoolColumn get banned => boolean().withDefault(const Constant(false))();
/// True if the member is shadow banned from the channel /// True if the member is shadow banned from the channel
BoolColumn get shadowBanned => boolean().nullable()(); BoolColumn get shadowBanned => boolean().withDefault(const Constant(false))();
/// True if the user is a moderator of the channel /// True if the user is a moderator of the channel
BoolColumn get isModerator => boolean().nullable()(); BoolColumn get isModerator => boolean().withDefault(const Constant(false))();
/// The date of creation /// The date of creation
DateTimeColumn get createdAt => dateTime()(); DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
/// The last date of update /// The last date of update
DateTimeColumn get updatedAt => dateTime().nullable()(); DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
@override @override
Set<Column> get primaryKey => { Set<Column> get primaryKey => {
@@ -15,19 +15,18 @@ class Messages extends Table {
/// The list of attachments, either provided by the user /// The list of attachments, either provided by the user
/// or generated from a command or as a result of URL scraping. /// or generated from a command or as a result of URL scraping.
TextColumn get attachments => TextColumn get attachments => text().map(ListConverter<String>())();
text().nullable().map(ListConverter<String>())();
/// The status of a sending message /// The status of a sending message
IntColumn get status => IntColumn get status => integer()
integer().nullable().map(MessageSendingStatusConverter())(); .withDefault(const Constant(1))
.map(MessageSendingStatusConverter())();
/// The message type /// The message type
TextColumn get type => text().nullable()(); TextColumn get type => text().withDefault(const Constant('regular'))();
/// The list of user mentioned in the message /// The list of user mentioned in the message
TextColumn get mentionedUsers => TextColumn get mentionedUsers => text().map(ListConverter<String>())();
text().nullable().map(ListConverter<String>())();
/// A map describing the count of number of every reaction /// A map describing the count of number of every reaction
TextColumn get reactionCounts => text().nullable().map(MapConverter<int>())(); TextColumn get reactionCounts => text().nullable().map(MapConverter<int>())();
@@ -48,16 +47,16 @@ class Messages extends Table {
BoolColumn get showInChannel => boolean().nullable()(); BoolColumn get showInChannel => boolean().nullable()();
/// If true the message is shadowed /// If true the message is shadowed
BoolColumn get shadowed => boolean().nullable()(); BoolColumn get shadowed => boolean().withDefault(const Constant(false))();
/// A used command name. /// A used command name.
TextColumn get command => text().nullable()(); TextColumn get command => text().nullable()();
/// The DateTime when the message was created. /// The DateTime when the message was created.
DateTimeColumn get createdAt => dateTime()(); DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
/// The DateTime when the message was updated last time. /// The DateTime when the message was updated last time.
DateTimeColumn get updatedAt => dateTime().nullable()(); DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
/// The DateTime when the message was deleted. /// The DateTime when the message was deleted.
DateTimeColumn get deletedAt => dateTime().nullable()(); DateTimeColumn get deletedAt => dateTime().nullable()();
@@ -16,10 +16,10 @@ class Reactions extends Table {
TextColumn get type => text()(); TextColumn get type => text()();
/// The DateTime on which the reaction is created /// The DateTime on which the reaction is created
DateTimeColumn get createdAt => dateTime()(); DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
/// The score of the reaction (ie. number of reactions sent) /// The score of the reaction (ie. number of reactions sent)
IntColumn get score => integer().nullable()(); IntColumn get score => integer().withDefault(const Constant(0))();
/// Reaction custom extraData /// Reaction custom extraData
TextColumn get extraData => text().nullable().map(MapConverter<Object>())(); TextColumn get extraData => text().nullable().map(MapConverter<Object>())();
@@ -15,7 +15,7 @@ class Reads extends Table {
text().customConstraint('REFERENCES channels(cid) ON DELETE CASCADE')(); text().customConstraint('REFERENCES channels(cid) ON DELETE CASCADE')();
/// Number of unread messages /// Number of unread messages
IntColumn get unreadMessages => integer().nullable()(); IntColumn get unreadMessages => integer().withDefault(const Constant(0))();
@override @override
Set<Column> get primaryKey => { Set<Column> get primaryKey => {
@@ -12,19 +12,19 @@ class Users extends Table {
TextColumn get role => text().nullable()(); TextColumn get role => text().nullable()();
/// Date of user creation /// Date of user creation
DateTimeColumn get createdAt => dateTime().nullable()(); DateTimeColumn get createdAt => dateTime().withDefault(currentDateAndTime)();
/// Date of last user update /// Date of last user update
DateTimeColumn get updatedAt => dateTime().nullable()(); DateTimeColumn get updatedAt => dateTime().withDefault(currentDateAndTime)();
/// Date of last user connection /// Date of last user connection
DateTimeColumn get lastActive => dateTime().nullable()(); DateTimeColumn get lastActive => dateTime().nullable()();
/// True if user is online /// True if user is online
BoolColumn get online => boolean().nullable()(); BoolColumn get online => boolean().withDefault(const Constant(false))();
/// True if user is banned from the chat /// True if user is banned from the chat
BoolColumn get banned => boolean().nullable()(); BoolColumn get banned => boolean().withDefault(const Constant(false))();
/// Map of custom user extraData /// Map of custom user extraData
TextColumn get extraData => text().nullable().map(MapConverter<Object>())(); TextColumn get extraData => text().nullable().map(MapConverter<Object>())();
@@ -30,17 +30,15 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
/// Connection mode on which the client will work /// Connection mode on which the client will work
ConnectionMode connectionMode = ConnectionMode.regular, ConnectionMode connectionMode = ConnectionMode.regular,
Level logLevel = Level.WARNING, Level logLevel = Level.WARNING,
LogHandlerFunction logHandlerFunction, LogHandlerFunction? logHandlerFunction,
}) : assert(connectionMode != null, 'ConnectionMode cannot be null'), }) : _connectionMode = connectionMode,
assert(logLevel != null, 'LogLevel cannot be null'),
_connectionMode = connectionMode,
_logger = Logger.detached('💽')..level = logLevel { _logger = Logger.detached('💽')..level = logLevel {
_logger.onRecord.listen(logHandlerFunction ?? _defaultLogHandler); _logger.onRecord.listen(logHandlerFunction ?? _defaultLogHandler);
} }
/// [MoorChatDatabase] instance used by this client. /// [MoorChatDatabase] instance used by this client.
@visibleForTesting @visibleForTesting
MoorChatDatabase db; MoorChatDatabase? db;
final Logger _logger; final Logger _logger;
final ConnectionMode _connectionMode; final ConnectionMode _connectionMode;
@@ -75,7 +73,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
@override @override
Future<void> connect( Future<void> connect(
String userId, { String userId, {
DatabaseProvider databaseProvider, // Used only for testing DatabaseProvider? databaseProvider, // Used only for testing
}) async { }) async {
if (db != null) { if (db != null) {
throw Exception( throw Exception(
@@ -330,13 +328,13 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
_logger.info('Disconnecting'); _logger.info('Disconnecting');
if (flush) { if (flush) {
_logger.info('Flushing'); _logger.info('Flushing');
await db.batch((batch) { await db!.batch((batch) {
db.allTables.forEach((table) { db!.allTables.forEach((table) {
db.delete(table).go(); db!.delete(table).go();
}); });
}); });
} }
await db.disconnect(); await db!.disconnect();
db = null; db = null;
} }
}); });