Skip to content

Commit

Permalink
Merge #573
Browse files Browse the repository at this point in the history
573: fix: fixed for the issue (#571) 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/twitter-dart/twitter-api-v2/issues
[contributor guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/CONTRIBUTING.md
[style guide]: https://github.com/twitter-dart/twitter-api-v2/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <[email protected]>
Co-authored-by: KATO, Shinya / 加藤 真也 <[email protected]>
  • Loading branch information
bors[bot] and myConsciousness authored Nov 24, 2022
2 parents 634131d + 9d2753f commit cbc9baa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## v4.4.3

- Fixed a bug that `TweetEditControls.remainingCount` had a different type. ([#571](https://github.com/twitter-dart/twitter-api-v2/issues/571))
- Fixed to exclude null fields when performing `toJson` on `TwitterResponse` and other model objects. With this fix, the JSON obtained from `toJson` is now fully equivalent to the raw JSON returned by Twitter. ([#569](https://github.com/twitter-dart/twitter-api-v2/issues/569))

## v4.4.2
Expand Down
15 changes: 1 addition & 14 deletions lib/src/service/tweets/tweet_edit_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ class TweetEditControls with _$TweetEditControls {
/// A number indicating how many more tweets will be allowed to be edited.
///
/// Tweet can be edited up to 5 times.
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
required int remainingCount,
@JsonKey(name: 'edits_remaining') required int remainingCount,

/// Indicates when the permission to edit tweets will expire.
@JsonKey(name: 'editable_until') required DateTime expireAt,
Expand All @@ -32,14 +30,3 @@ class TweetEditControls with _$TweetEditControls {
factory TweetEditControls.fromJson(Map<String, Object?> json) =>
_$TweetEditControlsFromJson(json);
}

class _RemainingCountConverter implements JsonConverter<int, String> {
/// Returns the new instance of [_RemainingCountConverter].
const _RemainingCountConverter();

@override
int fromJson(String value) => int.parse(value);

@override
String toJson(int value) => value.toString();
}
44 changes: 13 additions & 31 deletions lib/src/service/tweets/tweet_edit_controls.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ mixin _$TweetEditControls {
///
/// Tweet can be edited up to 5 times.
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
int get remainingCount => throw _privateConstructorUsedError;

/// Indicates when the permission to edit tweets will expire.
Expand All @@ -49,13 +48,9 @@ abstract class $TweetEditControlsCopyWith<$Res> {
TweetEditControls value, $Res Function(TweetEditControls) then) =
_$TweetEditControlsCopyWithImpl<$Res>;
$Res call(
{@JsonKey(name: 'is_edit_eligible')
bool isEditable,
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
int remainingCount,
@JsonKey(name: 'editable_until')
DateTime expireAt});
{@JsonKey(name: 'is_edit_eligible') bool isEditable,
@JsonKey(name: 'edits_remaining') int remainingCount,
@JsonKey(name: 'editable_until') DateTime expireAt});
}

/// @nodoc
Expand Down Expand Up @@ -98,13 +93,9 @@ abstract class _$$_TweetEditControlsCopyWith<$Res>
__$$_TweetEditControlsCopyWithImpl<$Res>;
@override
$Res call(
{@JsonKey(name: 'is_edit_eligible')
bool isEditable,
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
int remainingCount,
@JsonKey(name: 'editable_until')
DateTime expireAt});
{@JsonKey(name: 'is_edit_eligible') bool isEditable,
@JsonKey(name: 'edits_remaining') int remainingCount,
@JsonKey(name: 'editable_until') DateTime expireAt});
}

/// @nodoc
Expand Down Expand Up @@ -145,13 +136,9 @@ class __$$_TweetEditControlsCopyWithImpl<$Res>
@JsonSerializable()
class _$_TweetEditControls implements _TweetEditControls {
const _$_TweetEditControls(
{@JsonKey(name: 'is_edit_eligible')
required this.isEditable,
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
required this.remainingCount,
@JsonKey(name: 'editable_until')
required this.expireAt});
{@JsonKey(name: 'is_edit_eligible') required this.isEditable,
@JsonKey(name: 'edits_remaining') required this.remainingCount,
@JsonKey(name: 'editable_until') required this.expireAt});

factory _$_TweetEditControls.fromJson(Map<String, dynamic> json) =>
_$$_TweetEditControlsFromJson(json);
Expand All @@ -168,7 +155,6 @@ class _$_TweetEditControls implements _TweetEditControls {
/// Tweet can be edited up to 5 times.
@override
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
final int remainingCount;

/// Indicates when the permission to edit tweets will expire.
Expand Down Expand Up @@ -217,13 +203,10 @@ class _$_TweetEditControls implements _TweetEditControls {

abstract class _TweetEditControls implements TweetEditControls {
const factory _TweetEditControls(
{@JsonKey(name: 'is_edit_eligible')
required final bool isEditable,
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
required final int remainingCount,
@JsonKey(name: 'editable_until')
required final DateTime expireAt}) = _$_TweetEditControls;
{@JsonKey(name: 'is_edit_eligible') required final bool isEditable,
@JsonKey(name: 'edits_remaining') required final int remainingCount,
@JsonKey(name: 'editable_until') required final DateTime expireAt}) =
_$_TweetEditControls;

factory _TweetEditControls.fromJson(Map<String, dynamic> json) =
_$_TweetEditControls.fromJson;
Expand All @@ -241,7 +224,6 @@ abstract class _TweetEditControls implements TweetEditControls {
///
/// Tweet can be edited up to 5 times.
@JsonKey(name: 'edits_remaining')
@_RemainingCountConverter()
int get remainingCount;
@override

Expand Down
6 changes: 2 additions & 4 deletions lib/src/service/tweets/tweet_edit_controls.g.dart

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

2 changes: 1 addition & 1 deletion test/src/service/tweets/data/lookup_by_id.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"edit_controls": {
"is_edit_eligible": true,
"editable_until": "2022-08-21 09:35:20.311",
"edits_remaining": "4"
"edits_remaining": 4
}
}
}
2 changes: 1 addition & 1 deletion test/src/service/tweets/tweets_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ void main() {

expect(editControls.toJson(), {
'is_edit_eligible': true,
'edits_remaining': '4',
'edits_remaining': 4,
'editable_until': '2022-08-21T09:35:20.311'
});
});
Expand Down

0 comments on commit cbc9baa

Please sign in to comment.