mirror of
https://github.com/immich-app/immich.git
synced 2026-10-28 23:16:49 +08:00
* chore(mobile): static Store to unify and streamline reactivity * Add tests of caching and new stores * Don't instantiate PeopleDbRepository * Slight DB rename and fix throwing store methods
48 lines
1.9 KiB
Dart
48 lines
1.9 KiB
Dart
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/data/server/api_repository.dart';
|
|
import 'package:immich_mobile/infrastructure/utils/user.converter.dart';
|
|
import 'package:immich_mobile/models/activities/activity.model.dart';
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
final activityApiRepositoryProvider = Provider(
|
|
(ref) => ActivityApiRepository(ref.watch(apiServiceProvider).activitiesApi),
|
|
);
|
|
|
|
class ActivityApiRepository extends ApiRepository {
|
|
final ActivitiesApi _api;
|
|
|
|
const ActivityApiRepository(this._api);
|
|
|
|
Future<List<Activity>> getAll(String albumId, {String? assetId}) async {
|
|
final response = await checkNull(_api.getActivities(albumId, assetId: assetId));
|
|
return response.map((dto) => _toActivity(dto, albumId)).toList();
|
|
}
|
|
|
|
Future<Activity> create(String albumId, ActivityType type, {String? assetId, String? comment}) async {
|
|
final dto = ActivityCreateDto(
|
|
albumId: albumId,
|
|
type: type == ActivityType.comment ? ReactionType.comment : ReactionType.like,
|
|
assetId: assetId == null ? const Optional.absent() : Optional.present(assetId),
|
|
comment: comment == null ? const Optional.absent() : Optional.present(comment),
|
|
);
|
|
final response = await checkNull(_api.createActivity(dto));
|
|
return _toActivity(response, albumId);
|
|
}
|
|
|
|
Future<void> delete(String id) {
|
|
// TODO(agg23): I think this is a bug; `checkNull` will always throw here as the response is void (null)
|
|
return checkNull(_api.deleteActivity(id));
|
|
}
|
|
|
|
static Activity _toActivity(ActivityResponseDto dto, String albumId) => Activity(
|
|
id: dto.id,
|
|
albumId: albumId,
|
|
createdAt: dto.createdAt,
|
|
type: dto.type == ReactionType.comment ? ActivityType.comment : ActivityType.like,
|
|
user: UserConverter.fromSimpleUserDto(dto.user),
|
|
assetId: dto.assetId,
|
|
comment: dto.comment.orElse(null),
|
|
);
|
|
}
|