feat(llc): add support for channel.membership

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2022-05-19 14:34:04 +05:30
committed by xsahil03x
parent 8ae6023d48
commit b1e4e134ca
4 changed files with 41 additions and 44 deletions
@@ -171,6 +171,18 @@ class Channel {
return state!.channelStateStream.map((cs) => cs.channel?.config); return state!.channelStateStream.map((cs) => cs.channel?.config);
} }
/// Relationship of the current user to this channel.
Member? get membership {
_checkInitialized();
return state!._channelState.channel?.membership;
}
/// Relationship of the current user to this channel as a stream.
Stream<Member?> get membershipStream {
_checkInitialized();
return state!.channelStateStream.map((cs) => cs.channel?.membership);
}
/// Channel user creator. /// Channel user creator.
User? get createdBy { User? get createdBy {
_checkInitialized(); _checkInitialized();
@@ -12,7 +12,7 @@ part of 'attachment_file.dart';
T _$identity<T>(T value) => value; T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError( final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
UploadState _$UploadStateFromJson(Map<String, dynamic> json) { UploadState _$UploadStateFromJson(Map<String, dynamic> json) {
switch (json['runtimeType']) { switch (json['runtimeType']) {
@@ -31,39 +31,6 @@ UploadState _$UploadStateFromJson(Map<String, dynamic> json) {
} }
} }
/// @nodoc
class _$UploadStateTearOff {
const _$UploadStateTearOff();
Preparing preparing() {
return const Preparing();
}
InProgress inProgress({required int uploaded, required int total}) {
return InProgress(
uploaded: uploaded,
total: total,
);
}
Success success() {
return const Success();
}
Failed failed({required String error}) {
return Failed(
error: error,
);
}
UploadState fromJson(Map<String, Object?> json) {
return UploadState.fromJson(json);
}
}
/// @nodoc
const $UploadState = _$UploadStateTearOff();
/// @nodoc /// @nodoc
mixin _$UploadState { mixin _$UploadState {
@optionalTypeArgs @optionalTypeArgs
@@ -156,7 +123,7 @@ class __$$PreparingCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
/// @nodoc /// @nodoc
@JsonSerializable() @JsonSerializable()
class _$Preparing implements Preparing { class _$Preparing implements Preparing {
const _$Preparing({String? $type}) : $type = $type ?? 'preparing'; const _$Preparing({final String? $type}) : $type = $type ?? 'preparing';
factory _$Preparing.fromJson(Map<String, dynamic> json) => factory _$Preparing.fromJson(Map<String, dynamic> json) =>
_$$PreparingFromJson(json); _$$PreparingFromJson(json);
@@ -175,6 +142,7 @@ class _$Preparing implements Preparing {
(other.runtimeType == runtimeType && other is _$Preparing); (other.runtimeType == runtimeType && other is _$Preparing);
} }
@JsonKey(ignore: true)
@override @override
int get hashCode => runtimeType.hashCode; int get hashCode => runtimeType.hashCode;
@@ -304,7 +272,7 @@ class __$$InProgressCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
@JsonSerializable() @JsonSerializable()
class _$InProgress implements InProgress { class _$InProgress implements InProgress {
const _$InProgress( const _$InProgress(
{required this.uploaded, required this.total, String? $type}) {required this.uploaded, required this.total, final String? $type})
: $type = $type ?? 'inProgress'; : $type = $type ?? 'inProgress';
factory _$InProgress.fromJson(Map<String, dynamic> json) => factory _$InProgress.fromJson(Map<String, dynamic> json) =>
@@ -332,6 +300,7 @@ class _$InProgress implements InProgress {
const DeepCollectionEquality().equals(other.total, total)); const DeepCollectionEquality().equals(other.total, total));
} }
@JsonKey(ignore: true)
@override @override
int get hashCode => Object.hash( int get hashCode => Object.hash(
runtimeType, runtimeType,
@@ -424,14 +393,14 @@ class _$InProgress implements InProgress {
} }
abstract class InProgress implements UploadState { abstract class InProgress implements UploadState {
const factory InProgress({required int uploaded, required int total}) = const factory InProgress(
_$InProgress; {required final int uploaded, required final int total}) = _$InProgress;
factory InProgress.fromJson(Map<String, dynamic> json) = factory InProgress.fromJson(Map<String, dynamic> json) =
_$InProgress.fromJson; _$InProgress.fromJson;
int get uploaded; int get uploaded => throw _privateConstructorUsedError;
int get total; int get total => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$$InProgressCopyWith<_$InProgress> get copyWith => _$$InProgressCopyWith<_$InProgress> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@@ -456,7 +425,7 @@ class __$$SuccessCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
/// @nodoc /// @nodoc
@JsonSerializable() @JsonSerializable()
class _$Success implements Success { class _$Success implements Success {
const _$Success({String? $type}) : $type = $type ?? 'success'; const _$Success({final String? $type}) : $type = $type ?? 'success';
factory _$Success.fromJson(Map<String, dynamic> json) => factory _$Success.fromJson(Map<String, dynamic> json) =>
_$$SuccessFromJson(json); _$$SuccessFromJson(json);
@@ -475,6 +444,7 @@ class _$Success implements Success {
(other.runtimeType == runtimeType && other is _$Success); (other.runtimeType == runtimeType && other is _$Success);
} }
@JsonKey(ignore: true)
@override @override
int get hashCode => runtimeType.hashCode; int get hashCode => runtimeType.hashCode;
@@ -596,7 +566,7 @@ class __$$FailedCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
/// @nodoc /// @nodoc
@JsonSerializable() @JsonSerializable()
class _$Failed implements Failed { class _$Failed implements Failed {
const _$Failed({required this.error, String? $type}) const _$Failed({required this.error, final String? $type})
: $type = $type ?? 'failed'; : $type = $type ?? 'failed';
factory _$Failed.fromJson(Map<String, dynamic> json) => factory _$Failed.fromJson(Map<String, dynamic> json) =>
@@ -621,6 +591,7 @@ class _$Failed implements Failed {
const DeepCollectionEquality().equals(other.error, error)); const DeepCollectionEquality().equals(other.error, error));
} }
@JsonKey(ignore: true)
@override @override
int get hashCode => int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(error)); Object.hash(runtimeType, const DeepCollectionEquality().hash(error));
@@ -711,11 +682,11 @@ class _$Failed implements Failed {
} }
abstract class Failed implements UploadState { abstract class Failed implements UploadState {
const factory Failed({required String error}) = _$Failed; const factory Failed({required final String error}) = _$Failed;
factory Failed.fromJson(Map<String, dynamic> json) = _$Failed.fromJson; factory Failed.fromJson(Map<String, dynamic> json) = _$Failed.fromJson;
String get error; String get error => throw _privateConstructorUsedError;
@JsonKey(ignore: true) @JsonKey(ignore: true)
_$$FailedCopyWith<_$Failed> get copyWith => _$$FailedCopyWith<_$Failed> get copyWith =>
throw _privateConstructorUsedError; throw _privateConstructorUsedError;
@@ -1,5 +1,6 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:stream_chat/src/core/models/channel_config.dart'; import 'package:stream_chat/src/core/models/channel_config.dart';
import 'package:stream_chat/src/core/models/member.dart';
import 'package:stream_chat/src/core/models/user.dart'; import 'package:stream_chat/src/core/models/user.dart';
import 'package:stream_chat/src/core/util/serializer.dart'; import 'package:stream_chat/src/core/util/serializer.dart';
@@ -25,6 +26,7 @@ class ChannelModel {
this.extraData = const {}, this.extraData = const {},
this.team, this.team,
this.cooldown = 0, this.cooldown = 0,
this.membership,
}) : assert( }) : assert(
(cid != null && cid.contains(':')) || (id != null && type != null), (cid != null && cid.contains(':')) || (id != null && type != null),
'provide either a cid or an id and type', 'provide either a cid or an id and type',
@@ -100,6 +102,10 @@ class ChannelModel {
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly) @JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
final String? team; final String? team;
/// Relationship of the current user to this channel.
@JsonKey(includeIfNull: false)
final Member? membership;
/// Known top level fields. /// Known top level fields.
/// Useful for [Serializer] methods. /// Useful for [Serializer] methods.
static const topLevelFields = [ static const topLevelFields = [
@@ -117,6 +123,7 @@ class ChannelModel {
'member_count', 'member_count',
'team', 'team',
'cooldown', 'cooldown',
'membership',
]; ];
/// Shortcut for channel name /// Shortcut for channel name
@@ -145,6 +152,7 @@ class ChannelModel {
Map<String, Object?>? extraData, Map<String, Object?>? extraData,
String? team, String? team,
int? cooldown, int? cooldown,
Member? membership,
}) => }) =>
ChannelModel( ChannelModel(
id: id ?? this.id, id: id ?? this.id,
@@ -162,6 +170,7 @@ class ChannelModel {
extraData: extraData ?? this.extraData, extraData: extraData ?? this.extraData,
team: team ?? this.team, team: team ?? this.team,
cooldown: cooldown ?? this.cooldown, cooldown: cooldown ?? this.cooldown,
membership: membership ?? this.membership,
); );
/// Returns a new [ChannelModel] that is a combination of this channelModel /// Returns a new [ChannelModel] that is a combination of this channelModel
@@ -184,6 +193,7 @@ class ChannelModel {
extraData: {...extraData, ...other.extraData}, extraData: {...extraData, ...other.extraData},
team: other.team, team: other.team,
cooldown: other.cooldown, cooldown: other.cooldown,
membership: other.membership,
); );
} }
} }
@@ -36,6 +36,9 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) => ChannelModel(
extraData: json['extra_data'] as Map<String, dynamic>? ?? const {}, extraData: json['extra_data'] as Map<String, dynamic>? ?? const {},
team: json['team'] as String?, team: json['team'] as String?,
cooldown: json['cooldown'] as int? ?? 0, cooldown: json['cooldown'] as int? ?? 0,
membership: json['membership'] == null
? null
: Member.fromJson(json['membership'] as Map<String, dynamic>),
); );
Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) { Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) {
@@ -63,5 +66,6 @@ Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) {
val['cooldown'] = instance.cooldown; val['cooldown'] = instance.cooldown;
val['extra_data'] = instance.extraData; val['extra_data'] = instance.extraData;
writeNotNull('team', readonly(instance.team)); writeNotNull('team', readonly(instance.team));
writeNotNull('membership', instance.membership?.toJson());
return val; return val;
} }