make enums fall back to unknown or null where possible
Futureproofing.
This commit is contained in:
parent
401b527714
commit
53d9c2b1e6
11 changed files with 28 additions and 6 deletions
|
|
@ -663,6 +663,7 @@ class RoomSettingsSectionsController(final String roomId)
|
|||
.invited => "After invite",
|
||||
.joined => "After join",
|
||||
.worldReadable => "Anyone",
|
||||
.unknown => "Unknown",
|
||||
},
|
||||
onChanged: canSetHistoryVisibility
|
||||
? (visibility) => setState(
|
||||
|
|
|
|||
|
|
@ -9,5 +9,6 @@ extension JoinRuleName on JoinRule {
|
|||
.restricted => "Restricted",
|
||||
.knockRestricted => "Restricted or knock",
|
||||
.private => "Private",
|
||||
.unknown => "Unknown",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ sealed class HistoryVisibilityContent extends Content
|
|||
with _$HistoryVisibilityContent {
|
||||
HistoryVisibilityContent._();
|
||||
factory HistoryVisibilityContent({
|
||||
@JsonKey(unknownEnumValue: HistoryVisibility.unknown)
|
||||
required HistoryVisibility historyVisibility,
|
||||
}) = _HistoryVisibilityContent;
|
||||
|
||||
|
|
@ -16,4 +17,4 @@ sealed class HistoryVisibilityContent extends Content
|
|||
}
|
||||
|
||||
@JsonEnum(fieldRename: FieldRename.snake)
|
||||
enum HistoryVisibility { invited, joined, shared, worldReadable }
|
||||
enum HistoryVisibility { invited, joined, shared, worldReadable, unknown }
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ part "join_rules.g.dart";
|
|||
sealed class JoinRulesContent extends Content with _$JoinRulesContent {
|
||||
JoinRulesContent._();
|
||||
factory JoinRulesContent({
|
||||
required JoinRule joinRule,
|
||||
@JsonKey(unknownEnumValue: JoinRule.unknown) required JoinRule joinRule,
|
||||
@Default(ISet.empty()) ISet<AllowCondition> allow,
|
||||
}) = _JoinRulesContent;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ sealed class MembershipContent extends Content with _$MembershipContent {
|
|||
fromJson: MembershipContent.displaynameFromJson,
|
||||
)
|
||||
required String? displayName,
|
||||
@JsonKey(name: "membership") required MembershipStatus status,
|
||||
@JsonKey(name: "membership", unknownEnumValue: MembershipStatus.unknown)
|
||||
required MembershipStatus status,
|
||||
Uri? avatarUrl,
|
||||
String? reason,
|
||||
@Default(false) bool isDirect,
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.text")
|
||||
factory MessageContent.text({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = TextMessageContent;
|
||||
|
|
@ -27,6 +28,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.notice")
|
||||
factory MessageContent.notice({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = NoticeMessageContent;
|
||||
|
|
@ -34,6 +36,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.emote")
|
||||
factory MessageContent.emote({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
}) = EmoteMessageContent;
|
||||
|
|
@ -41,6 +44,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.image")
|
||||
factory MessageContent.image({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
EncryptedFile? file,
|
||||
|
|
@ -52,6 +56,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.file")
|
||||
factory MessageContent.file({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
EncryptedFile? file,
|
||||
|
|
@ -63,6 +68,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.audio")
|
||||
factory MessageContent.audio({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
EncryptedFile? file,
|
||||
|
|
@ -74,6 +80,7 @@ sealed class MessageContent extends Content with _$MessageContent {
|
|||
@FreezedUnionValue("m.video")
|
||||
factory MessageContent.video({
|
||||
required String body,
|
||||
@JsonKey(unknownEnumValue: JsonKey.nullForUndefinedEnumValue)
|
||||
MessageFormat? format,
|
||||
String? formattedBody,
|
||||
EncryptedFile? file,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,13 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
@JsonEnum(fieldRename: .snake)
|
||||
enum JoinRule { public, knock, invite, private, restricted, knockRestricted }
|
||||
enum JoinRule {
|
||||
public,
|
||||
knock,
|
||||
invite,
|
||||
private,
|
||||
restricted,
|
||||
knockRestricted,
|
||||
|
||||
unknown,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
enum MembershipStatus { leave, invite, ban, join, knock }
|
||||
enum MembershipStatus { leave, invite, ban, join, knock, unknown }
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ part "room_summary.g.dart";
|
|||
class const RoomSummary({
|
||||
required final String roomId,
|
||||
@JsonKey(name: "num_joined_members") final int? joinedMembers,
|
||||
final JoinRule? joinRule,
|
||||
@JsonKey(unknownEnumValue: JoinRule.unknown) final JoinRule? joinRule,
|
||||
|
||||
/// Rooms whose members may join without an invite, for restricted rooms.
|
||||
final IList<String> allowedRoomIds = const .empty(),
|
||||
|
|
|
|||
|
|
@ -240,6 +240,7 @@ class const EventRenderer(
|
|||
.joined => "since joined",
|
||||
.shared => "all history visible (shared)",
|
||||
.worldReadable => "all history visible (world readable)",
|
||||
.unknown => "something Nexus doesn't know about",
|
||||
}}",
|
||||
),
|
||||
PinnedEventsContent(:final pinnedEvents) => () {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ class const MembershipRenderer(
|
|||
.leave => event.sender == event.stateKey ? "left" : (previous == .ban ? "was unbanned from" : "was kicked from"),
|
||||
.ban => "was banned from",
|
||||
.knock => "asked to join",
|
||||
.unknown => "changed their membership in",
|
||||
}} the room${event.sender == event.stateKey ? "" : " by"}",
|
||||
),
|
||||
if (event.sender != event.stateKey)
|
||||
|
|
|
|||
Loading…
Reference in a new issue