Skip to content

Commit

Permalink
v.1.5.3 (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusprey authored Sep 24, 2024
1 parent 703dd4e commit 9480a2a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
12 changes: 8 additions & 4 deletions lib/feature/activity/activities_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:otraku/extension/date_time_extension.dart';
import 'package:otraku/extension/future_extension.dart';
import 'package:otraku/feature/activity/activities_filter_model.dart';
import 'package:otraku/feature/activity/activities_filter_provider.dart';
Expand All @@ -20,14 +19,17 @@ class ActivitiesNotifier
extends AutoDisposeFamilyAsyncNotifier<Paged<Activity>, int> {
late int viewerId;
late ActivitiesFilter filter;
int _lastCreatedAt = DateTime.now().secondsSinceEpoch;

// Used to skip activities when fetching outdated pages.
int? _lastId;

@override
FutureOr<Paged<Activity>> build(arg) async {
if (arg == homeFeedId) {
ref.keepAlive();
}

_lastId = null;
viewerId = Persistence().id!;
filter = ref.watch(activitiesFilterProvider(arg));
return await _fetch(const Paged());
Expand All @@ -46,10 +48,10 @@ class ActivitiesNotifier
'typeIn': filter.typeIn.map((t) => t.name).toList(),
...switch (filter) {
HomeActivitiesFilter filter => {
'page': oldState.next,
'isFollowing': filter.onFollowing,
if (!filter.withViewerActivities) 'userIdNot': viewerId,
if (!filter.onFollowing) 'hasRepliesOrText': true,
if (oldState.items.isNotEmpty) 'createdBefore': _lastCreatedAt,
},
UserActivitiesFilter filter => {
'userId': filter.userId,
Expand All @@ -61,12 +63,14 @@ class ActivitiesNotifier

final items = <Activity>[];
for (final a in data['Page']['activities']) {
if (_lastId != null && a['id'] >= _lastId) continue;

final item = Activity.maybe(a, viewerId, Persistence().imageQuality);
if (item != null) items.add(item);
}

if (data['Page']['activities'].isNotEmpty) {
_lastCreatedAt = data['Page']['activities'].last['createdAt'];
_lastId = data['Page']['activities'].last['id'];
}

return oldState.withNext(
Expand Down
5 changes: 2 additions & 3 deletions lib/util/graphql.dart
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,11 @@ abstract class GqlQuery {

static const activityPage = r'''
query Activities($userId: Int, $userIdNot: Int, $page: Int = 1, $isFollowing: Boolean,
$hasRepliesOrText: Boolean, $typeIn: [ActivityType], $createdBefore: Int) {
$hasRepliesOrText: Boolean, $typeIn: [ActivityType]) {
Page(page: $page) {
pageInfo {hasNextPage}
activities(userId: $userId, userId_not: $userIdNot, isFollowing: $isFollowing,
hasRepliesOrTypeText: $hasRepliesOrText, type_in: $typeIn, sort: [PINNED, ID_DESC],
createdAt_lesser: $createdBefore) {
hasRepliesOrTypeText: $hasRepliesOrText, type_in: $typeIn, sort: [PINNED, ID_DESC]) {
... on TextActivity {...textActivity}
... on ListActivity {...listActivity}
... on MessageActivity {...messageActivity}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/persistence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:otraku/util/theming.dart';
import 'package:path_provider/path_provider.dart';

/// Current app version.
const versionCode = '1.5.2';
const versionCode = '1.5.3';

/// General options keys.
enum _OptionKey {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: An unofficial AniList app.

publish_to: 'none'

version: 1.5.2+76
version: 1.5.3+77

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down

0 comments on commit 9480a2a

Please sign in to comment.