diff --git a/lib/models/auth.dart b/lib/models/auth.dart index 807722d..d371bd7 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -394,17 +394,6 @@ class AuthModel with ChangeNotifier { return data['data']; } - Future<dynamic> getWithCredentials(String url) async { - final res = await http - .get(_apiPrefix + url, headers: _headers) - .timeout(_timeoutDuration); - final data = json.decode(res.body); - if (res.statusCode >= 400) { - throw data['message']; - } - return data; - } - String _oauthState; void redirectToGithubOauth() { _oauthState = nanoid(); diff --git a/lib/models/github.dart b/lib/models/github.dart index 604af8d..55d447a 100644 --- a/lib/models/github.dart +++ b/lib/models/github.dart @@ -131,7 +131,6 @@ class GithubEventRelease { @JsonSerializable(fieldRename: FieldRename.snake) class GithubNotificationItem { String id; - String htmlUrl; GithubNotificationItemSubject subject; DateTime updatedAt; GithubNotificationItemRepo repository; diff --git a/lib/models/github.g.dart b/lib/models/github.g.dart index 1957177..0fbd81c 100644 --- a/lib/models/github.g.dart +++ b/lib/models/github.g.dart @@ -168,7 +168,6 @@ GithubNotificationItem _$GithubNotificationItemFromJson( Map<String, dynamic> json) { return GithubNotificationItem() ..id = json['id'] as String - ..htmlUrl = json['html_url'] as String ..subject = json['subject'] == null ? null : GithubNotificationItemSubject.fromJson( @@ -187,7 +186,6 @@ Map<String, dynamic> _$GithubNotificationItemToJson( GithubNotificationItem instance) => <String, dynamic>{ 'id': instance.id, - 'html_url': instance.htmlUrl, 'subject': instance.subject, 'updated_at': instance.updatedAt?.toIso8601String(), 'repository': instance.repository, diff --git a/lib/screens/gh_news.dart b/lib/screens/gh_news.dart index 698fd49..f163f94 100644 --- a/lib/screens/gh_news.dart +++ b/lib/screens/gh_news.dart @@ -22,7 +22,8 @@ class GhNewsScreenState extends State<GhNewsScreen> { // Check if there are unread notification items. // 1 item is enough since count is not displayed for now. var items = await Provider.of<AuthModel>(context) - .getWithCredentials('/notifications?per_page=1'); + .ghClient + .getJSON('/notifications?per_page=1'); if (items is List && items.isNotEmpty) { Provider.of<NotificationModel>(context).setCount(1); @@ -33,15 +34,14 @@ class GhNewsScreenState extends State<GhNewsScreen> { Future<ListPayload<GithubEvent, int>> fetchEvents([int page = 1]) async { final auth = Provider.of<AuthModel>(context); final login = auth.activeAccount.login; - List data = await auth.getWithCredentials( - '/users/$login/received_events?page=$page&per_page=$pageSize'); - // Fimber.d(data.length); - var hasMore = data.length == pageSize; - var events = data.map((item) => GithubEvent.fromJson(item)).toList(); + final events = await auth.ghClient.getJSON( + '/users/$login/received_events?page=$page&per_page=$pageSize', + convert: (vs) => [for (var v in vs) GithubEvent.fromJson(v)], + ); return ListPayload( cursor: page + 1, - hasMore: hasMore, + hasMore: events.length == pageSize, items: events, ); } diff --git a/lib/screens/gh_notification.dart b/lib/screens/gh_notification.dart index 54806c4..482ac1c 100644 --- a/lib/screens/gh_notification.dart +++ b/lib/screens/gh_notification.dart @@ -21,11 +21,11 @@ class GhNotificationScreen extends StatefulWidget { class GhNotificationScreenState extends State<GhNotificationScreen> { Future<Map<String, NotificationGroup>> fetchNotifications(int index) async { - List items = await Provider.of<AuthModel>(context).getWithCredentials( - '/notifications?all=${index == 2}&participating=${index == 1}'); - final ns = - items.map((item) => GithubNotificationItem.fromJson(item)).toList(); - + final ns = await Provider.of<AuthModel>(context).ghClient.getJSON( + '/notifications?all=${index == 2}&participating=${index == 1}', + convert: (vs) => + [for (var v in vs) GithubNotificationItem.fromJson(v)], + ); if (index == 0) { Provider.of<NotificationModel>(context).setCount(ns.length); }