From e772059f235af846a65b177041fa94414b0fd9f8 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Fri, 7 Feb 2020 22:05:07 +0800 Subject: [PATCH] refactor(gh): use github lib --- lib/models/auth.dart | 20 -------------------- lib/screens/gh_notification.dart | 17 +++++++++++------ lib/widgets/notification_item.dart | 4 +++- pubspec.yaml | 6 +++++- 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/models/auth.dart b/lib/models/auth.dart index c938257..7491d5c 100644 --- a/lib/models/auth.dart +++ b/lib/models/auth.dart @@ -414,26 +414,6 @@ class AuthModel with ChangeNotifier { return res.body; } - Future patchWithCredentials(String url) async { - await http - .patch(_apiPrefix + url, headers: _headers) - .timeout(_timeoutDuration); - } - - Future putWithCredentials( - String url, { - String contentType = 'application/json', - Map body = const {}, - }) async { - return http - .put( - _apiPrefix + url, - headers: {..._headers, HttpHeaders.contentTypeHeader: contentType}, - body: json.encode(body), - ) - .timeout(_timeoutDuration); - } - String _oauthState; void redirectToGithubOauth() { _oauthState = nanoid(); diff --git a/lib/screens/gh_notification.dart b/lib/screens/gh_notification.dart index 9375196..54806c4 100644 --- a/lib/screens/gh_notification.dart +++ b/lib/screens/gh_notification.dart @@ -4,6 +4,7 @@ import 'package:git_touch/models/theme.dart'; import 'package:git_touch/scaffolds/tab_stateful.dart'; import 'package:git_touch/widgets/action_entry.dart'; import 'package:git_touch/widgets/app_bar_title.dart'; +import 'package:github/github.dart'; import 'package:provider/provider.dart'; import 'package:git_touch/models/notification.dart'; import 'package:git_touch/models/auth.dart'; @@ -100,9 +101,10 @@ ${item.key}: pullRequest(number: ${item.subject.number}) { } Widget _buildGroupItem( - BuildContext context, - MapEntry entry, - Map groupMap) { + BuildContext context, + MapEntry entry, + Map groupMap, + ) { final theme = Provider.of(context); final group = entry.value; return ListGroup( @@ -119,8 +121,9 @@ ${item.key}: pullRequest(number: ${item.subject.number}) { ), GestureDetector( onTap: () async { - await Provider.of(context) - .putWithCredentials('/repos/${group.fullName}/notifications'); + final auth = Provider.of(context); + await auth.ghClient.activity.markRepositoryNotificationsRead( + RepositorySlug.full(group.fullName)); // await _onSwitchTab(); // TODO: }, child: Icon( @@ -172,7 +175,9 @@ ${item.key}: pullRequest(number: ${item.subject.number}) { .showConfirm(context, Text('Mark all as read?')); if (value) { await Provider.of(context) - .putWithCredentials('/notifications'); + .ghClient + .activity + .markNotificationsRead(); refresh(); } }, diff --git a/lib/widgets/notification_item.dart b/lib/widgets/notification_item.dart index 686232b..f0e8fc2 100644 --- a/lib/widgets/notification_item.dart +++ b/lib/widgets/notification_item.dart @@ -84,7 +84,9 @@ class _NotificationItemState extends State { }); try { await Provider.of(context) - .patchWithCredentials('/notifications/threads/${payload.id}'); + .ghClient + .activity + .markThreadRead(payload.id); widget.markAsRead(); } finally { if (mounted) { diff --git a/pubspec.yaml b/pubspec.yaml index a34e4fc..2f6d31e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,7 +40,11 @@ dependencies: gql_link: ^0.2.0 fluro: ^1.5.1 package_info: ^0.4.0 - + github: #^6.1.0 + git: + url: git://github.com/pd4d10/github.dart.git + ref: patch-1 + #path: ../../github/github.dart # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2