diff --git a/packages/stream_chat/CHANGELOG.md b/packages/stream_chat/CHANGELOG.md index f5ed075b3..889717629 100644 --- a/packages/stream_chat/CHANGELOG.md +++ b/packages/stream_chat/CHANGELOG.md @@ -4,6 +4,11 @@ - Added support for extra data in attachment file uploader. Thanks, [@rlee1990](https://github.com/rlee1990). +🔄 Changed + +- Deprecated `role` in `Member` in favor of `channelRole` +- Deprecated `currentUserRole` getter in `Channel` in favor of `currentUserChannelRole` + ## 4.0.1 - Minor fixes diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index bb97a3c68..a27b672ff 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -2017,8 +2017,12 @@ class ChannelClientState { ); /// User role for the current user. + @Deprecated('Please use currentUserChannelRole') String? get currentUserRole => currentUserMember?.role; + /// Channel role for the current user + String? get currentUserChannelRole => currentUserMember?.channelRole; + /// Channel read list. List get read => _channelState.read ?? []; diff --git a/packages/stream_chat/lib/src/core/models/member.dart b/packages/stream_chat/lib/src/core/models/member.dart index e8b0ecff9..c2dc9eb18 100644 --- a/packages/stream_chat/lib/src/core/models/member.dart +++ b/packages/stream_chat/lib/src/core/models/member.dart @@ -1,3 +1,5 @@ +// ignore_for_file: deprecated_member_use_from_same_package + import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:stream_chat/src/core/models/user.dart'; @@ -15,6 +17,7 @@ class Member extends Equatable { this.inviteRejectedAt, this.invited = false, this.role, + this.channelRole, this.userId, this.isModerator = false, DateTime? createdAt, @@ -46,8 +49,12 @@ class Member extends Equatable { final bool invited; /// The role of the user in the channel + @Deprecated('Please use channelRole') final String? role; + /// The role of this member in the channel + final String? channelRole; + /// The id of the interested user final String? userId; @@ -76,6 +83,7 @@ class Member extends Equatable { DateTime? inviteRejectedAt, bool? invited, String? role, + String? channelRole, String? userId, bool? isModerator, DateTime? createdAt, @@ -93,6 +101,7 @@ class Member extends Equatable { banExpires: banExpires ?? this.banExpires, shadowBanned: shadowBanned ?? this.shadowBanned, role: role ?? this.role, + channelRole: channelRole ?? this.channelRole, userId: userId ?? this.userId, isModerator: isModerator ?? this.isModerator, createdAt: createdAt ?? this.createdAt, @@ -109,6 +118,7 @@ class Member extends Equatable { inviteRejectedAt, invited, role, + channelRole, userId, isModerator, banned, diff --git a/packages/stream_chat/lib/src/core/models/member.g.dart b/packages/stream_chat/lib/src/core/models/member.g.dart index 4da3cfd2a..1bcde74db 100644 --- a/packages/stream_chat/lib/src/core/models/member.g.dart +++ b/packages/stream_chat/lib/src/core/models/member.g.dart @@ -18,6 +18,7 @@ Member _$MemberFromJson(Map json) => Member( : DateTime.parse(json['invite_rejected_at'] as String), invited: json['invited'] as bool? ?? false, role: json['role'] as String?, + channelRole: json['channel_role'] as String?, userId: json['user_id'] as String?, isModerator: json['is_moderator'] as bool? ?? false, createdAt: json['created_at'] == null @@ -39,6 +40,7 @@ Map _$MemberToJson(Member instance) => { 'invite_rejected_at': instance.inviteRejectedAt?.toIso8601String(), 'invited': instance.invited, 'role': instance.role, + 'channel_role': instance.channelRole, 'user_id': instance.userId, 'is_moderator': instance.isModerator, 'banned': instance.banned, diff --git a/packages/stream_chat/test/fixtures/member.json b/packages/stream_chat/test/fixtures/member.json index a33acf130..163878a38 100644 --- a/packages/stream_chat/test/fixtures/member.json +++ b/packages/stream_chat/test/fixtures/member.json @@ -9,7 +9,7 @@ "name": "Robin Papa", "image": "https://pbs.twimg.com/profile_images/669512187778498560/L7wQctBt.jpg" }, - "role": "member", + "channel_role": "channel_member", "created_at": "2020-01-28T22:17:30.95443Z", "updated_at": "2020-01-28T22:17:30.95443Z" } \ No newline at end of file diff --git a/packages/stream_chat/test/src/core/models/member_test.dart b/packages/stream_chat/test/src/core/models/member_test.dart index 4cd8efda8..98d427433 100644 --- a/packages/stream_chat/test/src/core/models/member_test.dart +++ b/packages/stream_chat/test/src/core/models/member_test.dart @@ -9,7 +9,7 @@ void main() { test('should parse json correctly', () { final member = Member.fromJson(jsonFixture('member.json')); expect(member.user, isA()); - expect(member.role, 'member'); + expect(member.channelRole, 'channel_member'); expect(member.createdAt, DateTime.parse('2020-01-28T22:17:30.95443Z')); expect(member.updatedAt, DateTime.parse('2020-01-28T22:17:30.95443Z')); }); diff --git a/packages/stream_chat_flutter/CHANGELOG.md b/packages/stream_chat_flutter/CHANGELOG.md index 5adf5c650..beb632c5e 100644 --- a/packages/stream_chat_flutter/CHANGELOG.md +++ b/packages/stream_chat_flutter/CHANGELOG.md @@ -5,6 +5,10 @@ - Fixed attachment picker ui. - Fixed message widget thread indicator in reverse mode. +🔄 Changed + +- Removed `isOwner` condition from `ChannelBottomSheet` and `StreamChannelInfoBottomSheet` for delete option tile. + ## 4.0.1 - Minor fixes diff --git a/packages/stream_chat_flutter/lib/src/channel_bottom_sheet.dart b/packages/stream_chat_flutter/lib/src/channel_bottom_sheet.dart index 664384797..8b273fe25 100644 --- a/packages/stream_chat_flutter/lib/src/channel_bottom_sheet.dart +++ b/packages/stream_chat_flutter/lib/src/channel_bottom_sheet.dart @@ -33,7 +33,6 @@ class _ChannelBottomSheetState extends State { final userAsMember = members .firstWhere((e) => e.user?.id == _streamChatState.currentUser?.id); - final isOwner = userAsMember.role == 'owner'; return Material( color: _streamChatThemeData.colorTheme.barsBg, @@ -179,9 +178,8 @@ class _ChannelBottomSheetState extends State { }); }, ), - if (isOwner && - channel.ownCapabilities - .contains(PermissionType.deleteChannel)) + if (channel.ownCapabilities + .contains(PermissionType.deleteChannel)) StreamOptionListTile( leading: Padding( padding: const EdgeInsets.symmetric(horizontal: 16), diff --git a/packages/stream_chat_flutter/lib/src/v4/stream_channel_info_bottom_sheet.dart b/packages/stream_chat_flutter/lib/src/v4/stream_channel_info_bottom_sheet.dart index 986a9cb31..19c2349be 100644 --- a/packages/stream_chat_flutter/lib/src/v4/stream_channel_info_bottom_sheet.dart +++ b/packages/stream_chat_flutter/lib/src/v4/stream_channel_info_bottom_sheet.dart @@ -59,10 +59,6 @@ class StreamChannelInfoBottomSheet extends StatelessWidget { final members = channel.state?.members ?? []; - final isOwner = members.any( - (it) => it.user?.id == currentUser?.id && it.role == 'owner', - ); - // remove current user in case it's 1-1 conversation if (isOneToOneChannel) { members.removeWhere((it) => it.user?.id == currentUser?.id); @@ -153,7 +149,7 @@ class StreamChannelInfoBottomSheet extends StatelessWidget { ), onTap: onLeaveChannelTap, ), - if (isOwner) + if (channel.ownCapabilities.contains(PermissionType.deleteChannel)) StreamOptionListTile( leading: Padding( padding: const EdgeInsets.symmetric(horizontal: 16), diff --git a/packages/stream_chat_persistence/CHANGELOG.md b/packages/stream_chat_persistence/CHANGELOG.md index 6dd74f8ba..175ebc691 100644 --- a/packages/stream_chat_persistence/CHANGELOG.md +++ b/packages/stream_chat_persistence/CHANGELOG.md @@ -1,3 +1,9 @@ +## Upcoming + +🔄 Changed + +- Deprecated `role` field in `Member` table in favor of `channelRole` + ## 4.0.1 - Updated `stream_chat` dependency to [`4.0.1`](https://pub.dev/packages/stream_chat/changelog). 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 9b73312db..1de782451 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 => 7; + int get schemaVersion => 8; @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 e5382861f..9c44cb2f4 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 @@ -3888,6 +3888,9 @@ class MemberEntity extends DataClass implements Insertable { /// The role of the user in the channel final String? role; + /// 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; @@ -3915,6 +3918,7 @@ class MemberEntity extends DataClass implements Insertable { {required this.userId, required this.channelCid, this.role, + this.channelRole, this.inviteAcceptedAt, this.inviteRejectedAt, required this.invited, @@ -3932,6 +3936,8 @@ class MemberEntity extends DataClass implements Insertable { .mapFromDatabaseResponse(data['${effectivePrefix}channel_cid'])!, role: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}role']), + channelRole: const StringType() + .mapFromDatabaseResponse(data['${effectivePrefix}channel_role']), inviteAcceptedAt: const DateTimeType().mapFromDatabaseResponse( data['${effectivePrefix}invite_accepted_at']), inviteRejectedAt: const DateTimeType().mapFromDatabaseResponse( @@ -3958,6 +3964,9 @@ class MemberEntity extends DataClass implements Insertable { if (!nullToAbsent || role != null) { map['role'] = Variable(role); } + if (!nullToAbsent || channelRole != null) { + map['channel_role'] = Variable(channelRole); + } if (!nullToAbsent || inviteAcceptedAt != null) { map['invite_accepted_at'] = Variable(inviteAcceptedAt); } @@ -3980,6 +3989,7 @@ class MemberEntity extends DataClass implements Insertable { userId: serializer.fromJson(json['userId']), channelCid: serializer.fromJson(json['channelCid']), role: serializer.fromJson(json['role']), + channelRole: serializer.fromJson(json['channelRole']), inviteAcceptedAt: serializer.fromJson(json['inviteAcceptedAt']), inviteRejectedAt: @@ -3999,6 +4009,7 @@ class MemberEntity extends DataClass implements Insertable { 'userId': serializer.toJson(userId), 'channelCid': serializer.toJson(channelCid), 'role': serializer.toJson(role), + 'channelRole': serializer.toJson(channelRole), 'inviteAcceptedAt': serializer.toJson(inviteAcceptedAt), 'inviteRejectedAt': serializer.toJson(inviteRejectedAt), 'invited': serializer.toJson(invited), @@ -4014,6 +4025,7 @@ class MemberEntity extends DataClass implements Insertable { {String? userId, String? channelCid, Value role = const Value.absent(), + Value channelRole = const Value.absent(), Value inviteAcceptedAt = const Value.absent(), Value inviteRejectedAt = const Value.absent(), bool? invited, @@ -4026,6 +4038,7 @@ class MemberEntity extends DataClass implements Insertable { userId: userId ?? this.userId, channelCid: channelCid ?? this.channelCid, role: role.present ? role.value : this.role, + channelRole: channelRole.present ? channelRole.value : this.channelRole, inviteAcceptedAt: inviteAcceptedAt.present ? inviteAcceptedAt.value : this.inviteAcceptedAt, @@ -4045,6 +4058,7 @@ class MemberEntity extends DataClass implements Insertable { ..write('userId: $userId, ') ..write('channelCid: $channelCid, ') ..write('role: $role, ') + ..write('channelRole: $channelRole, ') ..write('inviteAcceptedAt: $inviteAcceptedAt, ') ..write('inviteRejectedAt: $inviteRejectedAt, ') ..write('invited: $invited, ') @@ -4062,6 +4076,7 @@ class MemberEntity extends DataClass implements Insertable { userId, channelCid, role, + channelRole, inviteAcceptedAt, inviteRejectedAt, invited, @@ -4077,6 +4092,7 @@ class MemberEntity extends DataClass implements Insertable { other.userId == this.userId && other.channelCid == this.channelCid && other.role == this.role && + other.channelRole == this.channelRole && other.inviteAcceptedAt == this.inviteAcceptedAt && other.inviteRejectedAt == this.inviteRejectedAt && other.invited == this.invited && @@ -4091,6 +4107,7 @@ class MembersCompanion extends UpdateCompanion { final Value userId; final Value channelCid; final Value role; + final Value channelRole; final Value inviteAcceptedAt; final Value inviteRejectedAt; final Value invited; @@ -4103,6 +4120,7 @@ class MembersCompanion extends UpdateCompanion { this.userId = const Value.absent(), this.channelCid = const Value.absent(), this.role = const Value.absent(), + this.channelRole = const Value.absent(), this.inviteAcceptedAt = const Value.absent(), this.inviteRejectedAt = const Value.absent(), this.invited = const Value.absent(), @@ -4116,6 +4134,7 @@ class MembersCompanion extends UpdateCompanion { required String userId, required String channelCid, this.role = const Value.absent(), + this.channelRole = const Value.absent(), this.inviteAcceptedAt = const Value.absent(), this.inviteRejectedAt = const Value.absent(), this.invited = const Value.absent(), @@ -4130,6 +4149,7 @@ class MembersCompanion extends UpdateCompanion { Expression? userId, Expression? channelCid, Expression? role, + Expression? channelRole, Expression? inviteAcceptedAt, Expression? inviteRejectedAt, Expression? invited, @@ -4143,6 +4163,7 @@ class MembersCompanion extends UpdateCompanion { if (userId != null) 'user_id': userId, if (channelCid != null) 'channel_cid': channelCid, if (role != null) 'role': role, + 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, @@ -4158,6 +4179,7 @@ class MembersCompanion extends UpdateCompanion { {Value? userId, Value? channelCid, Value? role, + Value? channelRole, Value? inviteAcceptedAt, Value? inviteRejectedAt, Value? invited, @@ -4170,6 +4192,7 @@ class MembersCompanion extends UpdateCompanion { userId: userId ?? this.userId, channelCid: channelCid ?? this.channelCid, role: role ?? this.role, + channelRole: channelRole ?? this.channelRole, inviteAcceptedAt: inviteAcceptedAt ?? this.inviteAcceptedAt, inviteRejectedAt: inviteRejectedAt ?? this.inviteRejectedAt, invited: invited ?? this.invited, @@ -4193,6 +4216,9 @@ class MembersCompanion extends UpdateCompanion { if (role.present) { map['role'] = Variable(role.value); } + if (channelRole.present) { + map['channel_role'] = Variable(channelRole.value); + } if (inviteAcceptedAt.present) { map['invite_accepted_at'] = Variable(inviteAcceptedAt.value); } @@ -4226,6 +4252,7 @@ class MembersCompanion extends UpdateCompanion { ..write('userId: $userId, ') ..write('channelCid: $channelCid, ') ..write('role: $role, ') + ..write('channelRole: $channelRole, ') ..write('inviteAcceptedAt: $inviteAcceptedAt, ') ..write('inviteRejectedAt: $inviteRejectedAt, ') ..write('invited: $invited, ') @@ -4262,6 +4289,12 @@ class $MembersTable extends Members late final GeneratedColumn role = GeneratedColumn( 'role', aliasedName, true, type: const StringType(), requiredDuringInsert: false); + final VerificationMeta _channelRoleMeta = + const VerificationMeta('channelRole'); + @override + late final GeneratedColumn channelRole = GeneratedColumn( + 'channel_role', aliasedName, true, + type: const StringType(), requiredDuringInsert: false); final VerificationMeta _inviteAcceptedAtMeta = const VerificationMeta('inviteAcceptedAt'); @override @@ -4327,6 +4360,7 @@ class $MembersTable extends Members userId, channelCid, role, + channelRole, inviteAcceptedAt, inviteRejectedAt, invited, @@ -4363,6 +4397,12 @@ class $MembersTable extends Members context.handle( _roleMeta, role.isAcceptableOrUnknown(data['role']!, _roleMeta)); } + if (data.containsKey('channel_role')) { + context.handle( + _channelRoleMeta, + channelRole.isAcceptableOrUnknown( + data['channel_role']!, _channelRoleMeta)); + } if (data.containsKey('invite_accepted_at')) { context.handle( _inviteAcceptedAtMeta, diff --git a/packages/stream_chat_persistence/lib/src/entity/members.dart b/packages/stream_chat_persistence/lib/src/entity/members.dart index c17099811..371cb2be5 100644 --- a/packages/stream_chat_persistence/lib/src/entity/members.dart +++ b/packages/stream_chat_persistence/lib/src/entity/members.dart @@ -12,8 +12,12 @@ class Members extends Table { text().customConstraint('REFERENCES channels(cid) ON DELETE CASCADE')(); /// The role of the user in the channel + @Deprecated('Please use channelRole') TextColumn get role => text().nullable()(); + /// The role of the user in the channel + TextColumn get channelRole => text().nullable()(); + /// The date on which the user accepted the invite to the channel DateTimeColumn get inviteAcceptedAt => dateTime().nullable()(); diff --git a/packages/stream_chat_persistence/lib/src/mapper/member_mapper.dart b/packages/stream_chat_persistence/lib/src/mapper/member_mapper.dart index 925abe164..05975ea40 100644 --- a/packages/stream_chat_persistence/lib/src/mapper/member_mapper.dart +++ b/packages/stream_chat_persistence/lib/src/mapper/member_mapper.dart @@ -12,6 +12,7 @@ extension MemberEntityX on MemberEntity { updatedAt: updatedAt, createdAt: createdAt, role: role, + channelRole: channelRole, inviteAcceptedAt: inviteAcceptedAt, invited: invited, inviteRejectedAt: inviteRejectedAt, @@ -32,7 +33,9 @@ extension MemberX on Member { inviteRejectedAt: inviteRejectedAt, invited: invited, inviteAcceptedAt: inviteAcceptedAt, + // ignore: deprecated_member_use role: role, + channelRole: channelRole, updatedAt: updatedAt, ); } diff --git a/packages/stream_chat_persistence/test/src/dao/member_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/member_dao_test.dart index 4a3a31dae..1082967e3 100644 --- a/packages/stream_chat_persistence/test/src/dao/member_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/member_dao_test.dart @@ -62,7 +62,7 @@ void main() { expect(fetchedMember.createdAt, isSameDateAs(member.createdAt)); expect(fetchedMember.isModerator, member.isModerator); expect(fetchedMember.invited, member.invited); - expect(fetchedMember.role, member.role); + expect(fetchedMember.channelRole, member.channelRole); expect(fetchedMember.updatedAt, isSameDateAs(member.updatedAt)); expect( fetchedMember.inviteAcceptedAt, @@ -89,7 +89,7 @@ void main() { expect(fetchedMember.createdAt, isSameDateAs(member.createdAt)); expect(fetchedMember.isModerator, member.isModerator); expect(fetchedMember.invited, member.invited); - expect(fetchedMember.role, member.role); + expect(fetchedMember.channelRole, member.channelRole); expect(fetchedMember.updatedAt, isSameDateAs(member.updatedAt)); expect( fetchedMember.inviteAcceptedAt, diff --git a/packages/stream_chat_persistence/test/src/mapper/member_mapper_test.dart b/packages/stream_chat_persistence/test/src/mapper/member_mapper_test.dart index a38784097..e327e7520 100644 --- a/packages/stream_chat_persistence/test/src/mapper/member_mapper_test.dart +++ b/packages/stream_chat_persistence/test/src/mapper/member_mapper_test.dart @@ -28,7 +28,7 @@ void main() { expect(member.user!.id, entity.userId); expect(member.createdAt, isSameDateAs(entity.createdAt)); expect(member.updatedAt, isSameDateAs(entity.updatedAt)); - expect(member.role, entity.role); + expect(member.channelRole, entity.channelRole); expect(member.inviteAcceptedAt, isSameDateAs(entity.inviteAcceptedAt!)); expect(member.inviteRejectedAt, isSameDateAs(entity.inviteRejectedAt!)); expect(member.invited, entity.invited); @@ -58,7 +58,7 @@ void main() { expect(entity.userId, member.user!.id); expect(entity.createdAt, isSameDateAs(member.createdAt)); expect(entity.updatedAt, isSameDateAs(member.updatedAt)); - expect(entity.role, member.role); + expect(entity.channelRole, member.channelRole); expect(entity.inviteAcceptedAt, isSameDateAs(member.inviteAcceptedAt!)); expect(entity.inviteRejectedAt, isSameDateAs(member.inviteRejectedAt!)); expect(entity.invited, member.invited);