Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fixed for the issue (#21) #85

Merged
merged 1 commit into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Note

## v0.2.3

- Supported `suggestions API methods`. ([#21](https://github.com/mastodon-dart/mastodon-api/issues/21))
- `GET /api/v2/suggestions`
- `DELETE /api/v1/suggestions/:account_id`

## v0.2.2

- Supported `preferences API methods`. ([#19](https://github.com/mastodon-dart/mastodon-api/issues/19))
Expand Down
3 changes: 3 additions & 0 deletions lib/mastodon_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export 'package:mastodon_api/src/service/entities/preview_card_type.dart';
export 'package:mastodon_api/src/service/entities/rate_limit.dart';
export 'package:mastodon_api/src/service/entities/registered_application.dart';
export 'package:mastodon_api/src/service/entities/status.dart';
export 'package:mastodon_api/src/service/entities/suggested_reason.dart';
export 'package:mastodon_api/src/service/entities/suggestion.dart';
export 'package:mastodon_api/src/service/entities/tag.dart';
export 'package:mastodon_api/src/service/entities/thumbnail.dart';
export 'package:mastodon_api/src/service/entities/thumbnail_version.dart';
Expand All @@ -64,6 +66,7 @@ export 'package:mastodon_api/src/service/v1/apps/apps_v1_service.dart';
export 'package:mastodon_api/src/service/v1/statuses/status_poll_param.dart';
export 'package:mastodon_api/src/service/v1/statuses/statuses_v1_service.dart';
export 'package:mastodon_api/src/service/v1/timelines/timelines_v1_service.dart';
export 'package:mastodon_api/src/service/v2/accounts/accounts_v2_service.dart';
export 'package:mastodon_api/src/service/v2/entities/v2_instance.dart';
export 'package:mastodon_api/src/service/v2/entities/v2_instance_configuration.dart';
export 'package:mastodon_api/src/service/v2/entities/v2_search.dart';
Expand Down
25 changes: 25 additions & 0 deletions lib/src/service/entities/suggested_reason.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2022 Kato Shinya. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided the conditions.

import 'package:freezed_annotation/freezed_annotation.dart';

import '../../core/serializable.dart';

enum SuggestedReason implements Serializable {
/// This account was manually recommended by your administration team.
staff('staff'),

/// You have interacted with this account previously.
@JsonValue('past_interactions')
pastInteractions('past_interactions'),

/// This account has many reblogs, favourites, and active local followers
/// within the last 30 days.
global('global');

@override
final String value;

const SuggestedReason(this.value);
}
30 changes: 30 additions & 0 deletions lib/src/service/entities/suggestion.dart
Original file line number Diff line number Diff line change
@@ -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';

// 🌎 Project imports:
import 'account.dart';
import 'suggested_reason.dart';

part 'suggestion.freezed.dart';
part 'suggestion.g.dart';

@freezed
class Suggestion with _$Suggestion {
@JsonSerializable(includeIfNull: false)
const factory Suggestion({
/// The reason this account is being suggested.
required SuggestedReason source,

/// The account being recommended to follow.
required Account account,
}) = _Suggestion;

factory Suggestion.fromJson(Map<String, Object?> json) =>
_$SuggestionFromJson(json);
}
193 changes: 193 additions & 0 deletions lib/src/service/entities/suggestion.freezed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// 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 'suggestion.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(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');

Suggestion _$SuggestionFromJson(Map<String, dynamic> json) {
return _Suggestion.fromJson(json);
}

/// @nodoc
mixin _$Suggestion {
/// The reason this account is being suggested.
SuggestedReason get source => throw _privateConstructorUsedError;

/// The account being recommended to follow.
Account get account => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$SuggestionCopyWith<Suggestion> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $SuggestionCopyWith<$Res> {
factory $SuggestionCopyWith(
Suggestion value, $Res Function(Suggestion) then) =
_$SuggestionCopyWithImpl<$Res, Suggestion>;
@useResult
$Res call({SuggestedReason source, Account account});

$AccountCopyWith<$Res> get account;
}

/// @nodoc
class _$SuggestionCopyWithImpl<$Res, $Val extends Suggestion>
implements $SuggestionCopyWith<$Res> {
_$SuggestionCopyWithImpl(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? source = null,
Object? account = null,
}) {
return _then(_value.copyWith(
source: null == source
? _value.source
: source // ignore: cast_nullable_to_non_nullable
as SuggestedReason,
account: null == account
? _value.account
: account // ignore: cast_nullable_to_non_nullable
as Account,
) as $Val);
}

@override
@pragma('vm:prefer-inline')
$AccountCopyWith<$Res> get account {
return $AccountCopyWith<$Res>(_value.account, (value) {
return _then(_value.copyWith(account: value) as $Val);
});
}
}

/// @nodoc
abstract class _$$_SuggestionCopyWith<$Res>
implements $SuggestionCopyWith<$Res> {
factory _$$_SuggestionCopyWith(
_$_Suggestion value, $Res Function(_$_Suggestion) then) =
__$$_SuggestionCopyWithImpl<$Res>;
@override
@useResult
$Res call({SuggestedReason source, Account account});

@override
$AccountCopyWith<$Res> get account;
}

/// @nodoc
class __$$_SuggestionCopyWithImpl<$Res>
extends _$SuggestionCopyWithImpl<$Res, _$_Suggestion>
implements _$$_SuggestionCopyWith<$Res> {
__$$_SuggestionCopyWithImpl(
_$_Suggestion _value, $Res Function(_$_Suggestion) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? source = null,
Object? account = null,
}) {
return _then(_$_Suggestion(
source: null == source
? _value.source
: source // ignore: cast_nullable_to_non_nullable
as SuggestedReason,
account: null == account
? _value.account
: account // ignore: cast_nullable_to_non_nullable
as Account,
));
}
}

/// @nodoc

@JsonSerializable(includeIfNull: false)
class _$_Suggestion implements _Suggestion {
const _$_Suggestion({required this.source, required this.account});

factory _$_Suggestion.fromJson(Map<String, dynamic> json) =>
_$$_SuggestionFromJson(json);

/// The reason this account is being suggested.
@override
final SuggestedReason source;

/// The account being recommended to follow.
@override
final Account account;

@override
String toString() {
return 'Suggestion(source: $source, account: $account)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_Suggestion &&
(identical(other.source, source) || other.source == source) &&
(identical(other.account, account) || other.account == account));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, source, account);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_SuggestionCopyWith<_$_Suggestion> get copyWith =>
__$$_SuggestionCopyWithImpl<_$_Suggestion>(this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_SuggestionToJson(
this,
);
}
}

abstract class _Suggestion implements Suggestion {
const factory _Suggestion(
{required final SuggestedReason source,
required final Account account}) = _$_Suggestion;

factory _Suggestion.fromJson(Map<String, dynamic> json) =
_$_Suggestion.fromJson;

@override

/// The reason this account is being suggested.
SuggestedReason get source;
@override

/// The account being recommended to follow.
Account get account;
@override
@JsonKey(ignore: true)
_$$_SuggestionCopyWith<_$_Suggestion> get copyWith =>
throw _privateConstructorUsedError;
}
35 changes: 35 additions & 0 deletions lib/src/service/entities/suggestion.g.dart

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

10 changes: 9 additions & 1 deletion lib/src/service/mastodon_v2_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// 🌎 Project imports:
import '../core/client/client_context.dart';
import 'v2/accounts/accounts_v2_service.dart';
import 'v2/search/search_v2_service.dart';

/// The class represents the Mastodon v2 services.
Expand All @@ -18,6 +19,9 @@ abstract class MastodonV2Service {
context: context,
);

/// Returns the accounts service.
AccountsV2Service get accounts;

/// Returns the search service.
SearchV2Service get search;
}
Expand All @@ -27,7 +31,11 @@ class _MastodonV2Service implements MastodonV2Service {
_MastodonV2Service({
required String instance,
required ClientContext context,
}) : search = SearchV2Service(instance: instance, context: context);
}) : accounts = AccountsV2Service(instance: instance, context: context),
search = SearchV2Service(instance: instance, context: context);

@override
final AccountsV2Service accounts;

@override
final SearchV2Service search;
Expand Down
36 changes: 36 additions & 0 deletions lib/src/service/v1/accounts/accounts_v1_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,31 @@ abstract class AccountsV1Service {
///
/// - https://docs.joinmastodon.org/methods/followed_tags/#get
Future<MastodonResponse<List<Tag>>> lookupFollowedTags({int? limit});

/// Remove an account from follow suggestions.
///
/// ## Parameters
///
/// - [accountId]: The ID of the Account in the database.
///
/// ## Endpoint Url
///
/// - DELETE /api/v1/suggestions/:account_id HTTP/1.1
///
/// ## Authentication Methods
///
/// - OAuth 2.0
///
/// ## Required Scopes
///
/// - read
///
/// ## Reference
///
/// - https://docs.joinmastodon.org/methods/suggestions/#remove
Future<MastodonResponse<bool>> destroyFollowSuggestion({
required String accountId,
});
}

class _AccountsV1Service extends BaseService implements AccountsV1Service {
Expand Down Expand Up @@ -1408,4 +1433,15 @@ class _AccountsV1Service extends BaseService implements AccountsV1Service {
),
dataBuilder: Tag.fromJson,
);

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