Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(llc,ui,persistence): Deprecated Member.role in favor of Member.channelRole #1124

Merged
merged 6 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/stream_chat/lib/src/client/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Read> get read => _channelState.read ?? <Read>[];

Expand Down
10 changes: 10 additions & 0 deletions packages/stream_chat/lib/src/core/models/member.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,6 +17,7 @@ class Member extends Equatable {
this.inviteRejectedAt,
this.invited = false,
this.role,
this.channelRole,
this.userId,
this.isModerator = false,
DateTime? createdAt,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -76,6 +83,7 @@ class Member extends Equatable {
DateTime? inviteRejectedAt,
bool? invited,
String? role,
String? channelRole,
String? userId,
bool? isModerator,
DateTime? createdAt,
Expand All @@ -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,
Expand All @@ -109,6 +118,7 @@ class Member extends Equatable {
inviteRejectedAt,
invited,
role,
channelRole,
userId,
isModerator,
banned,
Expand Down
2 changes: 2 additions & 0 deletions packages/stream_chat/lib/src/core/models/member.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/stream_chat/test/fixtures/member.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 1 addition & 1 deletion packages/stream_chat/test/src/core/models/member_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void main() {
test('should parse json correctly', () {
final member = Member.fromJson(jsonFixture('member.json'));
expect(member.user, isA<User>());
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'));
});
Expand Down
4 changes: 4 additions & 0 deletions packages/stream_chat_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class _ChannelBottomSheetState extends State<ChannelBottomSheet> {

final userAsMember = members
.firstWhere((e) => e.user?.id == _streamChatState.currentUser?.id);
final isOwner = userAsMember.role == 'owner';

return Material(
color: _streamChatThemeData.colorTheme.barsBg,
Expand Down Expand Up @@ -179,9 +178,8 @@ class _ChannelBottomSheetState extends State<ChannelBottomSheet> {
});
},
),
if (isOwner &&
channel.ownCapabilities
.contains(PermissionType.deleteChannel))
if (channel.ownCapabilities
.contains(PermissionType.deleteChannel))
StreamOptionListTile(
leading: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions packages/stream_chat_persistence/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/stream_chat_persistence/lib/src/entity/members.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()();

Expand Down
Loading