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