mirror of
https://github.com/immich-app/immich.git
synced 2024-12-21 01:39:59 +02:00
af32183728
* refactor: autoroutex pushroute * refactor: autoroutex popRoute * refactor: autoroutex navigate and replace * chore: add doc comments for extension methods * refactor: Add LoggerMixin and refactor Album activities to use mixin * refactor: Activity page * chore: activity user from user constructor * fix: update current asset after build method * refactor: tests with similar structure as lib * chore: remove avoid-declaring-call-method rule from dcm analysis * test: fix proper expect order * test: activity_statistics_provider_test * test: activity_provider_test * test: use proper matchers * test: activity_text_field_test & dismissible_activity_test added * test: add http mock to return transparent image * test: download isar core libs during test * test: add widget tags to widget test cases * test: activity_tile_test * build: currentAlbumProvider to generator * movie add / remove like to activity input tile * test: activities_page_test.dart * chore: better error logs * chore: dismissibleactivity as statelesswidget --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
68 lines
2.5 KiB
Dart
68 lines
2.5 KiB
Dart
import 'package:immich_mobile/modules/activities/models/activity.model.dart';
|
|
import 'package:immich_mobile/modules/activities/providers/activity_service.provider.dart';
|
|
import 'package:immich_mobile/modules/activities/providers/activity_statistics.provider.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
part 'activity.provider.g.dart';
|
|
|
|
/// Maintains the current list of all activities for <share-album-id, asset>
|
|
@riverpod
|
|
class AlbumActivity extends _$AlbumActivity {
|
|
@override
|
|
Future<List<Activity>> build(String albumId, [String? assetId]) async {
|
|
return ref
|
|
.watch(activityServiceProvider)
|
|
.getAllActivities(albumId, assetId: assetId);
|
|
}
|
|
|
|
Future<void> removeActivity(String id) async {
|
|
if (await ref.watch(activityServiceProvider).removeActivity(id)) {
|
|
final activities = state.valueOrNull ?? [];
|
|
final removedActivity = activities.firstWhere((a) => a.id == id);
|
|
activities.remove(removedActivity);
|
|
state = AsyncData(activities);
|
|
// Decrement activity count only for comments
|
|
if (removedActivity.type == ActivityType.comment) {
|
|
ref
|
|
.watch(activityStatisticsProvider(albumId, assetId).notifier)
|
|
.removeActivity();
|
|
}
|
|
}
|
|
}
|
|
|
|
Future<void> addLike() async {
|
|
final activity = await ref
|
|
.watch(activityServiceProvider)
|
|
.addActivity(albumId, ActivityType.like, assetId: assetId);
|
|
if (activity.hasValue) {
|
|
final activities = state.asData?.value ?? [];
|
|
state = AsyncData([...activities, activity.requireValue]);
|
|
}
|
|
}
|
|
|
|
Future<void> addComment(String comment) async {
|
|
final activity = await ref.watch(activityServiceProvider).addActivity(
|
|
albumId,
|
|
ActivityType.comment,
|
|
assetId: assetId,
|
|
comment: comment,
|
|
);
|
|
|
|
if (activity.hasValue) {
|
|
final activities = state.valueOrNull ?? [];
|
|
state = AsyncData([...activities, activity.requireValue]);
|
|
ref
|
|
.watch(activityStatisticsProvider(albumId, assetId).notifier)
|
|
.addActivity();
|
|
// The previous addActivity call would increase the count of an asset if assetId != null
|
|
// To also increase the activity count of the album, calling it once again with assetId set to null
|
|
if (assetId != null) {
|
|
ref.watch(activityStatisticsProvider(albumId).notifier).addActivity();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Mock class for testing
|
|
abstract class AlbumActivityInternal extends _$AlbumActivity {}
|