8000 refactor: continue loading by poppingmoon · Pull Request #651 · poppingmoon/aria · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: continue loading #651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/model/id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ String _toCrockfordsBase32(BigInt i) {
enum IdGenMethod { aid, aidx, meid, meidg, ulid, objectid }

class Id {
Id({required this.method, required this.date, this.random = ''});
const Id({required this.method, required this.date, this.random = ''});

final IdGenMethod method;
final DateTime date;
Expand Down
14 changes: 11 additions & 3 deletions lib/provider/api/announcements_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ part 'announcements_notifier_provider.g.dart';
@riverpod
class AnnouncementsNotifier extends _$AnnouncementsNotifier {
@override
FutureOr<PaginationState<AnnouncementsResponse>> build(
Stream<PaginationState<AnnouncementsResponse>> build(
Account account, {
bool isActive = true,
}) async {
}) async* {
final response = await _fetchAnnouncements();
return PaginationState.fromIterable(response);
yield PaginationState.fromIterable(response);
if (response.isNotEmpty && response.length < 10) {
await loadMore();
}
}

Misskey get _misskey => ref.read(misskeyProvider(account));
Expand All @@ -41,17 +44,22 @@ class AnnouncementsNotifier extends _$AnnouncementsNotifier {
if (value.isLastLoaded) {
return;
}
bool shouldLoadMore = false;
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final response = await _fetchAnnouncements(
untilId: value.items.lastOrNull?.id,
offset: value.items.length,
);
shouldLoadMore = response.isNotEmpty && response.length < 5;
return PaginationState(
items: [...value.items, ...response],
isLastLoaded: response.isEmpty,
);
});
if (shouldLoadMore) {
await loadMore();
}
}

Future<void> readAnnouncement(String announcementId) async {
Expand Down
16 changes: 8 additions & 8 deletions lib/provider/api/announcements_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions lib/provider/api/attached_notes_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ part 'attached_notes_notifier_provider.g.dart';
@riverpod
class AttachedNotesNotifier extends _$AttachedNotesNotifier {
@override
FutureOr<PaginationState<Note>> build(Account account, String fileId) async {
Stream<PaginationState<Note>> build(Account account, String fileId) async* {
final response = await _fetchNotes();
return PaginationState.fromIterable(response);
yield PaginationState.fromIterable(response);
if (response.isNotEmpty && response.length < 10) {
await loadMore();
}
}

Future<Iterable<Note>> _fetchNotes({String? untilId}) async {
Expand All @@ -36,6 +39,7 @@ class AttachedNotesNotifier extends _$AttachedNotesNotifier {
if (value.isLastLoaded) {
return;
}
bool shouldLoadMore = false;
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final response = await _fetchNotes(untilId: value.items.lastOrNull?.id);
Expand All @@ -44,11 +48,15 @@ class AttachedNotesNotifier extends _$AttachedNotesNotifier {
// until Misskey 2023.10.0.
return value.copyWith(isLastLoaded: true);
} else {
shouldLoadMore = response.isNotEmpty && response.length < 5;
return PaginationState(
items: [...value.items, ...response],
isLastLoaded: response.isEmpty,
);
}
});
if (shouldLoadMore) {
await loadMore();
}
}
}
16 changes: 8 additions & 8 deletions lib/provider/api/attached_notes_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions lib/provider/api/blockings_notifier_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ part 'blockings_notifier_provider.g.dart';
@riverpod
class BlockingsNotifier extends _$BlockingsNotifier {
@override
FutureOr<PaginationState<Blocking>> build(Account account) async {
Stream<PaginationState<Blocking>> build(Account account) async* {
final response = await _fetchBlockings();
return PaginationState.fromIterable(response);
yield PaginationState.fromIterable(response);
if (response.isNotEmpty && response.length < 10) {
F41A await loadMore();
}
}

Misskey get _misskey => ref.read(misskeyProvider(account));
Expand All @@ -29,16 +32,21 @@ class BlockingsNotifier extends _$BlockingsNotifier {
if (value.isLastLoaded) {
return;
}
bool shouldLoadMore = false;
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final response = await _fetchBlockings(
untilId: value.items.lastOrNull?.id,
);
shouldLoadMore = response.isNotEmpty && response.length < 5;
return PaginationState(
items: [...value.items, ...response],
isLastLoaded: response.isEmpty,
);
});
if (shouldLoadMore) {
await loadMore();
}
}

Future<void> delete(String userId) async {
Expand Down
16 changes: 8 additions & 8 deletions lib/provider/api/blockings_notifier_provider.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions lib/provider/api/chat_invitations_notifier_provider.dart
74C7
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ part 'chat_invitations_notifier_provider.g.dart';
@riverpod
class ChatInvitationsNotifier extends _$ChatInvitationsNotifier {
@override
FutureOr<PaginationState<ChatJoining>> build(Account account) async {
Stream<PaginationState<ChatJoining>> build(Account account) async* {
final response = await _fetchInvitations();
return PaginationState.fromIterable(response);
yield PaginationState.fromIterable(response);
if (response.isNotEmpty && response.length < 10) {
await loadMore();
}
}

Misskey get _misskey => ref.read(misskeyProvider(account));
Expand All @@ -31,16 +34,21 @@ class ChatInvitationsNotifier extends _$ChatInvitationsNotifier {
if (value.isLastLoaded) {
return;
}
bool shouldLoadMore = false;
state = const AsyncValue.loading();
state = await AsyncValue.guard(() async {
final response = await _fetchInvitations(
untilId: value.items.lastOrNull?.id,
);
shouldLoadMore = response.isNotEmpty && response.length < 5;
return PaginationState(
items: [...value.items, ...response],
isLastLoaded: response.isEmpty,
);
});
if (shouldLoadMore) {
await loadMore();
}
}

Future<void> join(String roomId) async {
Expand Down
Loading
Loading
0