mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 19:23:31 +00:00
52 lines
1.5 KiB
Dart
52 lines
1.5 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:result_monad/result_monad.dart';
|
|
|
|
import '../globals.dart';
|
|
import '../models/connection.dart';
|
|
import '../models/exec_error.dart';
|
|
import 'auth_service.dart';
|
|
|
|
class InteractionsManager extends ChangeNotifier {
|
|
final _likesByStatusId = <String, List<Connection>>{};
|
|
final _resharesByStatusId = <String, List<Connection>>{};
|
|
|
|
List<Connection> getLikes(String statusId) {
|
|
if (!_likesByStatusId.containsKey(statusId)) {
|
|
updateLikesForStatus(statusId);
|
|
return [];
|
|
}
|
|
|
|
return _likesByStatusId[statusId]!;
|
|
}
|
|
|
|
List<Connection> getReshares(String statusId) {
|
|
if (!_resharesByStatusId.containsKey(statusId)) {
|
|
updateResharesForStatus(statusId);
|
|
return [];
|
|
}
|
|
|
|
return _resharesByStatusId[statusId]!;
|
|
}
|
|
|
|
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
|
|
String statusId) async {
|
|
final likesResult =
|
|
await getIt<AuthService>().currentClient.getLikes(statusId);
|
|
if (likesResult.isSuccess) {
|
|
_likesByStatusId[statusId] = likesResult.value;
|
|
notifyListeners();
|
|
}
|
|
return likesResult;
|
|
}
|
|
|
|
FutureResult<List<Connection>, ExecError> updateResharesForStatus(
|
|
String statusId) async {
|
|
final resharesResult =
|
|
await getIt<AuthService>().currentClient.getReshares(statusId);
|
|
if (resharesResult.isSuccess) {
|
|
_resharesByStatusId[statusId] = resharesResult.value;
|
|
notifyListeners();
|
|
}
|
|
return resharesResult;
|
|
}
|
|
}
|