feat(llc): add support for channel.membership
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -171,6 +171,18 @@ class Channel {
|
||||
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.
|
||||
User? get createdBy {
|
||||
_checkInitialized();
|
||||
|
||||
@@ -12,7 +12,7 @@ part of 'attachment_file.dart';
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
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) {
|
||||
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
|
||||
mixin _$UploadState {
|
||||
@optionalTypeArgs
|
||||
@@ -156,7 +123,7 @@ class __$$PreparingCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
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) =>
|
||||
_$$PreparingFromJson(json);
|
||||
@@ -175,6 +142,7 @@ class _$Preparing implements Preparing {
|
||||
(other.runtimeType == runtimeType && other is _$Preparing);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@@ -304,7 +272,7 @@ class __$$InProgressCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
|
||||
@JsonSerializable()
|
||||
class _$InProgress implements InProgress {
|
||||
const _$InProgress(
|
||||
{required this.uploaded, required this.total, String? $type})
|
||||
{required this.uploaded, required this.total, final String? $type})
|
||||
: $type = $type ?? 'inProgress';
|
||||
|
||||
factory _$InProgress.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -332,6 +300,7 @@ class _$InProgress implements InProgress {
|
||||
const DeepCollectionEquality().equals(other.total, total));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
@@ -424,14 +393,14 @@ class _$InProgress implements InProgress {
|
||||
}
|
||||
|
||||
abstract class InProgress implements UploadState {
|
||||
const factory InProgress({required int uploaded, required int total}) =
|
||||
_$InProgress;
|
||||
const factory InProgress(
|
||||
{required final int uploaded, required final int total}) = _$InProgress;
|
||||
|
||||
factory InProgress.fromJson(Map<String, dynamic> json) =
|
||||
_$InProgress.fromJson;
|
||||
|
||||
int get uploaded;
|
||||
int get total;
|
||||
int get uploaded => throw _privateConstructorUsedError;
|
||||
int get total => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
_$$InProgressCopyWith<_$InProgress> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -456,7 +425,7 @@ class __$$SuccessCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
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) =>
|
||||
_$$SuccessFromJson(json);
|
||||
@@ -475,6 +444,7 @@ class _$Success implements Success {
|
||||
(other.runtimeType == runtimeType && other is _$Success);
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => runtimeType.hashCode;
|
||||
|
||||
@@ -596,7 +566,7 @@ class __$$FailedCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$Failed implements Failed {
|
||||
const _$Failed({required this.error, String? $type})
|
||||
const _$Failed({required this.error, final String? $type})
|
||||
: $type = $type ?? 'failed';
|
||||
|
||||
factory _$Failed.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -621,6 +591,7 @@ class _$Failed implements Failed {
|
||||
const DeepCollectionEquality().equals(other.error, error));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, const DeepCollectionEquality().hash(error));
|
||||
@@ -711,11 +682,11 @@ class _$Failed implements Failed {
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
String get error;
|
||||
String get error => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
_$$FailedCopyWith<_$Failed> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:json_annotation/json_annotation.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/util/serializer.dart';
|
||||
|
||||
@@ -25,6 +26,7 @@ class ChannelModel {
|
||||
this.extraData = const {},
|
||||
this.team,
|
||||
this.cooldown = 0,
|
||||
this.membership,
|
||||
}) : assert(
|
||||
(cid != null && cid.contains(':')) || (id != null && type != null),
|
||||
'provide either a cid or an id and type',
|
||||
@@ -100,6 +102,10 @@ class ChannelModel {
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final String? team;
|
||||
|
||||
/// Relationship of the current user to this channel.
|
||||
@JsonKey(includeIfNull: false)
|
||||
final Member? membership;
|
||||
|
||||
/// Known top level fields.
|
||||
/// Useful for [Serializer] methods.
|
||||
static const topLevelFields = [
|
||||
@@ -117,6 +123,7 @@ class ChannelModel {
|
||||
'member_count',
|
||||
'team',
|
||||
'cooldown',
|
||||
'membership',
|
||||
];
|
||||
|
||||
/// Shortcut for channel name
|
||||
@@ -145,6 +152,7 @@ class ChannelModel {
|
||||
Map<String, Object?>? extraData,
|
||||
String? team,
|
||||
int? cooldown,
|
||||
Member? membership,
|
||||
}) =>
|
||||
ChannelModel(
|
||||
id: id ?? this.id,
|
||||
@@ -162,6 +170,7 @@ class ChannelModel {
|
||||
extraData: extraData ?? this.extraData,
|
||||
team: team ?? this.team,
|
||||
cooldown: cooldown ?? this.cooldown,
|
||||
membership: membership ?? this.membership,
|
||||
);
|
||||
|
||||
/// Returns a new [ChannelModel] that is a combination of this channelModel
|
||||
@@ -184,6 +193,7 @@ class ChannelModel {
|
||||
extraData: {...extraData, ...other.extraData},
|
||||
team: other.team,
|
||||
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 {},
|
||||
team: json['team'] as String?,
|
||||
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) {
|
||||
@@ -63,5 +66,6 @@ Map<String, dynamic> _$ChannelModelToJson(ChannelModel instance) {
|
||||
val['cooldown'] = instance.cooldown;
|
||||
val['extra_data'] = instance.extraData;
|
||||
writeNotNull('team', readonly(instance.team));
|
||||
writeNotNull('membership', instance.membership?.toJson());
|
||||
return val;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user