From 129f4f5162e43fc6ab08c7722aca9a3b914255fb Mon Sep 17 00:00:00 2001 From: Felipe Bueno Date: Sat, 8 Jun 2024 12:23:35 -0300 Subject: [PATCH] 1.3.2+31: Fix upsertComment --- lib/data/api.dart | 50 ++++++++++++++++++++++++++++++++++++++++++++--- pubspec.yaml | 2 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/lib/data/api.dart b/lib/data/api.dart index 2fecdcb..4bb6f8d 100644 --- a/lib/data/api.dart +++ b/lib/data/api.dart @@ -553,8 +553,27 @@ final class Api { final response = await _dio.post( 'https://stacker.news/api/graphql', - data: - "{\"operationName\":\"upsertComment\",\"variables\":{\"parentId\":\"$parentId\",\"text\":\"$text\"},\"query\":\"fragment CommentFields on Item {\\n id\\n parentId\\n createdAt\\n deletedAt\\n text\\n user {\\n id\\n name\\n optional {\\n streak\\n __typename\\n }\\n meMute\\n __typename\\n }\\n sats\\n upvotes\\n wvotes\\n boost\\n meSats\\n meDontLike\\n meBookmark\\n meSubscription\\n outlawed\\n freebie\\n path\\n commentSats\\n mine\\n otsHash\\n ncomments\\n imgproxyUrls\\n __typename\\n}\\n\\nfragment CommentsRecursive on Item {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n comments {\\n ...CommentFields\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n }\\n __typename\\n}\\n\\nmutation upsertComment(\$text: String!, \$parentId: ID!, \$hash: String, \$hmac: String) {\\n upsertComment(text: \$text, parentId: \$parentId, hash: \$hash, hmac: \$hmac) {\\n ...CommentFields\\n comments {\\n ...CommentsRecursive\\n __typename\\n }\\n __typename\\n }\\n}\"}", + options: Options( + headers: { + 'Content-Type': 'application/json', + }, + ), + data: jsonEncode( + GqlBody( + operationName: "upsertComment", + variables: { + "parentId": parentId, + "text": text, + }, + query: """ + mutation upsertComment(\$parentId: ID!, \$text: String!) { + upsertComment(parentId: \$parentId, text: \$text) { + id + } + } + """, + ), + ), ); if (response.statusCode == 200) { @@ -563,7 +582,6 @@ final class Api { if (error != null) { Utils.showError(error); - throw Exception(error); } @@ -574,3 +592,29 @@ final class Api { } // #endregion Items & Comments } + +class GqlBody { + final String? operationName; + final String? query; + final Map? variables; + + GqlBody({ + this.operationName, + this.query, + this.variables, + }); + + Map toJson() => { + 'operationName': operationName, + 'query': query, + 'variables': variables, + }; +} + +class GqlError { + final String? message; + + GqlError({ + this.message, + }); +} diff --git a/pubspec.yaml b/pubspec.yaml index 7b313af..abb9207 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A new Flutter project. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.3.1+30 +version: 1.3.2+31 environment: sdk: ">=3.4.0 <4.0.0"