Skip to content

Commit

Permalink
Merge #81
Browse files Browse the repository at this point in the history
81: fix: fixed for the issue (#18) r=myConsciousness a=myConsciousness

# 1. Description

<!-- Provide a description of what this PR is doing.
If you're modifying existing behavior, describe the existing behavior, how this PR is changing it,
and what motivated the change. If this is a breaking change, specify explicitly which APIs have been
changed. -->

## 1.1. Checklist

<!-- Before you create this PR confirm that it meets all requirements listed below by checking the
relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. -->

- [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc).
- [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs.
- [x] I have updated/added tests for ALL new/updated/fixed functionality.
- [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`.
- [x] I have updated/added relevant examples in `examples`.

## 1.2. Breaking Change

<!-- Does your PR require users to manually update their apps to accommodate your change?

If the PR is a breaking change this should be indicated with suffix "!"  (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details.
-->

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

## 1.3. Related Issues

<!-- Provide a list of issues related to this PR from the [issue database].
Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !-->

<!-- Links -->

[issue database]: https://github.com/mastodon-dart/mastodon-api/issues
[contributor guide]: https://github.com/mastodon-dart/mastodon-api/blob/main/CONTRIBUTING.md
[style guide]: https://github.com/mastodon-dart/mastodon-api/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <contact@shinyakato.dev>
Co-authored-by: Shinya Kato / 加藤 真也 <kato.shinya.dev@gmail.com>
  • Loading branch information
3 people committed Dec 26, 2022
2 parents c874e88 + 1f2eaa5 commit e585f30
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

- Supported `preferences API methods`. ([#19](https://github.com/mastodon-dart/mastodon-api/issues/19))
- `GET /api/v1/preferences`
- Fixed ([#78](https://github.com/mastodon-dart/mastodon-api/issues/78)).
- Supported `featured_tags API methods`. ([#18](https://github.com/mastodon-dart/mastodon-api/issues/18))
- `GET /api/v1/featured_tags`
- `POST /api/v1/featured_tags`
- `DELETE /api/v1/featured_tags/:id`
- `GET /api/v1/featured_tags/suggestions`

## v0.2.1

Expand Down
6 changes: 4 additions & 2 deletions lib/src/service/entities/featured_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// 📦 Package imports:
import 'package:freezed_annotation/freezed_annotation.dart';

import '../../core/convert/int_converter.dart';

part 'featured_tag.freezed.dart';
part 'featured_tag.g.dart';

Expand All @@ -24,10 +26,10 @@ class FeaturedTag with _$FeaturedTag {
String? url,

/// The number of authored statuses containing this hashtag.
required int statusesCount,
@IntConverter() int? statusesCount,

/// The timestamp of the last authored status containing this hashtag.
required DateTime lastStatusAt,
DateTime? lastStatusAt,
}) = _FeaturedTag;

factory FeaturedTag.fromJson(Map<String, Object?> json) =>
Expand Down
55 changes: 29 additions & 26 deletions lib/src/service/entities/featured_tag.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ mixin _$FeaturedTag {
String? get url => throw _privateConstructorUsedError;

/// The number of authored statuses containing this hashtag.
int get statusesCount => throw _privateConstructorUsedError;
@IntConverter()
int? get statusesCount => throw _privateConstructorUsedError;

/// The timestamp of the last authored status containing this hashtag.
DateTime get lastStatusAt => throw _privateConstructorUsedError;
DateTime? get lastStatusAt => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -51,8 +52,8 @@ abstract class $FeaturedTagCopyWith<$Res> {
{String id,
String name,
String? url,
int statusesCount,
DateTime lastStatusAt});
@IntConverter() int? statusesCount,
DateTime? lastStatusAt});
}

/// @nodoc
Expand All @@ -71,8 +72,8 @@ class _$FeaturedTagCopyWithImpl<$Res, $Val extends FeaturedTag>
Object? id = null,
Object? name = null,
Object? url = freezed,
Object? statusesCount = null,
Object? lastStatusAt = null,
Object? statusesCount = freezed,
Object? lastStatusAt = freezed,
}) {
return _then(_value.copyWith(
id: null == id
Expand All @@ -87,14 +88,14 @@ class _$FeaturedTagCopyWithImpl<$Res, $Val extends FeaturedTag>
? _value.url
: url // ignore: cast_nullable_to_non_nullable
as String?,
statusesCount: null == statusesCount
statusesCount: freezed == statusesCount
? _value.statusesCount
: statusesCount // ignore: cast_nullable_to_non_nullable
as int,
lastStatusAt: null == lastStatusAt
as int?,
lastStatusAt: freezed == lastStatusAt
? _value.lastStatusAt
: lastStatusAt // ignore: cast_nullable_to_non_nullable
as DateTime,
as DateTime?,
) as $Val);
}
}
Expand All @@ -111,8 +112,8 @@ abstract class _$$_FeaturedTagCopyWith<$Res>
{String id,
String name,
String? url,
int statusesCount,
DateTime lastStatusAt});
@IntConverter() int? statusesCount,
DateTime? lastStatusAt});
}

/// @nodoc
Expand All @@ -129,8 +130,8 @@ class __$$_FeaturedTagCopyWithImpl<$Res>
Object? id = null,
Object? name = null,
Object? url = freezed,
Object? statusesCount = null,
Object? lastStatusAt = null,
Object? statusesCount = freezed,
Object? lastStatusAt = freezed,
}) {
return _then(_$_FeaturedTag(
id: null == id
Expand All @@ -145,14 +146,14 @@ class __$$_FeaturedTagCopyWithImpl<$Res>
? _value.url
: url // ignore: cast_nullable_to_non_nullable
as String?,
statusesCount: null == statusesCount
statusesCount: freezed == statusesCount
? _value.statusesCount
: statusesCount // ignore: cast_nullable_to_non_nullable
as int,
lastStatusAt: null == lastStatusAt
as int?,
lastStatusAt: freezed == lastStatusAt
? _value.lastStatusAt
: lastStatusAt // ignore: cast_nullable_to_non_nullable
as DateTime,
as DateTime?,
));
}
}
Expand All @@ -165,8 +166,8 @@ class _$_FeaturedTag implements _FeaturedTag {
{required this.id,
required this.name,
this.url,
required this.statusesCount,
required this.lastStatusAt});
@IntConverter() this.statusesCount,
this.lastStatusAt});

factory _$_FeaturedTag.fromJson(Map<String, dynamic> json) =>
_$$_FeaturedTagFromJson(json);
Expand All @@ -185,11 +186,12 @@ class _$_FeaturedTag implements _FeaturedTag {

/// The number of authored statuses containing this hashtag.
@override
final int statusesCount;
@IntConverter()
final int? statusesCount;

/// The timestamp of the last authored status containing this hashtag.
@override
final DateTime lastStatusAt;
final DateTime? lastStatusAt;

@override
String toString() {
Expand Down Expand Up @@ -234,8 +236,8 @@ abstract class _FeaturedTag implements FeaturedTag {
{required final String id,
required final String name,
final String? url,
required final int statusesCount,
required final DateTime lastStatusAt}) = _$_FeaturedTag;
@IntConverter() final int? statusesCount,
final DateTime? lastStatusAt}) = _$_FeaturedTag;

factory _FeaturedTag.fromJson(Map<String, dynamic> json) =
_$_FeaturedTag.fromJson;
Expand All @@ -255,11 +257,12 @@ abstract class _FeaturedTag implements FeaturedTag {
@override

/// The number of authored statuses containing this hashtag.
int get statusesCount;
@IntConverter()
int? get statusesCount;
@override

/// The timestamp of the last authored status containing this hashtag.
DateTime get lastStatusAt;
DateTime? get lastStatusAt;
@override
@JsonKey(ignore: true)
_$$_FeaturedTagCopyWith<_$_FeaturedTag> get copyWith =>
Expand Down
28 changes: 23 additions & 5 deletions lib/src/service/entities/featured_tag.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

136 changes: 136 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import '../../entities/familiar_follower.dart';
import '../../entities/featured_tag.dart';
import '../../entities/relationship.dart';
import '../../entities/status.dart';
import '../../entities/tag.dart';
import '../../entities/token.dart';
import '../../entities/user_list.dart';
import '../../response/mastodon_response.dart';
Expand Down Expand Up @@ -794,6 +795,94 @@ abstract class AccountsV1Service {
///
/// - https://docs.joinmastodon.org/methods/preferences/#get
Future<MastodonResponse<AccountPreferences>> lookupPreferences();

/// List all hashtags featured on your profile.
///
/// ## Endpoint Url
///
/// - GET /api/v1/featured_tags HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/featured_tags/#get
Future<MastodonResponse<List<FeaturedTag>>> lookupOwnedFeaturedTags();

/// Promote a hashtag on your profile.
///
/// ## Parameters
///
/// - [tagName]: The hashtag to be featured, without the hash sign.
///
/// ## Endpoint Url
///
/// - POST /api/v1/featured_tags HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - write:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/featured_tags/#feature
Future<MastodonResponse<FeaturedTag>> createFeaturedTag({
required String tagName,
});

/// Stop promoting a hashtag on your profile.
///
/// ## Parameters
///
/// - [tagId]: The ID of the FeaturedTag in the database.
///
/// ## Endpoint Url
///
/// - DELETE /api/v1/featured_tags/:id HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - write:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/featured_tags/#unfeature-a-tag-unfeature
Future<MastodonResponse<bool>> destroyFeaturedTag({
required String tagId,
});

/// Shows up to 10 recently-used tags.
///
/// ## Endpoint Url
///
/// - GET /api/v1/featured_tags/suggestions HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read:accounts
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/featured_tags/#suggestions
Future<MastodonResponse<List<Tag>>> lookupSuggestedTags();
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1233,4 +1322,51 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: AccountPreferences.fromJson,
);

@override
Future<MastodonResponse<List<FeaturedTag>>> lookupOwnedFeaturedTags() async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/featured_tags',
),
dataBuilder: FeaturedTag.fromJson,
);

@override
Future<MastodonResponse<FeaturedTag>> createFeaturedTag({
required String tagName,
}) async =>
super.transformSingleDataResponse(
await super.post(
UserContext.oauth2Only,
'/api/v1/featured_tags',
body: {
'name': tagName,
},
checkEntity: true,
),
dataBuilder: FeaturedTag.fromJson,
);

@override
Future<MastodonResponse<bool>> destroyFeaturedTag({
required String tagId,
}) async =>
super.evaluateResponse(
await super.delete(
UserContext.oauth2Only,
'/api/v1/featured_tags/$tagId',
),
);

@override
Future<MastodonResponse<List<Tag>>> lookupSuggestedTags() async =>
super.transformMultiDataResponse(
await super.get(
UserContext.oauth2Only,
'/api/v1/featured_tags/suggestions',
),
dataBuilder: Tag.fromJson,
);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: mastodon_api
description: The easiest and powerful Dart/Flutter library for Mastodon API.
version: 0.3.0
version: 0.2.1
repository: https://github.com/mastodon-dart/mastodon-api
issue_tracker: https://github.com/mastodon-dart/mastodon-api/issues

Expand Down

0 comments on commit e585f30

Please sign in to comment.