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