From d83db82971d8e5b38e8acb7f3bdaa870c0289ae6 Mon Sep 17 00:00:00 2001 From: Jonathan Bouchard Date: Sat, 18 Feb 2023 00:18:19 -0500 Subject: [PATCH] Fixing the "invalid offset" error from the new pagination from BTTV --- .github/workflows/flutter-ci.yml | 25 ++++++++++++------------ android/app/build.gradle | 4 ++-- android/app/src/main/AndroidManifest.xml | 1 + lib/models/emote.dart | 3 +++ lib/services/fetch_emotes.dart | 17 ++++++++++++---- lib/widgets/network_emote_list.dart | 10 +++++++--- pubspec.yaml | 8 +++----- 7 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.github/workflows/flutter-ci.yml b/.github/workflows/flutter-ci.yml index ccbad0b..0384213 100644 --- a/.github/workflows/flutter-ci.yml +++ b/.github/workflows/flutter-ci.yml @@ -3,9 +3,9 @@ name: Flutter CI on: push: tags: - - 'v*' - workflow_dispatch: - + - "v*" + workflow_dispatch: + jobs: build: runs-on: ubuntu-latest @@ -16,18 +16,18 @@ jobs: - name: Setup Java uses: actions/setup-java@v1 with: - java-version: '12.x' - + java-version: "12.x" + - name: Download signing key id: signing_key - uses: timheuer/base64-to-file@master + uses: timheuer/base64-to-file@main with: fileName: key.jks encodedString: ${{ secrets.SIGNING_KEY }} - name: Download Google services file id: google_services_file - uses: timheuer/base64-to-file@master + uses: timheuer/base64-to-file@main with: fileName: google-services.json encodedString: ${{ secrets.GOOGLE_SERVICES_FILE }} @@ -40,7 +40,8 @@ jobs: - name: Setup Flutter actions uses: subosito/flutter-action@v1 with: - channel: 'stable' + flutter-version: "2.0.3" + channel: "stable" - name: Download pub dependencies run: flutter pub get @@ -50,7 +51,7 @@ jobs: - name: Run analyzer run: flutter analyze . - + - name: Run tests run: flutter test @@ -66,8 +67,8 @@ jobs: uses: actions/upload-artifact@v2 with: name: release-apks - path: 'build/app/outputs/apk/release/*.apk' - + path: "build/app/outputs/apk/release/*.apk" + - name: Build release appbundle run: flutter build appbundle env: @@ -80,4 +81,4 @@ jobs: uses: actions/upload-artifact@v2 with: name: release-appbundle - path: 'build/app/outputs/bundle/release/app-release.aab' \ No newline at end of file + path: "build/app/outputs/bundle/release/app-release.aab" diff --git a/android/app/build.gradle b/android/app/build.gradle index 924bbf0..ecfbfb5 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -40,7 +40,7 @@ if (keystorePropertiesFile.exists()) { } android { - compileSdkVersion 30 + compileSdkVersion 31 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -53,7 +53,7 @@ android { defaultConfig { applicationId "com.drakota.bttvstickers" minSdkVersion 21 - targetSdkVersion 30 + targetSdkVersion 31 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index a8b9038..c085ae1 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -27,6 +27,7 @@ json) { return Emote( id: json['id'], + paginationId: json['paginationId'], code: json['code'], imageType: json['imageType'], imageUrl: "$kEmoteCdnUrl/${json['id']}/3x.${json['imageType']}", diff --git a/lib/services/fetch_emotes.dart b/lib/services/fetch_emotes.dart index d1b786c..e0936f8 100644 --- a/lib/services/fetch_emotes.dart +++ b/lib/services/fetch_emotes.dart @@ -50,12 +50,21 @@ Future> fetchEmotes({ final response = await http.get(Uri.parse("$url?$queryString")); if (response.statusCode == 200) { var result = jsonDecode(response.body) as List; - // Global emotes return the emote directly so if the value in the object's - // key emote is null we just take the whole object - return result.map((item) => Emote.fromJson(item['emote'] ?? item)).toList(); + return result.map((item) { + // Global emotes return the emote directly so if the value in the object's + // key emote is null we just take the whole object + if (item['emote'] == null) { + return Emote.fromJson(item); + } + + var emote = item['emote']; + // Offset doesn't work anymore for global emotes so we use the id + emote['paginationId'] = item['id']; + return Emote.fromJson(emote); + }).toList(); } else { throw Exception( - 'Failed to while fetching emotes...\nError: ${response.body}', + 'Failure while fetching emotes...\nError: ${response.body}', ); } } diff --git a/lib/widgets/network_emote_list.dart b/lib/widgets/network_emote_list.dart index 69799b5..9a3a4a7 100644 --- a/lib/widgets/network_emote_list.dart +++ b/lib/widgets/network_emote_list.dart @@ -33,8 +33,10 @@ class _NetworkEmoteListState extends State { setState(() { _loading = true; }); - var before = (widget.category == Category.shared && _emotes.isNotEmpty) - ? _emotes.last.id + var before = _emotes.isNotEmpty + ? (widget.category == Category.shared) + ? _emotes.last.id + : _emotes.last.paginationId : null; var query = (widget.query != null && widget.query!.length >= 3) ? widget.query @@ -42,7 +44,9 @@ class _NetworkEmoteListState extends State { var result = await fetchEmotes( category: widget.category, query: query, - offset: _offset, + // Pagination with offset seems to only work for + // shared emotes with a query + offset: query != null ? _offset : null, // The API for shared needs to know the last id of our // list of emotes to paginate before: before, diff --git a/pubspec.yaml b/pubspec.yaml index a68467b..b7201e7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Use any BetterTTV emotes in messaging apps with stickers. # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -15,16 +15,16 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # 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: 2.1.0+10 +version: 2.1.1+11 environment: sdk: ">=2.12.0 <3.0.0" + flutter: "^2.0.3" dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. http: ^0.13.0 @@ -49,7 +49,6 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. @@ -123,7 +122,6 @@ flutter: - family: CascadiaMono fonts: - asset: assets/fonts/CascadiaMono.ttf - # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages