diff --git a/lib/src/service/base_service.dart b/lib/src/service/base_service.dart index 9b92081..2d1624b 100644 --- a/lib/src/service/base_service.dart +++ b/lib/src/service/base_service.dart @@ -285,7 +285,7 @@ abstract class BaseService implements _Service { Response checkResponse( final Response response, - final bool checkUnprocessableEntity, + final bool checkEntity, ) { if (response.statusCode == 401) { throw UnauthorizedException( @@ -298,8 +298,8 @@ abstract class BaseService implements _Service { throw RateLimitExceededException('Rate limit exceeded.', response); } - if (checkUnprocessableEntity) { - if (response.statusCode == 422) { + if (checkEntity) { + if (400 <= response.statusCode && response.statusCode < 500) { throw MastodonException( 'Required parameter is missing or improperly formatted.', response, diff --git a/lib/src/service/entities/featured_tag.dart b/lib/src/service/entities/featured_tag.dart new file mode 100644 index 0000000..ccac9ae --- /dev/null +++ b/lib/src/service/entities/featured_tag.dart @@ -0,0 +1,33 @@ +// Copyright 2022 Kato Shinya. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided the conditions. + +// Package imports: +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'featured_tag.freezed.dart'; +part 'featured_tag.g.dart'; + +@freezed +class FeaturedTag with _$FeaturedTag { + @JsonSerializable(includeIfNull: false) + const factory FeaturedTag({ + /// The internal ID of the featured tag in the database. + required String id, + + /// The name of the hashtag being featured. + required String name, + + /// A link to all statuses by a user that contain this hashtag. + required String url, + + /// The number of authored statuses containing this hashtag. + required int statusesCount, + + /// The timestamp of the last authored status containing this hashtag. + required DateTime lastStatusAt, + }) = _FeaturedTag; + + factory FeaturedTag.fromJson(Map json) => + _$FeaturedTagFromJson(json); +} diff --git a/lib/src/service/entities/featured_tag.freezed.dart b/lib/src/service/entities/featured_tag.freezed.dart new file mode 100644 index 0000000..eaf3346 --- /dev/null +++ b/lib/src/service/entities/featured_tag.freezed.dart @@ -0,0 +1,267 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of 'featured_tag.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +FeaturedTag _$FeaturedTagFromJson(Map json) { + return _FeaturedTag.fromJson(json); +} + +/// @nodoc +mixin _$FeaturedTag { + /// The internal ID of the featured tag in the database. + String get id => throw _privateConstructorUsedError; + + /// The name of the hashtag being featured. + String get name => throw _privateConstructorUsedError; + + /// A link to all statuses by a user that contain this hashtag. + String get url => throw _privateConstructorUsedError; + + /// The number of authored statuses containing this hashtag. + int get statusesCount => throw _privateConstructorUsedError; + + /// The timestamp of the last authored status containing this hashtag. + DateTime get lastStatusAt => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $FeaturedTagCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $FeaturedTagCopyWith<$Res> { + factory $FeaturedTagCopyWith( + FeaturedTag value, $Res Function(FeaturedTag) then) = + _$FeaturedTagCopyWithImpl<$Res, FeaturedTag>; + @useResult + $Res call( + {String id, + String name, + String url, + int statusesCount, + DateTime lastStatusAt}); +} + +/// @nodoc +class _$FeaturedTagCopyWithImpl<$Res, $Val extends FeaturedTag> + implements $FeaturedTagCopyWith<$Res> { + _$FeaturedTagCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? name = null, + Object? url = null, + Object? statusesCount = null, + Object? lastStatusAt = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + statusesCount: null == statusesCount + ? _value.statusesCount + : statusesCount // ignore: cast_nullable_to_non_nullable + as int, + lastStatusAt: null == lastStatusAt + ? _value.lastStatusAt + : lastStatusAt // ignore: cast_nullable_to_non_nullable + as DateTime, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_FeaturedTagCopyWith<$Res> + implements $FeaturedTagCopyWith<$Res> { + factory _$$_FeaturedTagCopyWith( + _$_FeaturedTag value, $Res Function(_$_FeaturedTag) then) = + __$$_FeaturedTagCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String id, + String name, + String url, + int statusesCount, + DateTime lastStatusAt}); +} + +/// @nodoc +class __$$_FeaturedTagCopyWithImpl<$Res> + extends _$FeaturedTagCopyWithImpl<$Res, _$_FeaturedTag> + implements _$$_FeaturedTagCopyWith<$Res> { + __$$_FeaturedTagCopyWithImpl( + _$_FeaturedTag _value, $Res Function(_$_FeaturedTag) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? name = null, + Object? url = null, + Object? statusesCount = null, + Object? lastStatusAt = null, + }) { + return _then(_$_FeaturedTag( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + name: null == name + ? _value.name + : name // ignore: cast_nullable_to_non_nullable + as String, + url: null == url + ? _value.url + : url // ignore: cast_nullable_to_non_nullable + as String, + statusesCount: null == statusesCount + ? _value.statusesCount + : statusesCount // ignore: cast_nullable_to_non_nullable + as int, + lastStatusAt: null == lastStatusAt + ? _value.lastStatusAt + : lastStatusAt // ignore: cast_nullable_to_non_nullable + as DateTime, + )); + } +} + +/// @nodoc + +@JsonSerializable(includeIfNull: false) +class _$_FeaturedTag implements _FeaturedTag { + const _$_FeaturedTag( + {required this.id, + required this.name, + required this.url, + required this.statusesCount, + required this.lastStatusAt}); + + factory _$_FeaturedTag.fromJson(Map json) => + _$$_FeaturedTagFromJson(json); + + /// The internal ID of the featured tag in the database. + @override + final String id; + + /// The name of the hashtag being featured. + @override + final String name; + + /// A link to all statuses by a user that contain this hashtag. + @override + final String url; + + /// The number of authored statuses containing this hashtag. + @override + final int statusesCount; + + /// The timestamp of the last authored status containing this hashtag. + @override + final DateTime lastStatusAt; + + @override + String toString() { + return 'FeaturedTag(id: $id, name: $name, url: $url, statusesCount: $statusesCount, lastStatusAt: $lastStatusAt)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_FeaturedTag && + (identical(other.id, id) || other.id == id) && + (identical(other.name, name) || other.name == name) && + (identical(other.url, url) || other.url == url) && + (identical(other.statusesCount, statusesCount) || + other.statusesCount == statusesCount) && + (identical(other.lastStatusAt, lastStatusAt) || + other.lastStatusAt == lastStatusAt)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => + Object.hash(runtimeType, id, name, url, statusesCount, lastStatusAt); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_FeaturedTagCopyWith<_$_FeaturedTag> get copyWith => + __$$_FeaturedTagCopyWithImpl<_$_FeaturedTag>(this, _$identity); + + @override + Map toJson() { + return _$$_FeaturedTagToJson( + this, + ); + } +} + +abstract class _FeaturedTag implements FeaturedTag { + const factory _FeaturedTag( + {required final String id, + required final String name, + required final String url, + required final int statusesCount, + required final DateTime lastStatusAt}) = _$_FeaturedTag; + + factory _FeaturedTag.fromJson(Map json) = + _$_FeaturedTag.fromJson; + + @override + + /// The internal ID of the featured tag in the database. + String get id; + @override + + /// The name of the hashtag being featured. + String get name; + @override + + /// A link to all statuses by a user that contain this hashtag. + String get url; + @override + + /// The number of authored statuses containing this hashtag. + int get statusesCount; + @override + + /// The timestamp of the last authored status containing this hashtag. + DateTime get lastStatusAt; + @override + @JsonKey(ignore: true) + _$$_FeaturedTagCopyWith<_$_FeaturedTag> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/service/entities/featured_tag.g.dart b/lib/src/service/entities/featured_tag.g.dart new file mode 100644 index 0000000..0dd573f --- /dev/null +++ b/lib/src/service/entities/featured_tag.g.dart @@ -0,0 +1,38 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: non_constant_identifier_names + +part of 'featured_tag.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_FeaturedTag _$$_FeaturedTagFromJson(Map json) => $checkedCreate( + r'_$_FeaturedTag', + json, + ($checkedConvert) { + final val = _$_FeaturedTag( + id: $checkedConvert('id', (v) => v as String), + name: $checkedConvert('name', (v) => v as String), + url: $checkedConvert('url', (v) => v as String), + statusesCount: $checkedConvert('statuses_count', (v) => v as int), + lastStatusAt: $checkedConvert( + 'last_status_at', (v) => DateTime.parse(v as String)), + ); + return val; + }, + fieldKeyMap: const { + 'statusesCount': 'statuses_count', + 'lastStatusAt': 'last_status_at' + }, + ); + +Map _$$_FeaturedTagToJson(_$_FeaturedTag instance) => + { + 'id': instance.id, + 'name': instance.name, + 'url': instance.url, + 'statuses_count': instance.statusesCount, + 'last_status_at': instance.lastStatusAt.toIso8601String(), + }; diff --git a/lib/src/service/entities/list_replies_policy.dart b/lib/src/service/entities/list_replies_policy.dart new file mode 100644 index 0000000..c19fce7 --- /dev/null +++ b/lib/src/service/entities/list_replies_policy.dart @@ -0,0 +1,14 @@ +// Copyright 2022 Kato Shinya. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided the conditions. + +enum ListRepliesPolicy { + /// Show replies to any followed user. + followed, + + /// Show replies to members of the list. + list, + + /// Show replies to no one. + none, +} diff --git a/lib/src/service/entities/relationship.dart b/lib/src/service/entities/relationship.dart new file mode 100644 index 0000000..1574a2b --- /dev/null +++ b/lib/src/service/entities/relationship.dart @@ -0,0 +1,63 @@ +// Copyright 2022 Kato Shinya. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided the conditions. + +// ignore_for_file: invalid_annotation_target + +// Package imports: +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../core/language.dart'; + +part 'relationship.freezed.dart'; +part 'relationship.g.dart'; + +@freezed +class Relationship with _$Relationship { + const factory Relationship({ + /// The account ID. + required String id, + + /// This user’s profile bio + @JsonKey(name: 'note') required String bio, + + /// Are you following this user? + @JsonKey(name: 'following') required bool isFollowing, + + /// Are you followed by this user? + @JsonKey(name: 'followed_by') required bool isFollowed, + + /// Are you receiving this user’s boosts in your home timeline? + @JsonKey(name: 'showing_reblogs') required bool isShowingReblogs, + + /// Have you enabled notifications for this user? + @JsonKey(name: 'notifying') required bool isNotifying, + + /// Are you blocking this user? + @JsonKey(name: 'blocking') required bool isBlocking, + + /// Is this user blocking you? + @JsonKey(name: 'blocked_by') required bool isBlocked, + + /// Are you muting this user? + @JsonKey(name: 'muting') required bool isMuting, + + /// Are you muting notifications from this user? + @JsonKey(name: 'muting_notifications') required bool isMutingNotifications, + + /// Do you have a pending follow request for this user? + @JsonKey(name: 'requested') required bool isRequested, + + /// Are you blocking this user’s domain? + @JsonKey(name: 'domain_blocking') required bool isDomainBlocking, + + /// Are you featuring this user on your profile? + @JsonKey(name: 'endorsed') required bool isEndorsed, + + /// Which languages are you following from this user? + required List languages, + }) = _Relationship; + + factory Relationship.fromJson(Map json) => + _$RelationshipFromJson(json); +} diff --git a/lib/src/service/entities/relationship.freezed.dart b/lib/src/service/entities/relationship.freezed.dart new file mode 100644 index 0000000..e4b3cad --- /dev/null +++ b/lib/src/service/entities/relationship.freezed.dart @@ -0,0 +1,591 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of 'relationship.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +Relationship _$RelationshipFromJson(Map json) { + return _Relationship.fromJson(json); +} + +/// @nodoc +mixin _$Relationship { + /// The account ID. + String get id => throw _privateConstructorUsedError; + + /// This user’s profile bio + @JsonKey(name: 'note') + String get bio => throw _privateConstructorUsedError; + + /// Are you following this user? + @JsonKey(name: 'following') + bool get isFollowing => throw _privateConstructorUsedError; + + /// Are you followed by this user? + @JsonKey(name: 'followed_by') + bool get isFollowed => throw _privateConstructorUsedError; + + /// Are you receiving this user’s boosts in your home timeline? + @JsonKey(name: 'showing_reblogs') + bool get isShowingReblogs => throw _privateConstructorUsedError; + + /// Have you enabled notifications for this user? + @JsonKey(name: 'notifying') + bool get isNotifying => throw _privateConstructorUsedError; + + /// Are you blocking this user? + @JsonKey(name: 'blocking') + bool get isBlocking => throw _privateConstructorUsedError; + + /// Is this user blocking you? + @JsonKey(name: 'blocked_by') + bool get isBlocked => throw _privateConstructorUsedError; + + /// Are you muting this user? + @JsonKey(name: 'muting') + bool get isMuting => throw _privateConstructorUsedError; + + /// Are you muting notifications from this user? + @JsonKey(name: 'muting_notifications') + bool get isMutingNotifications => throw _privateConstructorUsedError; + + /// Do you have a pending follow request for this user? + @JsonKey(name: 'requested') + bool get isRequested => throw _privateConstructorUsedError; + + /// Are you blocking this user’s domain? + @JsonKey(name: 'domain_blocking') + bool get isDomainBlocking => throw _privateConstructorUsedError; + + /// Are you featuring this user on your profile? + @JsonKey(name: 'endorsed') + bool get isEndorsed => throw _privateConstructorUsedError; + + /// Which languages are you following from this user? + List get languages => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $RelationshipCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $RelationshipCopyWith<$Res> { + factory $RelationshipCopyWith( + Relationship value, $Res Function(Relationship) then) = + _$RelationshipCopyWithImpl<$Res, Relationship>; + @useResult + $Res call( + {String id, + @JsonKey(name: 'note') String bio, + @JsonKey(name: 'following') bool isFollowing, + @JsonKey(name: 'followed_by') bool isFollowed, + @JsonKey(name: 'showing_reblogs') bool isShowingReblogs, + @JsonKey(name: 'notifying') bool isNotifying, + @JsonKey(name: 'blocking') bool isBlocking, + @JsonKey(name: 'blocked_by') bool isBlocked, + @JsonKey(name: 'muting') bool isMuting, + @JsonKey(name: 'muting_notifications') bool isMutingNotifications, + @JsonKey(name: 'requested') bool isRequested, + @JsonKey(name: 'domain_blocking') bool isDomainBlocking, + @JsonKey(name: 'endorsed') bool isEndorsed, + List languages}); +} + +/// @nodoc +class _$RelationshipCopyWithImpl<$Res, $Val extends Relationship> + implements $RelationshipCopyWith<$Res> { + _$RelationshipCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? bio = null, + Object? isFollowing = null, + Object? isFollowed = null, + Object? isShowingReblogs = null, + Object? isNotifying = null, + Object? isBlocking = null, + Object? isBlocked = null, + Object? isMuting = null, + Object? isMutingNotifications = null, + Object? isRequested = null, + Object? isDomainBlocking = null, + Object? isEndorsed = null, + Object? languages = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + bio: null == bio + ? _value.bio + : bio // ignore: cast_nullable_to_non_nullable + as String, + isFollowing: null == isFollowing + ? _value.isFollowing + : isFollowing // ignore: cast_nullable_to_non_nullable + as bool, + isFollowed: null == isFollowed + ? _value.isFollowed + : isFollowed // ignore: cast_nullable_to_non_nullable + as bool, + isShowingReblogs: null == isShowingReblogs + ? _value.isShowingReblogs + : isShowingReblogs // ignore: cast_nullable_to_non_nullable + as bool, + isNotifying: null == isNotifying + ? _value.isNotifying + : isNotifying // ignore: cast_nullable_to_non_nullable + as bool, + isBlocking: null == isBlocking + ? _value.isBlocking + : isBlocking // ignore: cast_nullable_to_non_nullable + as bool, + isBlocked: null == isBlocked + ? _value.isBlocked + : isBlocked // ignore: cast_nullable_to_non_nullable + as bool, + isMuting: null == isMuting + ? _value.isMuting + : isMuting // ignore: cast_nullable_to_non_nullable + as bool, + isMutingNotifications: null == isMutingNotifications + ? _value.isMutingNotifications + : isMutingNotifications // ignore: cast_nullable_to_non_nullable + as bool, + isRequested: null == isRequested + ? _value.isRequested + : isRequested // ignore: cast_nullable_to_non_nullable + as bool, + isDomainBlocking: null == isDomainBlocking + ? _value.isDomainBlocking + : isDomainBlocking // ignore: cast_nullable_to_non_nullable + as bool, + isEndorsed: null == isEndorsed + ? _value.isEndorsed + : isEndorsed // ignore: cast_nullable_to_non_nullable + as bool, + languages: null == languages + ? _value.languages + : languages // ignore: cast_nullable_to_non_nullable + as List, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_RelationshipCopyWith<$Res> + implements $RelationshipCopyWith<$Res> { + factory _$$_RelationshipCopyWith( + _$_Relationship value, $Res Function(_$_Relationship) then) = + __$$_RelationshipCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String id, + @JsonKey(name: 'note') String bio, + @JsonKey(name: 'following') bool isFollowing, + @JsonKey(name: 'followed_by') bool isFollowed, + @JsonKey(name: 'showing_reblogs') bool isShowingReblogs, + @JsonKey(name: 'notifying') bool isNotifying, + @JsonKey(name: 'blocking') bool isBlocking, + @JsonKey(name: 'blocked_by') bool isBlocked, + @JsonKey(name: 'muting') bool isMuting, + @JsonKey(name: 'muting_notifications') bool isMutingNotifications, + @JsonKey(name: 'requested') bool isRequested, + @JsonKey(name: 'domain_blocking') bool isDomainBlocking, + @JsonKey(name: 'endorsed') bool isEndorsed, + List languages}); +} + +/// @nodoc +class __$$_RelationshipCopyWithImpl<$Res> + extends _$RelationshipCopyWithImpl<$Res, _$_Relationship> + implements _$$_RelationshipCopyWith<$Res> { + __$$_RelationshipCopyWithImpl( + _$_Relationship _value, $Res Function(_$_Relationship) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? bio = null, + Object? isFollowing = null, + Object? isFollowed = null, + Object? isShowingReblogs = null, + Object? isNotifying = null, + Object? isBlocking = null, + Object? isBlocked = null, + Object? isMuting = null, + Object? isMutingNotifications = null, + Object? isRequested = null, + Object? isDomainBlocking = null, + Object? isEndorsed = null, + Object? languages = null, + }) { + return _then(_$_Relationship( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + bio: null == bio + ? _value.bio + : bio // ignore: cast_nullable_to_non_nullable + as String, + isFollowing: null == isFollowing + ? _value.isFollowing + : isFollowing // ignore: cast_nullable_to_non_nullable + as bool, + isFollowed: null == isFollowed + ? _value.isFollowed + : isFollowed // ignore: cast_nullable_to_non_nullable + as bool, + isShowingReblogs: null == isShowingReblogs + ? _value.isShowingReblogs + : isShowingReblogs // ignore: cast_nullable_to_non_nullable + as bool, + isNotifying: null == isNotifying + ? _value.isNotifying + : isNotifying // ignore: cast_nullable_to_non_nullable + as bool, + isBlocking: null == isBlocking + ? _value.isBlocking + : isBlocking // ignore: cast_nullable_to_non_nullable + as bool, + isBlocked: null == isBlocked + ? _value.isBlocked + : isBlocked // ignore: cast_nullable_to_non_nullable + as bool, + isMuting: null == isMuting + ? _value.isMuting + : isMuting // ignore: cast_nullable_to_non_nullable + as bool, + isMutingNotifications: null == isMutingNotifications + ? _value.isMutingNotifications + : isMutingNotifications // ignore: cast_nullable_to_non_nullable + as bool, + isRequested: null == isRequested + ? _value.isRequested + : isRequested // ignore: cast_nullable_to_non_nullable + as bool, + isDomainBlocking: null == isDomainBlocking + ? _value.isDomainBlocking + : isDomainBlocking // ignore: cast_nullable_to_non_nullable + as bool, + isEndorsed: null == isEndorsed + ? _value.isEndorsed + : isEndorsed // ignore: cast_nullable_to_non_nullable + as bool, + languages: null == languages + ? _value._languages + : languages // ignore: cast_nullable_to_non_nullable + as List, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_Relationship implements _Relationship { + const _$_Relationship( + {required this.id, + @JsonKey(name: 'note') + required this.bio, + @JsonKey(name: 'following') + required this.isFollowing, + @JsonKey(name: 'followed_by') + required this.isFollowed, + @JsonKey(name: 'showing_reblogs') + required this.isShowingReblogs, + @JsonKey(name: 'notifying') + required this.isNotifying, + @JsonKey(name: 'blocking') + required this.isBlocking, + @JsonKey(name: 'blocked_by') + required this.isBlocked, + @JsonKey(name: 'muting') + required this.isMuting, + @JsonKey(name: 'muting_notifications') + required this.isMutingNotifications, + @JsonKey(name: 'requested') + required this.isRequested, + @JsonKey(name: 'domain_blocking') + required this.isDomainBlocking, + @JsonKey(name: 'endorsed') + required this.isEndorsed, + required final List languages}) + : _languages = languages; + + factory _$_Relationship.fromJson(Map json) => + _$$_RelationshipFromJson(json); + + /// The account ID. + @override + final String id; + + /// This user’s profile bio + @override + @JsonKey(name: 'note') + final String bio; + + /// Are you following this user? + @override + @JsonKey(name: 'following') + final bool isFollowing; + + /// Are you followed by this user? + @override + @JsonKey(name: 'followed_by') + final bool isFollowed; + + /// Are you receiving this user’s boosts in your home timeline? + @override + @JsonKey(name: 'showing_reblogs') + final bool isShowingReblogs; + + /// Have you enabled notifications for this user? + @override + @JsonKey(name: 'notifying') + final bool isNotifying; + + /// Are you blocking this user? + @override + @JsonKey(name: 'blocking') + final bool isBlocking; + + /// Is this user blocking you? + @override + @JsonKey(name: 'blocked_by') + final bool isBlocked; + + /// Are you muting this user? + @override + @JsonKey(name: 'muting') + final bool isMuting; + + /// Are you muting notifications from this user? + @override + @JsonKey(name: 'muting_notifications') + final bool isMutingNotifications; + + /// Do you have a pending follow request for this user? + @override + @JsonKey(name: 'requested') + final bool isRequested; + + /// Are you blocking this user’s domain? + @override + @JsonKey(name: 'domain_blocking') + final bool isDomainBlocking; + + /// Are you featuring this user on your profile? + @override + @JsonKey(name: 'endorsed') + final bool isEndorsed; + + /// Which languages are you following from this user? + final List _languages; + + /// Which languages are you following from this user? + @override + List get languages { + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_languages); + } + + @override + String toString() { + return 'Relationship(id: $id, bio: $bio, isFollowing: $isFollowing, isFollowed: $isFollowed, isShowingReblogs: $isShowingReblogs, isNotifying: $isNotifying, isBlocking: $isBlocking, isBlocked: $isBlocked, isMuting: $isMuting, isMutingNotifications: $isMutingNotifications, isRequested: $isRequested, isDomainBlocking: $isDomainBlocking, isEndorsed: $isEndorsed, languages: $languages)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_Relationship && + (identical(other.id, id) || other.id == id) && + (identical(other.bio, bio) || other.bio == bio) && + (identical(other.isFollowing, isFollowing) || + other.isFollowing == isFollowing) && + (identical(other.isFollowed, isFollowed) || + other.isFollowed == isFollowed) && + (identical(other.isShowingReblogs, isShowingReblogs) || + other.isShowingReblogs == isShowingReblogs) && + (identical(other.isNotifying, isNotifying) || + other.isNotifying == isNotifying) && + (identical(other.isBlocking, isBlocking) || + other.isBlocking == isBlocking) && + (identical(other.isBlocked, isBlocked) || + other.isBlocked == isBlocked) && + (identical(other.isMuting, isMuting) || + other.isMuting == isMuting) && + (identical(other.isMutingNotifications, isMutingNotifications) || + other.isMutingNotifications == isMutingNotifications) && + (identical(other.isRequested, isRequested) || + other.isRequested == isRequested) && + (identical(other.isDomainBlocking, isDomainBlocking) || + other.isDomainBlocking == isDomainBlocking) && + (identical(other.isEndorsed, isEndorsed) || + other.isEndorsed == isEndorsed) && + const DeepCollectionEquality() + .equals(other._languages, _languages)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash( + runtimeType, + id, + bio, + isFollowing, + isFollowed, + isShowingReblogs, + isNotifying, + isBlocking, + isBlocked, + isMuting, + isMutingNotifications, + isRequested, + isDomainBlocking, + isEndorsed, + const DeepCollectionEquality().hash(_languages)); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_RelationshipCopyWith<_$_Relationship> get copyWith => + __$$_RelationshipCopyWithImpl<_$_Relationship>(this, _$identity); + + @override + Map toJson() { + return _$$_RelationshipToJson( + this, + ); + } +} + +abstract class _Relationship implements Relationship { + const factory _Relationship( + {required final String id, + @JsonKey(name: 'note') + required final String bio, + @JsonKey(name: 'following') + required final bool isFollowing, + @JsonKey(name: 'followed_by') + required final bool isFollowed, + @JsonKey(name: 'showing_reblogs') + required final bool isShowingReblogs, + @JsonKey(name: 'notifying') + required final bool isNotifying, + @JsonKey(name: 'blocking') + required final bool isBlocking, + @JsonKey(name: 'blocked_by') + required final bool isBlocked, + @JsonKey(name: 'muting') + required final bool isMuting, + @JsonKey(name: 'muting_notifications') + required final bool isMutingNotifications, + @JsonKey(name: 'requested') + required final bool isRequested, + @JsonKey(name: 'domain_blocking') + required final bool isDomainBlocking, + @JsonKey(name: 'endorsed') + required final bool isEndorsed, + required final List languages}) = _$_Relationship; + + factory _Relationship.fromJson(Map json) = + _$_Relationship.fromJson; + + @override + + /// The account ID. + String get id; + @override + + /// This user’s profile bio + @JsonKey(name: 'note') + String get bio; + @override + + /// Are you following this user? + @JsonKey(name: 'following') + bool get isFollowing; + @override + + /// Are you followed by this user? + @JsonKey(name: 'followed_by') + bool get isFollowed; + @override + + /// Are you receiving this user’s boosts in your home timeline? + @JsonKey(name: 'showing_reblogs') + bool get isShowingReblogs; + @override + + /// Have you enabled notifications for this user? + @JsonKey(name: 'notifying') + bool get isNotifying; + @override + + /// Are you blocking this user? + @JsonKey(name: 'blocking') + bool get isBlocking; + @override + + /// Is this user blocking you? + @JsonKey(name: 'blocked_by') + bool get isBlocked; + @override + + /// Are you muting this user? + @JsonKey(name: 'muting') + bool get isMuting; + @override + + /// Are you muting notifications from this user? + @JsonKey(name: 'muting_notifications') + bool get isMutingNotifications; + @override + + /// Do you have a pending follow request for this user? + @JsonKey(name: 'requested') + bool get isRequested; + @override + + /// Are you blocking this user’s domain? + @JsonKey(name: 'domain_blocking') + bool get isDomainBlocking; + @override + + /// Are you featuring this user on your profile? + @JsonKey(name: 'endorsed') + bool get isEndorsed; + @override + + /// Which languages are you following from this user? + List get languages; + @override + @JsonKey(ignore: true) + _$$_RelationshipCopyWith<_$_Relationship> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/service/entities/relationship.g.dart b/lib/src/service/entities/relationship.g.dart new file mode 100644 index 0000000..6c40315 --- /dev/null +++ b/lib/src/service/entities/relationship.g.dart @@ -0,0 +1,259 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: non_constant_identifier_names + +part of 'relationship.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_Relationship _$$_RelationshipFromJson(Map json) => $checkedCreate( + r'_$_Relationship', + json, + ($checkedConvert) { + final val = _$_Relationship( + id: $checkedConvert('id', (v) => v as String), + bio: $checkedConvert('note', (v) => v as String), + isFollowing: $checkedConvert('following', (v) => v as bool), + isFollowed: $checkedConvert('followed_by', (v) => v as bool), + isShowingReblogs: + $checkedConvert('showing_reblogs', (v) => v as bool), + isNotifying: $checkedConvert('notifying', (v) => v as bool), + isBlocking: $checkedConvert('blocking', (v) => v as bool), + isBlocked: $checkedConvert('blocked_by', (v) => v as bool), + isMuting: $checkedConvert('muting', (v) => v as bool), + isMutingNotifications: + $checkedConvert('muting_notifications', (v) => v as bool), + isRequested: $checkedConvert('requested', (v) => v as bool), + isDomainBlocking: + $checkedConvert('domain_blocking', (v) => v as bool), + isEndorsed: $checkedConvert('endorsed', (v) => v as bool), + languages: $checkedConvert( + 'languages', + (v) => (v as List) + .map((e) => $enumDecode(_$LanguageEnumMap, e)) + .toList()), + ); + return val; + }, + fieldKeyMap: const { + 'bio': 'note', + 'isFollowing': 'following', + 'isFollowed': 'followed_by', + 'isShowingReblogs': 'showing_reblogs', + 'isNotifying': 'notifying', + 'isBlocking': 'blocking', + 'isBlocked': 'blocked_by', + 'isMuting': 'muting', + 'isMutingNotifications': 'muting_notifications', + 'isRequested': 'requested', + 'isDomainBlocking': 'domain_blocking', + 'isEndorsed': 'endorsed' + }, + ); + +Map _$$_RelationshipToJson(_$_Relationship instance) => + { + 'id': instance.id, + 'note': instance.bio, + 'following': instance.isFollowing, + 'followed_by': instance.isFollowed, + 'showing_reblogs': instance.isShowingReblogs, + 'notifying': instance.isNotifying, + 'blocking': instance.isBlocking, + 'blocked_by': instance.isBlocked, + 'muting': instance.isMuting, + 'muting_notifications': instance.isMutingNotifications, + 'requested': instance.isRequested, + 'domain_blocking': instance.isDomainBlocking, + 'endorsed': instance.isEndorsed, + 'languages': + instance.languages.map((e) => _$LanguageEnumMap[e]!).toList(), + }; + +const _$LanguageEnumMap = { + Language.afar: 'aa', + Language.abkhaz: 'ab', + Language.avestan: 'ae', + Language.afrikaans: 'af', + Language.akan: 'ak', + Language.amharic: 'am', + Language.aragonese: 'an', + Language.arabic: 'ar', + Language.assamese: 'as', + Language.avaric: 'av', + Language.aymara: 'ay', + Language.azerbaijani: 'az', + Language.bashkir: 'ba', + Language.belarusian: 'be', + Language.bulgarian: 'bg', + Language.bihari: 'bh', + Language.bislama: 'bi', + Language.bambara: 'bm', + Language.bengali: 'bn', + Language.tibetan: 'bo', + Language.breton: 'br', + Language.bosnian: 'bs', + Language.catalan: 'ca', + Language.chechen: 'ce', + Language.chamorro: 'ch', + Language.corsican: 'co', + Language.cree: 'cr', + Language.czech: 'cs', + Language.oldChurchSlavonic: 'cu', + Language.chuvash: 'cv', + Language.welsh: 'cy', + Language.danish: 'da', + Language.german: 'de', + Language.divehi: 'dv', + Language.dzongkha: 'dz', + Language.ewe: 'ee', + Language.greek: 'el', + Language.english: 'en', + Language.americanEnglish: 'en-us', + Language.esperanto: 'eo', + Language.spanish: 'es', + Language.estonian: 'et', + Language.basque: 'eu', + Language.persian: 'fa', + Language.fula: 'ff', + Language.finnish: 'fi', + Language.fijian: 'fj', + Language.faroese: 'fo', + Language.french: 'fr', + Language.westernFrisian: 'fy', + Language.irish: 'ga', + Language.scottishGaelic: 'gd', + Language.galician: 'gl', + Language.gujarati: 'gu', + Language.manx: 'gv', + Language.hausa: 'ha', + Language.hebrew: 'he', + Language.hindi: 'hi', + Language.hiriMotu: 'ho', + Language.croatian: 'hr', + Language.haitian: 'ht', + Language.hungarian: 'hu', + Language.armenian: 'hy', + Language.herero: 'hz', + Language.interlingua: 'ia', + Language.indonesian: 'id', + Language.interlingue: 'ie', + Language.igbo: 'ig', + Language.nuosu: 'ii', + Language.inupiaq: 'ik', + Language.ido: 'io', + Language.icelandic: 'is_', + Language.italian: 'it', + Language.inuktitut: 'iu', + Language.japanese: 'ja', + Language.javanese: 'jv', + Language.georgian: 'ka', + Language.kongo: 'kg', + Language.kikuyu: 'ki', + Language.kwanyama: 'kj', + Language.kazakh: 'kk', + Language.kalaallisut: 'kl', + Language.khmer: 'km', + Language.kannada: 'kn', + Language.korean: 'ko', + Language.kanuri: 'kr', + Language.kashmiri: 'ks', + Language.kurmanji: 'ku', + Language.komi: 'kv', + Language.cornish: 'kw', + Language.kyrgyz: 'ky', + Language.latin: 'la', + Language.luxembourgish: 'lb', + Language.ganda: 'lg', + Language.limburgish: 'li', + Language.lingala: 'ln', + Language.lao: 'lo', + Language.lithuanian: 'lt', + Language.lubaKatanga: 'lu', + Language.latvian: 'lv', + Language.malagasy: 'mg', + Language.marshallese: 'mh', + Language.maori: 'mi', + Language.macedonian: 'mk', + Language.malayalam: 'ml', + Language.mongolian: 'mn', + Language.marathi: 'mr', + Language.malay: 'ms', + Language.maltese: 'mt', + Language.burmese: 'my', + Language.nauru: 'na', + Language.norwegianBokmal: 'nb', + Language.northernNdebele: 'nd', + Language.nepali: 'ne', + Language.ndonga: 'ng', + Language.dutch: 'nl', + Language.norwegianNynorsk: 'nn', + Language.norwegian: 'no', + Language.southernNdebele: 'nr', + Language.navajo: 'nv', + Language.chichewa: 'ny', + Language.occitan: 'oc', + Language.ojibwe: 'oj', + Language.oromo: 'om', + Language.oriya: 'or', + Language.ossetian: 'os', + Language.panjabi: 'pa', + Language.pali: 'pi', + Language.polish: 'pl', + Language.pashto: 'ps', + Language.portuguese: 'pt', + Language.quechua: 'qu', + Language.romansh: 'rm', + Language.kirundi: 'rn', + Language.romanian: 'ro', + Language.russian: 'ru', + Language.kinyarwanda: 'rw', + Language.sanskrit: 'sa', + Language.sardinian: 'sc', + Language.sindhi: 'sd', + Language.northernSami: 'se', + Language.sango: 'sg', + Language.sinhala: 'si', + Language.slovak: 'sk', + Language.slovenian: 'sl', + Language.shona: 'sn', + Language.somali: 'so', + Language.albanian: 'sq', + Language.serbian: 'sr', + Language.swati: 'ss', + Language.southernSotho: 'st', + Language.sundanese: 'su', + Language.swedish: 'sv', + Language.swahili: 'sw', + Language.tamil: 'ta', + Language.telugu: 'te', + Language.tajik: 'tg', + Language.thai: 'th', + Language.tigrinya: 'ti', + Language.turkmen: 'tk', + Language.tagalog: 'tl', + Language.tswana: 'tn', + Language.tonga: 'to', + Language.turkish: 'tr', + Language.tsonga: 'ts', + Language.tatar: 'tt', + Language.twi: 'tw', + Language.tahitian: 'ty', + Language.uyghur: 'ug', + Language.ukrainian: 'uk', + Language.urdu: 'ur', + Language.uzbek: 'uz', + Language.venda: 've', + Language.vietnamese: 'vi', + Language.volapuk: 'vo', + Language.walloon: 'wa', + Language.wolof: 'wo', + Language.xhosa: 'xh', + Language.yiddish: 'yi', + Language.yoruba: 'yo', + Language.zhuang: 'za', + Language.chinese: 'zh', + Language.zulu: 'zu', +}; diff --git a/lib/src/service/entities/user_list.dart b/lib/src/service/entities/user_list.dart new file mode 100644 index 0000000..0eb58b0 --- /dev/null +++ b/lib/src/service/entities/user_list.dart @@ -0,0 +1,30 @@ +// Copyright 2022 Kato Shinya. All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided the conditions. + +// ignore_for_file: invalid_annotation_target + +// Package imports: +import 'package:freezed_annotation/freezed_annotation.dart'; + +import 'list_replies_policy.dart'; + +part 'user_list.freezed.dart'; +part 'user_list.g.dart'; + +@freezed +class UserList with _$UserList { + const factory UserList({ + /// The internal database ID of the list. + required String id, + + /// The user-defined title of the list. + required String title, + + /// Which replies should be shown in the list. + required ListRepliesPolicy repliesPolicy, + }) = _UserList; + + factory UserList.fromJson(Map json) => + _$UserListFromJson(json); +} diff --git a/lib/src/service/entities/user_list.freezed.dart b/lib/src/service/entities/user_list.freezed.dart new file mode 100644 index 0000000..0185a54 --- /dev/null +++ b/lib/src/service/entities/user_list.freezed.dart @@ -0,0 +1,201 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target + +part of 'user_list.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +UserList _$UserListFromJson(Map json) { + return _UserList.fromJson(json); +} + +/// @nodoc +mixin _$UserList { + /// The internal database ID of the list. + String get id => throw _privateConstructorUsedError; + + /// The user-defined title of the list. + String get title => throw _privateConstructorUsedError; + + /// Which replies should be shown in the list. + ListRepliesPolicy get repliesPolicy => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $UserListCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $UserListCopyWith<$Res> { + factory $UserListCopyWith(UserList value, $Res Function(UserList) then) = + _$UserListCopyWithImpl<$Res, UserList>; + @useResult + $Res call({String id, String title, ListRepliesPolicy repliesPolicy}); +} + +/// @nodoc +class _$UserListCopyWithImpl<$Res, $Val extends UserList> + implements $UserListCopyWith<$Res> { + _$UserListCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? title = null, + Object? repliesPolicy = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + title: null == title + ? _value.title + : title // ignore: cast_nullable_to_non_nullable + as String, + repliesPolicy: null == repliesPolicy + ? _value.repliesPolicy + : repliesPolicy // ignore: cast_nullable_to_non_nullable + as ListRepliesPolicy, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_UserListCopyWith<$Res> implements $UserListCopyWith<$Res> { + factory _$$_UserListCopyWith( + _$_UserList value, $Res Function(_$_UserList) then) = + __$$_UserListCopyWithImpl<$Res>; + @override + @useResult + $Res call({String id, String title, ListRepliesPolicy repliesPolicy}); +} + +/// @nodoc +class __$$_UserListCopyWithImpl<$Res> + extends _$UserListCopyWithImpl<$Res, _$_UserList> + implements _$$_UserListCopyWith<$Res> { + __$$_UserListCopyWithImpl( + _$_UserList _value, $Res Function(_$_UserList) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? title = null, + Object? repliesPolicy = null, + }) { + return _then(_$_UserList( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + title: null == title + ? _value.title + : title // ignore: cast_nullable_to_non_nullable + as String, + repliesPolicy: null == repliesPolicy + ? _value.repliesPolicy + : repliesPolicy // ignore: cast_nullable_to_non_nullable + as ListRepliesPolicy, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_UserList implements _UserList { + const _$_UserList( + {required this.id, required this.title, required this.repliesPolicy}); + + factory _$_UserList.fromJson(Map json) => + _$$_UserListFromJson(json); + + /// The internal database ID of the list. + @override + final String id; + + /// The user-defined title of the list. + @override + final String title; + + /// Which replies should be shown in the list. + @override + final ListRepliesPolicy repliesPolicy; + + @override + String toString() { + return 'UserList(id: $id, title: $title, repliesPolicy: $repliesPolicy)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_UserList && + (identical(other.id, id) || other.id == id) && + (identical(other.title, title) || other.title == title) && + (identical(other.repliesPolicy, repliesPolicy) || + other.repliesPolicy == repliesPolicy)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, id, title, repliesPolicy); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_UserListCopyWith<_$_UserList> get copyWith => + __$$_UserListCopyWithImpl<_$_UserList>(this, _$identity); + + @override + Map toJson() { + return _$$_UserListToJson( + this, + ); + } +} + +abstract class _UserList implements UserList { + const factory _UserList( + {required final String id, + required final String title, + required final ListRepliesPolicy repliesPolicy}) = _$_UserList; + + factory _UserList.fromJson(Map json) = _$_UserList.fromJson; + + @override + + /// The internal database ID of the list. + String get id; + @override + + /// The user-defined title of the list. + String get title; + @override + + /// Which replies should be shown in the list. + ListRepliesPolicy get repliesPolicy; + @override + @JsonKey(ignore: true) + _$$_UserListCopyWith<_$_UserList> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/lib/src/service/entities/user_list.g.dart b/lib/src/service/entities/user_list.g.dart new file mode 100644 index 0000000..6fa3f25 --- /dev/null +++ b/lib/src/service/entities/user_list.g.dart @@ -0,0 +1,37 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +// ignore_for_file: non_constant_identifier_names + +part of 'user_list.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_UserList _$$_UserListFromJson(Map json) => $checkedCreate( + r'_$_UserList', + json, + ($checkedConvert) { + final val = _$_UserList( + id: $checkedConvert('id', (v) => v as String), + title: $checkedConvert('title', (v) => v as String), + repliesPolicy: $checkedConvert('replies_policy', + (v) => $enumDecode(_$ListRepliesPolicyEnumMap, v)), + ); + return val; + }, + fieldKeyMap: const {'repliesPolicy': 'replies_policy'}, + ); + +Map _$$_UserListToJson(_$_UserList instance) => + { + 'id': instance.id, + 'title': instance.title, + 'replies_policy': _$ListRepliesPolicyEnumMap[instance.repliesPolicy]!, + }; + +const _$ListRepliesPolicyEnumMap = { + ListRepliesPolicy.followed: 'followed', + ListRepliesPolicy.list: 'list', + ListRepliesPolicy.none: 'none', +}; diff --git a/lib/src/service/v1/accounts/accounts_v1_service.dart b/lib/src/service/v1/accounts/accounts_v1_service.dart index 8000468..e426b5e 100644 --- a/lib/src/service/v1/accounts/accounts_v1_service.dart +++ b/lib/src/service/v1/accounts/accounts_v1_service.dart @@ -9,10 +9,14 @@ import 'package:http/http.dart'; import '../../../core/client/client_context.dart'; import '../../../core/client/user_context.dart'; +import '../../../core/language.dart'; import '../../base_service.dart'; import '../../entities/account.dart'; +import '../../entities/featured_tag.dart'; +import '../../entities/relationship.dart'; import '../../entities/status.dart'; import '../../entities/token.dart'; +import '../../entities/user_list.dart'; import '../../response/mastodon_response.dart'; import 'account_default_settings_param.dart'; import 'account_profile_meta_param.dart'; @@ -97,7 +101,7 @@ abstract class AccountsV1Service { /// /// - https://docs.joinmastodon.org/methods/accounts/#verify_credentials Future> verifyAccountCredentials({ - required String bearerToken, + String? bearerToken, }); /// Update the user’s display and preferences. @@ -265,6 +269,149 @@ abstract class AccountsV1Service { int? limit, bool? excludeReblogs, }); + + /// Accounts which follow the given account, if network is not hidden by the + /// account owner. + /// + /// ## Parameters + /// + /// - [accountId]: The ID of the Account in the database. + /// + /// - [limit]: Maximum number of results to return. Defaults to 40. + /// + /// ## Endpoint Url + /// + /// - GET https://mastodon.example/api/v1/accounts/:id/followers HTTP/1.1 + /// + /// ## Authentication Methods + /// + /// - OAuth 2.0 + /// + /// ## Required Scopes + /// + /// - read:accounts + /// + /// ## Reference + /// + /// - https://docs.joinmastodon.org/methods/accounts/#followers + Future>> lookupFollowers({ + required String accountId, + int? limit, + }); + + /// Accounts which follow the given account, if network is not hidden by the + /// account owner. + /// + /// ## Parameters + /// + /// - [accountId]: The ID of the Account in the database. + /// + /// - [limit]: Maximum number of results to return. Defaults to 40. + /// + /// ## Endpoint Url + /// + /// - GET https://mastodon.example/api/v1/accounts/:id/following HTTP/1.1 + /// + /// ## Authentication Methods + /// + /// - OAuth 2.0 + /// + /// ## Required Scopes + /// + /// - read:accounts + /// + /// ## Reference + /// + /// - https://docs.joinmastodon.org/methods/accounts/#following + Future>> lookupFollowings({ + required String accountId, + int? limit, + }); + + /// Tags featured by this account. + /// + /// ## Parameters + /// + /// - [accountId]: The ID of the Account in the database. + /// + /// ## Endpoint Url + /// + /// - GET https://mastodon.example/api/v1/accounts/:id/featured_tags HTTP/1.1 + /// + /// ## Authentication Methods + /// + /// - Anonymous + /// + /// ## Reference + /// + /// - https://docs.joinmastodon.org/methods/accounts/#featured_tags + Future>> lookupFeaturedTags({ + required String accountId, + }); + + /// User lists that you have added this account to. + /// + /// ## Parameters + /// + /// - [accountId]: The ID of the Account in the database. + /// + /// ## Endpoint Url + /// + /// - GET https://mastodon.example/api/v1/accounts/:id/lists HTTP/1.1 + /// + /// ## Authentication Methods + /// + /// - OAuth 2.0 + /// + /// ## Required Scopes + /// + /// - read:lists + /// + /// ## Reference + /// + /// - https://docs.joinmastodon.org/methods/accounts/#lists + Future>> lookupContainedLists({ + required String accountId, + }); + + /// Follow the given account. Can also be used to update whether to show + /// reblogs or enable notifications. + /// + /// ## Parameters + /// + /// - [accountId]: The ID of the Account in the database. + /// + /// - [receiveReblogs]: Receive this account’s reblogs in home timeline? + /// Defaults to true. + /// + /// - [receiveNotifications]: Receive notifications when this account posts + /// a status? Defaults to false. + /// + /// - [filteringLanguages]: Filter received statuses for these languages. + /// If not provided, you will receive this account’s + /// posts in all languages. + /// + /// ## Endpoint Url + /// + /// - POST https://mastodon.example/api/v1/accounts/:id/follow HTTP/1.1 + /// + /// ## Authentication Methods + /// + /// - OAuth 2.0 + /// + /// ## Required Scopes + /// + /// - read:lists + /// + /// ## Reference + /// + /// - https://docs.joinmastodon.org/methods/accounts/#follow + Future> createFollow({ + required String accountId, + bool? receiveReblogs, + bool? receiveNotifications, + List? filteringLanguages, + }); } class _AccountsV1Service extends BaseService implements AccountsV1Service { @@ -302,14 +449,14 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service { @override Future> verifyAccountCredentials({ - required String bearerToken, + String? bearerToken, }) async => super.transformSingleDataResponse( await super.get( UserContext.oauth2Only, '/api/v1/accounts/verify_credentials', headers: { - 'Authorization': 'Bearer $bearerToken', + if (bearerToken != null) 'Authorization': 'Bearer $bearerToken', }, ), dataBuilder: Account.fromJson, @@ -428,4 +575,81 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service { ), dataBuilder: Status.fromJson, ); + + @override + Future>> lookupFollowers({ + required String accountId, + int? limit, + }) async => + super.transformMultiDataResponse( + await super.get( + UserContext.oauth2Only, + '/api/v1/accounts/$accountId/followers', + queryParameters: { + 'limit': limit, + }, + ), + dataBuilder: Account.fromJson, + ); + + @override + Future>> lookupFollowings({ + required Object accountId, + int? limit, + }) async => + super.transformMultiDataResponse( + await super.get( + UserContext.oauth2Only, + '/api/v1/accounts/$accountId/following', + queryParameters: { + 'limit': limit, + }, + ), + dataBuilder: Account.fromJson, + ); + + @override + Future>> lookupFeaturedTags({ + required String accountId, + }) async => + super.transformMultiDataResponse( + await super.get( + UserContext.anonymousOnly, + '/api/v1/accounts/$accountId/featured_tags', + ), + dataBuilder: FeaturedTag.fromJson, + ); + + @override + Future>> lookupContainedLists({ + required String accountId, + }) async => + super.transformMultiDataResponse( + await super.get( + UserContext.oauth2Only, + '/api/v1/accounts/$accountId/lists', + ), + dataBuilder: UserList.fromJson, + ); + + @override + Future> createFollow({ + required String accountId, + bool? receiveReblogs, + bool? receiveNotifications, + List? filteringLanguages, + }) async => + super.transformSingleDataResponse( + await super.post( + UserContext.oauth2Only, + '/api/v1/accounts/$accountId/follow', + body: { + 'reblogs': receiveReblogs, + 'notify': receiveNotifications, + 'languages': filteringLanguages?.map((e) => e.value).toList(), + }, + checkUnprocessableEntity: true, + ), + dataBuilder: Relationship.fromJson, + ); }