refactor(llc): move membership from channel_model to channel_state
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -174,13 +174,13 @@ class Channel {
|
||||
/// Relationship of the current user to this channel.
|
||||
Member? get membership {
|
||||
_checkInitialized();
|
||||
return state!._channelState.channel?.membership;
|
||||
return state!._channelState.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);
|
||||
return state!.channelStateStream.map((cs) => cs.membership);
|
||||
}
|
||||
|
||||
/// Channel user creator.
|
||||
|
||||
@@ -26,7 +26,6 @@ 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',
|
||||
@@ -102,10 +101,6 @@ 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 = [
|
||||
@@ -123,7 +118,6 @@ class ChannelModel {
|
||||
'member_count',
|
||||
'team',
|
||||
'cooldown',
|
||||
'membership',
|
||||
];
|
||||
|
||||
/// Shortcut for channel name
|
||||
@@ -152,7 +146,6 @@ class ChannelModel {
|
||||
Map<String, Object?>? extraData,
|
||||
String? team,
|
||||
int? cooldown,
|
||||
Member? membership,
|
||||
}) =>
|
||||
ChannelModel(
|
||||
id: id ?? this.id,
|
||||
@@ -170,7 +163,6 @@ 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
|
||||
@@ -193,7 +185,6 @@ class ChannelModel {
|
||||
extraData: {...extraData, ...other.extraData},
|
||||
team: other.team,
|
||||
cooldown: other.cooldown,
|
||||
membership: other.membership,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ 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) {
|
||||
@@ -66,6 +63,5 @@ 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;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ class ChannelState {
|
||||
this.watcherCount,
|
||||
this.watchers,
|
||||
this.read,
|
||||
this.membership,
|
||||
});
|
||||
|
||||
/// The channel to which this state belongs
|
||||
@@ -42,6 +43,9 @@ class ChannelState {
|
||||
/// The list of channel reads
|
||||
final List<Read>? read;
|
||||
|
||||
///
|
||||
final Member? membership;
|
||||
|
||||
/// Create a new instance from a json
|
||||
static ChannelState fromJson(Map<String, dynamic> json) =>
|
||||
_$ChannelStateFromJson(json);
|
||||
@@ -58,6 +62,7 @@ class ChannelState {
|
||||
int? watcherCount,
|
||||
List<User>? watchers,
|
||||
List<Read>? read,
|
||||
Member? membership,
|
||||
}) =>
|
||||
ChannelState(
|
||||
channel: channel ?? this.channel,
|
||||
@@ -67,5 +72,6 @@ class ChannelState {
|
||||
watcherCount: watcherCount ?? this.watcherCount,
|
||||
watchers: watchers ?? this.watchers,
|
||||
read: read ?? this.read,
|
||||
membership: membership ?? this.membership,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ ChannelState _$ChannelStateFromJson(Map<String, dynamic> json) => ChannelState(
|
||||
read: (json['read'] as List<dynamic>?)
|
||||
?.map((e) => Read.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
membership: json['membership'] == null
|
||||
? null
|
||||
: Member.fromJson(json['membership'] as Map<String, dynamic>),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ChannelStateToJson(ChannelState instance) =>
|
||||
@@ -38,4 +41,5 @@ Map<String, dynamic> _$ChannelStateToJson(ChannelState instance) =>
|
||||
'watcher_count': instance.watcherCount,
|
||||
'watchers': instance.watchers?.map((e) => e.toJson()).toList(),
|
||||
'read': instance.read?.map((e) => e.toJson()).toList(),
|
||||
'membership': instance.membership?.toJson(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user