Move to Flutter 3.47, use the improvements that come with this (#64)
Reviewed-on: #64
This commit is contained in:
parent
01b13b4764
commit
077044ec19
65 changed files with 1366 additions and 1457 deletions
|
|
@ -1,11 +1,26 @@
|
|||
import "package:fast_immutable_collections/fast_immutable_collections.dart";
|
||||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
part "account_data.freezed.dart";
|
||||
part "account_data.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class AccountData with _$AccountData {
|
||||
const AccountData._();
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const AccountData({
|
||||
@JsonKey(name: AccountData.invitePermissionConfigKey)
|
||||
final InvitePermissionConfig invitePermissionConfig =
|
||||
const InvitePermissionConfig(),
|
||||
|
||||
@JsonKey(name: AccountData.directKey)
|
||||
final IMap<String, IList<String>> directMessages = const IMap.empty(),
|
||||
|
||||
@JsonKey(
|
||||
name: AccountData.recentEmojiKey,
|
||||
readValue: AccountData.readRecentEmojiValue,
|
||||
toJson: AccountData.recentEmojiToJson,
|
||||
)
|
||||
final IList<RecentEmoji> recentEmoji = const IList.empty(),
|
||||
}) with _$AccountData {
|
||||
static List<dynamic>? readRecentEmojiValue(
|
||||
Map<dynamic, dynamic> json,
|
||||
String key,
|
||||
|
|
@ -19,44 +34,29 @@ abstract class AccountData with _$AccountData {
|
|||
static const directKey = "m.direct";
|
||||
static const recentEmojiKey = "m.recent_emoji";
|
||||
|
||||
const factory AccountData({
|
||||
@JsonKey(name: AccountData.invitePermissionConfigKey)
|
||||
@Default(InvitePermissionConfig())
|
||||
InvitePermissionConfig invitePermissionConfig,
|
||||
|
||||
@JsonKey(name: AccountData.directKey)
|
||||
@Default(IMap.empty())
|
||||
IMap<String, IList<String>> directMessages,
|
||||
|
||||
@JsonKey(
|
||||
name: AccountData.recentEmojiKey,
|
||||
readValue: AccountData.readRecentEmojiValue,
|
||||
toJson: AccountData.recentEmojiToJson,
|
||||
)
|
||||
@Default(IList.empty())
|
||||
IList<RecentEmoji> recentEmoji,
|
||||
}) = _AccountData;
|
||||
Map<String, Object?> toJson() => _$AccountDataToJson(this);
|
||||
|
||||
factory AccountData.fromJson(Map<String, Object?> json) =>
|
||||
_$AccountDataFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class InvitePermissionConfig with _$InvitePermissionConfig {
|
||||
const factory InvitePermissionConfig({
|
||||
@JsonKey(unknownEnumValue: DefaultInviteAction.allow)
|
||||
@Default(DefaultInviteAction.allow)
|
||||
DefaultInviteAction defaultAction,
|
||||
}) = _InvitePermissionConfig;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const InvitePermissionConfig({
|
||||
@JsonKey(unknownEnumValue: DefaultInviteAction.allow)
|
||||
final DefaultInviteAction defaultAction = DefaultInviteAction.allow,
|
||||
}) with _$InvitePermissionConfig {
|
||||
Map<String, Object?> toJson() => _$InvitePermissionConfigToJson(this);
|
||||
|
||||
factory InvitePermissionConfig.fromJson(Map<String, Object?> json) =>
|
||||
_$InvitePermissionConfigFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class RecentEmoji with _$RecentEmoji {
|
||||
const factory RecentEmoji({required String emoji, required int total}) =
|
||||
_RecentEmoji;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const RecentEmoji({required final String emoji, required final int total})
|
||||
with _$RecentEmoji {
|
||||
Map<String, Object?> toJson() => _$RecentEmojiToJson(this);
|
||||
|
||||
factory RecentEmoji.fromJson(Map<String, Object?> json) =>
|
||||
_$RecentEmojiFromJson(json);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
part "client_state.freezed.dart";
|
||||
part "client_state.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class ClientState with _$ClientState {
|
||||
const factory ClientState({
|
||||
required bool isInitialized,
|
||||
required bool isLoggedIn,
|
||||
required bool isVerified,
|
||||
required String? userId,
|
||||
required String? homeserverUrl,
|
||||
}) = _ClientState;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const ClientState({
|
||||
required final bool isInitialized,
|
||||
required final bool isLoggedIn,
|
||||
required final bool isVerified,
|
||||
required final String? userId,
|
||||
required final String? homeserverUrl,
|
||||
}) with _$ClientState {
|
||||
Map<String, Object?> toJson() => _$ClientStateToJson(this);
|
||||
|
||||
factory ClientState.fromJson(Map<String, Object?> json) =>
|
||||
_$ClientStateFromJson(json);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/membership_status.dart";
|
||||
|
||||
part "members_by_status.freezed.dart";
|
||||
part "members_by_status.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class MembersByStatusConfig with _$MembersByStatusConfig {
|
||||
const factory MembersByStatusConfig({
|
||||
required String roomId,
|
||||
required MembershipStatus status,
|
||||
}) = _MembersByStatusConfig;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const MembersByStatusConfig({
|
||||
required final String roomId,
|
||||
required final MembershipStatus status,
|
||||
}) with _$MembersByStatusConfig {
|
||||
Map<String, Object?> toJson() => _$MembersByStatusConfigToJson(this);
|
||||
|
||||
factory MembersByStatusConfig.fromJson(Map<String, Object?> json) =>
|
||||
_$MembersByStatusConfigFromJson(json);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
import "package:nexus/models/content/content.dart";
|
||||
import "package:nexus/models/membership_action.dart";
|
||||
|
||||
part "power_level.freezed.dart";
|
||||
|
||||
@freezed
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
part "reactions.freezed.dart";
|
||||
part "reactions.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class ReactionsConfig with _$ReactionsConfig {
|
||||
const factory ReactionsConfig({
|
||||
required String roomId,
|
||||
required int eventRowId,
|
||||
}) = _ReactionsConfig;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const ReactionsConfig({
|
||||
required final String roomId,
|
||||
required final int eventRowId,
|
||||
}) with _$ReactionsConfig {
|
||||
Map<String, Object?> toJson() => _$ReactionsConfigToJson(this);
|
||||
|
||||
factory ReactionsConfig.fromJson(Map<String, Object?> json) =>
|
||||
_$ReactionsConfigFromJson(json);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import "package:freezed_annotation/freezed_annotation.dart";
|
||||
|
||||
part "user.freezed.dart";
|
||||
part "user.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class UserConfig with _$UserConfig {
|
||||
const factory UserConfig({required String? roomId, required String userId}) =
|
||||
_UserConfig;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const UserConfig({final String? roomId, required final String userId})
|
||||
with _$UserConfig {
|
||||
Map<String, Object?> toJson() => _$UserConfigToJson(this);
|
||||
|
||||
factory UserConfig.fromJson(Map<String, Object?> json) =>
|
||||
_$UserConfigFromJson(json);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "avatar.freezed.dart";
|
|||
part "avatar.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class AvatarContent extends Content with _$AvatarContent {
|
||||
sealed class AvatarContent extends Content with _$AvatarContent {
|
||||
AvatarContent._();
|
||||
factory AvatarContent({ImageInfo? info, Uri? url}) = _AvatarContent;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "canonical_alias.freezed.dart";
|
|||
part "canonical_alias.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class CanonicalAliasContent extends Content
|
||||
sealed class CanonicalAliasContent extends Content
|
||||
with _$CanonicalAliasContent {
|
||||
CanonicalAliasContent._();
|
||||
factory CanonicalAliasContent({
|
||||
|
|
|
|||
|
|
@ -19,9 +19,11 @@ import "package:nexus/models/content/history_visibility.dart";
|
|||
|
||||
class Content {
|
||||
final Error? parseError;
|
||||
Content({this.parseError});
|
||||
|
||||
factory Content.fromJson(Map<String, dynamic> json) => Content();
|
||||
const Content({this.parseError});
|
||||
|
||||
factory Content.fromJson(Map<String, dynamic> json) => const Content();
|
||||
|
||||
Map<String, dynamic> toJson() => {};
|
||||
|
||||
static Map<String, dynamic> readValue(Map<dynamic, dynamic> json, _) =>
|
||||
|
|
@ -34,13 +36,16 @@ class Content {
|
|||
?.contentFromJson ??
|
||||
Content.fromJson)(json);
|
||||
} catch (error) {
|
||||
if (error is Error) return .new(parseError: error);
|
||||
if (error is Error) return Content(parseError: error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum EventType {
|
||||
enum EventType(
|
||||
final String type,
|
||||
final Content Function(Map<String, dynamic> json) contentFromJson,
|
||||
) {
|
||||
encrypted("m.room.encrypted", EncryptedContent.fromJson),
|
||||
redaction("m.room.redaction", RedactionContent.fromJson),
|
||||
encryption("m.room.encryption", EncryptionContent.fromJson),
|
||||
|
|
@ -61,8 +66,4 @@ enum EventType {
|
|||
reaction("m.reaction", ReactionContent.fromJson),
|
||||
pinnedEvents("m.room.pinned_events", PinnedEventsContent.fromJson),
|
||||
message("m.room.message", MessageContent.fromJson);
|
||||
|
||||
final String type;
|
||||
final Content Function(Map<String, dynamic> json) contentFromJson;
|
||||
const EventType(this.type, this.contentFromJson);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "create.freezed.dart";
|
|||
part "create.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class CreateContent extends Content with _$CreateContent {
|
||||
sealed class CreateContent extends Content with _$CreateContent {
|
||||
CreateContent._();
|
||||
factory CreateContent({
|
||||
@JsonKey(name: "additional_creators")
|
||||
|
|
@ -30,9 +30,10 @@ enum RoomType {
|
|||
space,
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class PreviousRoom with _$PreviousRoom {
|
||||
const factory PreviousRoom({required String roomId}) = _PreviousRoom;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const PreviousRoom({required final String roomId}) with _$PreviousRoom {
|
||||
Map<String, Object?> toJson() => _$PreviousRoomToJson(this);
|
||||
|
||||
factory PreviousRoom.fromJson(Map<String, Object?> json) =>
|
||||
_$PreviousRoomFromJson(json);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ part "encrypted.freezed.dart";
|
|||
part "encrypted.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class EncryptedContent extends Content with _$EncryptedContent {
|
||||
sealed class EncryptedContent extends Content with _$EncryptedContent {
|
||||
EncryptedContent._();
|
||||
factory EncryptedContent() = _EncryptedContent;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ part "encryption.freezed.dart";
|
|||
part "encryption.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class EncryptionContent extends Content with _$EncryptionContent {
|
||||
sealed class EncryptionContent extends Content with _$EncryptionContent {
|
||||
EncryptionContent._();
|
||||
factory EncryptionContent({
|
||||
required String algorithm,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ part "history_visibility.freezed.dart";
|
|||
part "history_visibility.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class HistoryVisibilityContent extends Content
|
||||
sealed class HistoryVisibilityContent extends Content
|
||||
with _$HistoryVisibilityContent {
|
||||
HistoryVisibilityContent._();
|
||||
factory HistoryVisibilityContent({
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ part "join_rules.freezed.dart";
|
|||
part "join_rules.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class JoinRulesContent extends Content with _$JoinRulesContent {
|
||||
sealed class JoinRulesContent extends Content with _$JoinRulesContent {
|
||||
JoinRulesContent._();
|
||||
factory JoinRulesContent({
|
||||
required JoinRule joinRule,
|
||||
|
|
@ -17,12 +17,13 @@ abstract class JoinRulesContent extends Content with _$JoinRulesContent {
|
|||
_$JoinRulesContentFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class AllowCondition with _$AllowCondition {
|
||||
const factory AllowCondition({
|
||||
String? roomId,
|
||||
required AllowConditionType type,
|
||||
}) = _AllowCondition;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const AllowCondition({
|
||||
final String? roomId,
|
||||
required final AllowConditionType type,
|
||||
}) with _$AllowCondition {
|
||||
Map<String, Object?> toJson() => _$AllowConditionToJson(this);
|
||||
|
||||
factory AllowCondition.fromJson(Map<String, Object?> json) =>
|
||||
_$AllowConditionFromJson(json);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "membership.freezed.dart";
|
|||
part "membership.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class MembershipContent extends Content with _$MembershipContent {
|
||||
sealed class MembershipContent extends Content with _$MembershipContent {
|
||||
MembershipContent._();
|
||||
|
||||
static String? displaynameFromJson(String? displayName) =>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ part "message.g.dart";
|
|||
typedef EncryptedFile = Map<String, dynamic>;
|
||||
|
||||
@Freezed(unionKey: "msgtype", fallbackUnion: "default")
|
||||
abstract class MessageContent extends Content with _$MessageContent {
|
||||
sealed class MessageContent extends Content with _$MessageContent {
|
||||
MessageContent._();
|
||||
static String? mediaUrlFromJson(Map<dynamic, dynamic> json, String key) =>
|
||||
json[key] ?? json["file"]?[key];
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ part "name.freezed.dart";
|
|||
part "name.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class NameContent extends Content with _$NameContent {
|
||||
sealed class NameContent extends Content with _$NameContent {
|
||||
NameContent._();
|
||||
factory NameContent({required String name}) = _NameContent;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "pinned_events.freezed.dart";
|
|||
part "pinned_events.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class PinnedEventsContent extends Content with _$PinnedEventsContent {
|
||||
sealed class PinnedEventsContent extends Content with _$PinnedEventsContent {
|
||||
PinnedEventsContent._();
|
||||
factory PinnedEventsContent({
|
||||
@Default(IList.empty()) @JsonKey(name: "pinned") IList<String> pinnedEvents,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ part "power_levels.freezed.dart";
|
|||
part "power_levels.g.dart";
|
||||
|
||||
@freezed
|
||||
abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
|
||||
sealed class PowerLevelsContent extends Content with _$PowerLevelsContent {
|
||||
PowerLevelsContent._();
|
||||
factory PowerLevelsContent({
|
||||
@Default(IMap.empty()) IMap<String, int> events,
|
||||
|
|
@ -24,12 +24,13 @@ abstract class PowerLevelsContent extends Content with _$PowerLevelsContent {
|
|||
_$PowerLevelsContentFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class Notifications with _$Notifications {
|
||||
const factory Notifications({
|
||||
@Default(50) int room,
|
||||
@Default(IMapConst({})) IMap<String, int> other,
|
||||
}) = _Notifications;
|
||||
@Freezed(toJson: false, fromJson: false)
|
||||
@JsonSerializable()
|
||||
class const Notifications({
|
||||
final int room = 50,
|
||||
final IMap<String, int> other = const IMap.empty(),
|
||||
}) with _$Notifications {
|
||||
Map<String, Object?> toJson() => _$NotificationsToJson(this);
|
||||
|
||||
factory Notifications.fromJson(Map<String, Object?> json) =>
|
||||
_$NotificationsFromJson(json);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ part "reaction.freezed.dart";
|
|||
part "reaction.g.dart";
|
||||
|
||||
@Freezed(toJson: false)
|
||||
abstract class ReactionContent extends Content with _$ReactionContent {
|
||||
sealed class ReactionContent extends Content with _$ReactionContent {
|
||||
ReactionContent._();
|
||||
static String? keyJsonFromJson(Map<dynamic, dynamic> json, String key) =>
|
||||
json["m.relates_to"]?["key"];
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue