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 1de78245..f87aecc4 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 @@ -56,7 +56,7 @@ class DriftChatDatabase extends _$DriftChatDatabase { // you should bump this number whenever you change or add a table definition. @override - int get schemaVersion => 8; + int get schemaVersion => 9; @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 9c44cb2f..af0dc874 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 @@ -6,7 +6,7 @@ part of 'drift_chat_database.dart'; // MoorGenerator // ************************************************************************** -// ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this +// ignore_for_file: type=lint class ChannelEntity extends DataClass implements Insertable { /// The id of this channel final String id; @@ -17,6 +17,9 @@ class ChannelEntity extends DataClass implements Insertable { /// The cid of this channel final String cid; + /// List of user permissions on this channel + final List? ownCapabilities; + /// The channel configuration data final Map config; @@ -47,6 +50,7 @@ class ChannelEntity extends DataClass implements Insertable { {required this.id, required this.type, required this.cid, + this.ownCapabilities, required this.config, required this.frozen, this.lastMessageAt, @@ -65,7 +69,9 @@ class ChannelEntity extends DataClass implements Insertable { .mapFromDatabaseResponse(data['${effectivePrefix}type'])!, cid: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}cid'])!, - config: $ChannelsTable.$converter0.mapToDart(const StringType() + ownCapabilities: $ChannelsTable.$converter0.mapToDart(const StringType() + .mapFromDatabaseResponse(data['${effectivePrefix}own_capabilities'])), + config: $ChannelsTable.$converter1.mapToDart(const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}config']))!, frozen: const BoolType() .mapFromDatabaseResponse(data['${effectivePrefix}frozen'])!, @@ -81,7 +87,7 @@ class ChannelEntity extends DataClass implements Insertable { .mapFromDatabaseResponse(data['${effectivePrefix}member_count'])!, createdById: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}created_by_id']), - extraData: $ChannelsTable.$converter1.mapToDart(const StringType() + extraData: $ChannelsTable.$converter2.mapToDart(const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}extra_data'])), ); } @@ -91,8 +97,13 @@ class ChannelEntity extends DataClass implements Insertable { map['id'] = Variable(id); map['type'] = Variable(type); map['cid'] = Variable(cid); - { + if (!nullToAbsent || ownCapabilities != null) { final converter = $ChannelsTable.$converter0; + map['own_capabilities'] = + Variable(converter.mapToSql(ownCapabilities)); + } + { + final converter = $ChannelsTable.$converter1; map['config'] = Variable(converter.mapToSql(config)!); } map['frozen'] = Variable(frozen); @@ -109,7 +120,7 @@ class ChannelEntity extends DataClass implements Insertable { map['created_by_id'] = Variable(createdById); } if (!nullToAbsent || extraData != null) { - final converter = $ChannelsTable.$converter1; + final converter = $ChannelsTable.$converter2; map['extra_data'] = Variable(converter.mapToSql(extraData)); } return map; @@ -122,6 +133,8 @@ class ChannelEntity extends DataClass implements Insertable { id: serializer.fromJson(json['id']), type: serializer.fromJson(json['type']), cid: serializer.fromJson(json['cid']), + ownCapabilities: + serializer.fromJson?>(json['ownCapabilities']), config: serializer.fromJson>(json['config']), frozen: serializer.fromJson(json['frozen']), lastMessageAt: serializer.fromJson(json['lastMessageAt']), @@ -140,6 +153,7 @@ class ChannelEntity extends DataClass implements Insertable { 'id': serializer.toJson(id), 'type': serializer.toJson(type), 'cid': serializer.toJson(cid), + 'ownCapabilities': serializer.toJson?>(ownCapabilities), 'config': serializer.toJson>(config), 'frozen': serializer.toJson(frozen), 'lastMessageAt': serializer.toJson(lastMessageAt), @@ -156,6 +170,7 @@ class ChannelEntity extends DataClass implements Insertable { {String? id, String? type, String? cid, + Value?> ownCapabilities = const Value.absent(), Map? config, bool? frozen, Value lastMessageAt = const Value.absent(), @@ -169,6 +184,9 @@ class ChannelEntity extends DataClass implements Insertable { id: id ?? this.id, type: type ?? this.type, cid: cid ?? this.cid, + ownCapabilities: ownCapabilities.present + ? ownCapabilities.value + : this.ownCapabilities, config: config ?? this.config, frozen: frozen ?? this.frozen, lastMessageAt: @@ -186,6 +204,7 @@ class ChannelEntity extends DataClass implements Insertable { ..write('id: $id, ') ..write('type: $type, ') ..write('cid: $cid, ') + ..write('ownCapabilities: $ownCapabilities, ') ..write('config: $config, ') ..write('frozen: $frozen, ') ..write('lastMessageAt: $lastMessageAt, ') @@ -200,8 +219,20 @@ class ChannelEntity extends DataClass implements Insertable { } @override - int get hashCode => Object.hash(id, type, cid, config, frozen, lastMessageAt, - createdAt, updatedAt, deletedAt, memberCount, createdById, extraData); + int get hashCode => Object.hash( + id, + type, + cid, + ownCapabilities, + config, + frozen, + lastMessageAt, + createdAt, + updatedAt, + deletedAt, + memberCount, + createdById, + extraData); @override bool operator ==(Object other) => identical(this, other) || @@ -209,6 +240,7 @@ class ChannelEntity extends DataClass implements Insertable { other.id == this.id && other.type == this.type && other.cid == this.cid && + other.ownCapabilities == this.ownCapabilities && other.config == this.config && other.frozen == this.frozen && other.lastMessageAt == this.lastMessageAt && @@ -224,6 +256,7 @@ class ChannelsCompanion extends UpdateCompanion { final Value id; final Value type; final Value cid; + final Value?> ownCapabilities; final Value> config; final Value frozen; final Value lastMessageAt; @@ -237,6 +270,7 @@ class ChannelsCompanion extends UpdateCompanion { this.id = const Value.absent(), this.type = const Value.absent(), this.cid = const Value.absent(), + this.ownCapabilities = const Value.absent(), this.config = const Value.absent(), this.frozen = const Value.absent(), this.lastMessageAt = const Value.absent(), @@ -251,6 +285,7 @@ class ChannelsCompanion extends UpdateCompanion { required String id, required String type, required String cid, + this.ownCapabilities = const Value.absent(), required Map config, this.frozen = const Value.absent(), this.lastMessageAt = const Value.absent(), @@ -268,6 +303,7 @@ class ChannelsCompanion extends UpdateCompanion { Expression? id, Expression? type, Expression? cid, + Expression?>? ownCapabilities, Expression>? config, Expression? frozen, Expression? lastMessageAt, @@ -282,6 +318,7 @@ class ChannelsCompanion extends UpdateCompanion { if (id != null) 'id': id, if (type != null) 'type': type, if (cid != null) 'cid': cid, + if (ownCapabilities != null) 'own_capabilities': ownCapabilities, if (config != null) 'config': config, if (frozen != null) 'frozen': frozen, if (lastMessageAt != null) 'last_message_at': lastMessageAt, @@ -298,6 +335,7 @@ class ChannelsCompanion extends UpdateCompanion { {Value? id, Value? type, Value? cid, + Value?>? ownCapabilities, Value>? config, Value? frozen, Value? lastMessageAt, @@ -311,6 +349,7 @@ class ChannelsCompanion extends UpdateCompanion { id: id ?? this.id, type: type ?? this.type, cid: cid ?? this.cid, + ownCapabilities: ownCapabilities ?? this.ownCapabilities, config: config ?? this.config, frozen: frozen ?? this.frozen, lastMessageAt: lastMessageAt ?? this.lastMessageAt, @@ -335,8 +374,13 @@ class ChannelsCompanion extends UpdateCompanion { if (cid.present) { map['cid'] = Variable(cid.value); } - if (config.present) { + if (ownCapabilities.present) { final converter = $ChannelsTable.$converter0; + map['own_capabilities'] = + Variable(converter.mapToSql(ownCapabilities.value)); + } + if (config.present) { + final converter = $ChannelsTable.$converter1; map['config'] = Variable(converter.mapToSql(config.value)!); } if (frozen.present) { @@ -361,7 +405,7 @@ class ChannelsCompanion extends UpdateCompanion { map['created_by_id'] = Variable(createdById.value); } if (extraData.present) { - final converter = $ChannelsTable.$converter1; + final converter = $ChannelsTable.$converter2; map['extra_data'] = Variable(converter.mapToSql(extraData.value)); } @@ -374,6 +418,7 @@ class ChannelsCompanion extends UpdateCompanion { ..write('id: $id, ') ..write('type: $type, ') ..write('cid: $cid, ') + ..write('ownCapabilities: $ownCapabilities, ') ..write('config: $config, ') ..write('frozen: $frozen, ') ..write('lastMessageAt: $lastMessageAt, ') @@ -409,12 +454,20 @@ class $ChannelsTable extends Channels late final GeneratedColumn cid = GeneratedColumn( 'cid', aliasedName, false, type: const StringType(), requiredDuringInsert: true); + final VerificationMeta _ownCapabilitiesMeta = + const VerificationMeta('ownCapabilities'); + @override + late final GeneratedColumnWithTypeConverter, String?> + ownCapabilities = GeneratedColumn( + 'own_capabilities', aliasedName, true, + type: const StringType(), requiredDuringInsert: false) + .withConverter>($ChannelsTable.$converter0); final VerificationMeta _configMeta = const VerificationMeta('config'); @override late final GeneratedColumnWithTypeConverter, String?> config = GeneratedColumn('config', aliasedName, false, type: const StringType(), requiredDuringInsert: true) - .withConverter>($ChannelsTable.$converter0); + .withConverter>($ChannelsTable.$converter1); final VerificationMeta _frozenMeta = const VerificationMeta('frozen'); @override late final GeneratedColumn frozen = GeneratedColumn( @@ -467,12 +520,13 @@ class $ChannelsTable extends Channels late final GeneratedColumnWithTypeConverter, String?> extraData = GeneratedColumn('extra_data', aliasedName, true, type: const StringType(), requiredDuringInsert: false) - .withConverter>($ChannelsTable.$converter1); + .withConverter>($ChannelsTable.$converter2); @override List get $columns => [ id, type, cid, + ownCapabilities, config, frozen, lastMessageAt, @@ -509,6 +563,7 @@ class $ChannelsTable extends Channels } else if (isInserting) { context.missing(_cidMeta); } + context.handle(_ownCapabilitiesMeta, const VerificationResult.success()); context.handle(_configMeta, const VerificationResult.success()); if (data.containsKey('frozen')) { context.handle(_frozenMeta, @@ -561,9 +616,11 @@ class $ChannelsTable extends Channels return $ChannelsTable(attachedDatabase, alias); } - static TypeConverter, String> $converter0 = + static TypeConverter, String> $converter0 = + ListConverter(); + static TypeConverter, String> $converter1 = MapConverter(); - static TypeConverter, String> $converter1 = + static TypeConverter, String> $converter2 = MapConverter(); } diff --git a/packages/stream_chat_persistence/lib/src/entity/channels.dart b/packages/stream_chat_persistence/lib/src/entity/channels.dart index a685db68..84b16fe6 100644 --- a/packages/stream_chat_persistence/lib/src/entity/channels.dart +++ b/packages/stream_chat_persistence/lib/src/entity/channels.dart @@ -1,6 +1,6 @@ // coverage:ignore-file import 'package:drift/drift.dart'; -import 'package:stream_chat_persistence/src/converter/map_converter.dart'; +import 'package:stream_chat_persistence/src/converter/converter.dart'; /// Represents a [Channels] table in [MoorChatDatabase]. @DataClassName('ChannelEntity') @@ -14,6 +14,10 @@ class Channels extends Table { /// The cid of this channel TextColumn get cid => text()(); + /// List of user permissions on this channel + TextColumn get ownCapabilities => + text().nullable().map(ListConverter())(); + /// The channel configuration data TextColumn get config => text().map(MapConverter())(); diff --git a/packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart index ef4111f6..18865d82 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/channel_mapper.dart @@ -8,6 +8,7 @@ extension ChannelEntityX on ChannelEntity { final config = ChannelConfig.fromJson(this.config); return ChannelModel( id: id, + ownCapabilities: ownCapabilities, config: config, type: type, frozen: frozen, @@ -46,6 +47,7 @@ extension ChannelModelX on ChannelModel { id: id, type: type, cid: cid, + ownCapabilities: ownCapabilities, config: config.toJson(), frozen: frozen, lastMessageAt: lastMessageAt, diff --git a/packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart index d89687d3..b8bcc2ed 100644 --- a/packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/channel_mapper_test.dart @@ -14,6 +14,7 @@ void main() { id: 'testId', type: 'testType', cid: 'testCid', + ownCapabilities: ['testCapability'], config: {'max_message_length': 33}, frozen: math.Random().nextBool(), lastMessageAt: DateTime.now(), @@ -29,6 +30,7 @@ void main() { final channelModel = entity.toChannelModel(createdBy: user); expect(channelModel, isA()); expect(channelModel.id, entity.id); + expect(channelModel.ownCapabilities, entity.ownCapabilities); expect(channelModel.config.toJson()['max_message_length'], 33); expect(channelModel.frozen, entity.frozen); expect(channelModel.createdAt, isSameDateAs(entity.createdAt)); @@ -68,6 +70,7 @@ void main() { final channelModel = channelState.channel!; expect(channelModel.id, entity.id); + expect(channelModel.ownCapabilities, entity.ownCapabilities); expect(channelModel.config.toJson()['max_message_length'], 33); expect(channelModel.frozen, entity.frozen); expect(channelModel.createdAt, isSameDateAs(entity.createdAt)); @@ -87,6 +90,7 @@ void main() { id: 'testId', type: 'testType', cid: 'testCid', + ownCapabilities: ['testCapability'], config: ChannelConfig(maxMessageLength: 33), frozen: math.Random().nextBool(), lastMessageAt: DateTime.now(), @@ -101,6 +105,7 @@ void main() { final channelEntity = model.toEntity(); expect(channelEntity, isA()); expect(channelEntity.id, model.id); + expect(channelEntity.ownCapabilities, model.ownCapabilities); expect( channelEntity.config['max_message_length'], model.config.maxMessageLength,