mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 15:53:32 +00:00
Wire profile into services when created for each profile rather than looking up "active profile" each time
This commit is contained in:
parent
330a19692f
commit
ae5916cc84
8 changed files with 109 additions and 106 deletions
|
@ -25,7 +25,6 @@ import 'services/follow_requests_manager.dart';
|
||||||
import 'services/gallery_service.dart';
|
import 'services/gallery_service.dart';
|
||||||
import 'services/hashtag_service.dart';
|
import 'services/hashtag_service.dart';
|
||||||
import 'services/interactions_manager.dart';
|
import 'services/interactions_manager.dart';
|
||||||
import 'services/media_upload_attachment_helper.dart';
|
|
||||||
import 'services/network_status_service.dart';
|
import 'services/network_status_service.dart';
|
||||||
import 'services/notifications_manager.dart';
|
import 'services/notifications_manager.dart';
|
||||||
import 'services/persistent_info_service.dart';
|
import 'services/persistent_info_service.dart';
|
||||||
|
@ -95,13 +94,14 @@ Future<void> dependencyInjectionInitialization() async {
|
||||||
));
|
));
|
||||||
|
|
||||||
getIt.registerSingleton<ActiveProfileSelector<GalleryService>>(
|
getIt.registerSingleton<ActiveProfileSelector<GalleryService>>(
|
||||||
ActiveProfileSelector((p) => GalleryService())
|
ActiveProfileSelector((p) => GalleryService(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<EntryManagerService>>(
|
getIt.registerSingleton<ActiveProfileSelector<EntryManagerService>>(
|
||||||
ActiveProfileSelector((p) => EntryManagerService())
|
ActiveProfileSelector((p) => EntryManagerService(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<TimelineManager>>(
|
getIt.registerSingleton<ActiveProfileSelector<TimelineManager>>(
|
||||||
ActiveProfileSelector((p) => TimelineManager(
|
ActiveProfileSelector((p) => TimelineManager(
|
||||||
|
p,
|
||||||
getIt<ActiveProfileSelector<IGroupsRepo>>().getForProfile(p).value,
|
getIt<ActiveProfileSelector<IGroupsRepo>>().getForProfile(p).value,
|
||||||
getIt<ActiveProfileSelector<EntryManagerService>>()
|
getIt<ActiveProfileSelector<EntryManagerService>>()
|
||||||
.getForProfile(p)
|
.getForProfile(p)
|
||||||
|
@ -109,21 +109,18 @@ Future<void> dependencyInjectionInitialization() async {
|
||||||
))
|
))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<NotificationsManager>>(
|
getIt.registerSingleton<ActiveProfileSelector<NotificationsManager>>(
|
||||||
ActiveProfileSelector((_) => NotificationsManager())
|
ActiveProfileSelector((p) => NotificationsManager(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<FollowRequestsManager>>(
|
getIt.registerSingleton<ActiveProfileSelector<FollowRequestsManager>>(
|
||||||
ActiveProfileSelector((_) => FollowRequestsManager())
|
ActiveProfileSelector((p) => FollowRequestsManager(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<DirectMessageService>>(
|
getIt.registerSingleton<ActiveProfileSelector<DirectMessageService>>(
|
||||||
ActiveProfileSelector((p) => DirectMessageService())
|
ActiveProfileSelector((p) => DirectMessageService(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
getIt.registerSingleton<ActiveProfileSelector<InteractionsManager>>(
|
getIt.registerSingleton<ActiveProfileSelector<InteractionsManager>>(
|
||||||
ActiveProfileSelector((p) => InteractionsManager())
|
ActiveProfileSelector((p) => InteractionsManager(p))
|
||||||
..subscribeToProfileSwaps());
|
..subscribeToProfileSwaps());
|
||||||
|
|
||||||
getIt.registerLazySingleton<MediaUploadAttachmentHelper>(
|
|
||||||
() => MediaUploadAttachmentHelper());
|
|
||||||
|
|
||||||
setupUpdateTimers();
|
setupUpdateTimers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,26 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:relatica/models/auth/oauth_credentials.dart';
|
|
||||||
import 'package:relatica/services/feature_version_checker.dart';
|
|
||||||
import 'package:result_monad/result_monad.dart';
|
import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../friendica_client/friendica_client.dart';
|
import '../friendica_client/friendica_client.dart';
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
import '../models/auth/oauth_credentials.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/connection.dart';
|
import '../models/connection.dart';
|
||||||
import '../models/direct_message.dart';
|
import '../models/direct_message.dart';
|
||||||
import '../models/direct_message_thread.dart';
|
import '../models/direct_message_thread.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import 'auth_service.dart';
|
import 'feature_version_checker.dart';
|
||||||
|
|
||||||
class DirectMessageService extends ChangeNotifier {
|
class DirectMessageService extends ChangeNotifier {
|
||||||
static final _logger = Logger('$DirectMessageService');
|
static final _logger = Logger('$DirectMessageService');
|
||||||
final _threads = <String, DirectMessageThread>{};
|
final _threads = <String, DirectMessageThread>{};
|
||||||
|
final Profile profile;
|
||||||
var _firstLoading = true;
|
var _firstLoading = true;
|
||||||
|
|
||||||
|
DirectMessageService(this.profile);
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_threads.clear();
|
_threads.clear();
|
||||||
_firstLoading = true;
|
_firstLoading = true;
|
||||||
|
@ -47,9 +50,7 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateThreads() async {
|
Future<void> updateThreads() async {
|
||||||
await DirectMessagingClient(getIt<AccountsService>().currentProfile)
|
await DirectMessagingClient(profile).getDirectMessages(PagingData()).match(
|
||||||
.getDirectMessages(PagingData())
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
final newThreads = DirectMessageThread.createThreads(update);
|
final newThreads = DirectMessageThread.createThreads(update);
|
||||||
_threads.clear();
|
_threads.clear();
|
||||||
|
@ -71,7 +72,6 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<DirectMessage, ExecError> newThread(
|
FutureResult<DirectMessage, ExecError> newThread(
|
||||||
Connection receiver, String text) async {
|
Connection receiver, String text) async {
|
||||||
final profile = getIt<AccountsService>().currentProfile;
|
|
||||||
if (profile.credentials is OAuthCredentials) {
|
if (profile.credentials is OAuthCredentials) {
|
||||||
final result = getIt<FriendicaVersionChecker>()
|
final result = getIt<FriendicaVersionChecker>()
|
||||||
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
|
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
|
||||||
|
@ -118,7 +118,6 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final profile = getIt<AccountsService>().currentProfile;
|
|
||||||
if (profile.credentials is OAuthCredentials) {
|
if (profile.credentials is OAuthCredentials) {
|
||||||
final result = getIt<FriendicaVersionChecker>()
|
final result = getIt<FriendicaVersionChecker>()
|
||||||
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
|
.canUseFeatureResult(RelaticaFeatures.directMessageCreation);
|
||||||
|
@ -154,9 +153,7 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await DirectMessagingClient(getIt<AccountsService>().currentProfile)
|
await DirectMessagingClient(profile).markDirectMessageRead(m).match(
|
||||||
.markDirectMessageRead(m)
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
thread.messages.removeAt(oldIndex);
|
thread.messages.removeAt(oldIndex);
|
||||||
thread.messages.insert(oldIndex, update);
|
thread.messages.insert(oldIndex, update);
|
||||||
|
|
|
@ -7,13 +7,13 @@ import '../friendica_client/friendica_client.dart';
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import '../models/TimelineIdentifiers.dart';
|
import '../models/TimelineIdentifiers.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/entry_tree_item.dart';
|
import '../models/entry_tree_item.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../models/image_entry.dart';
|
import '../models/image_entry.dart';
|
||||||
import '../models/media_attachment_uploads/new_entry_media_items.dart';
|
import '../models/media_attachment_uploads/new_entry_media_items.dart';
|
||||||
import '../models/timeline_entry.dart';
|
import '../models/timeline_entry.dart';
|
||||||
import '../models/visibility.dart';
|
import '../models/visibility.dart';
|
||||||
import 'auth_service.dart';
|
|
||||||
import 'feature_version_checker.dart';
|
import 'feature_version_checker.dart';
|
||||||
import 'media_upload_attachment_helper.dart';
|
import 'media_upload_attachment_helper.dart';
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
final _entries = <String, TimelineEntry>{};
|
final _entries = <String, TimelineEntry>{};
|
||||||
final _parentPostIds = <String, String>{};
|
final _parentPostIds = <String, String>{};
|
||||||
final _postNodes = <String, _Node>{};
|
final _postNodes = <String, _Node>{};
|
||||||
|
final Profile profile;
|
||||||
|
|
||||||
|
EntryManagerService(this.profile);
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_entries.clear();
|
_entries.clear();
|
||||||
|
@ -46,7 +49,6 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
Result<EntryTreeItem, ExecError> getPostTreeEntryBy(String id) {
|
Result<EntryTreeItem, ExecError> getPostTreeEntryBy(String id) {
|
||||||
_logger.finest('Getting post: $id');
|
_logger.finest('Getting post: $id');
|
||||||
final idForCall = mapInteractionId(id);
|
final idForCall = mapInteractionId(id);
|
||||||
final currentId = getIt<AccountsService>().currentProfile.userId;
|
|
||||||
final postNode = _getPostRootNode(idForCall);
|
final postNode = _getPostRootNode(idForCall);
|
||||||
if (postNode == null) {
|
if (postNode == null) {
|
||||||
return Result.error(ExecError(
|
return Result.error(ExecError(
|
||||||
|
@ -55,7 +57,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.ok(_nodeToTreeItem(postNode, currentId));
|
return Result.ok(_nodeToTreeItem(postNode, profile.userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<TimelineEntry, ExecError> getEntryById(String id) {
|
Result<TimelineEntry, ExecError> getEntryById(String id) {
|
||||||
|
@ -71,8 +73,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<bool, ExecError> deleteEntryById(String id) async {
|
FutureResult<bool, ExecError> deleteEntryById(String id) async {
|
||||||
_logger.finest('Delete entry: $id');
|
_logger.finest('Delete entry: $id');
|
||||||
final result = await StatusesClient(getIt<AccountsService>().currentProfile)
|
final result = await StatusesClient(profile).deleteEntryById(id);
|
||||||
.deleteEntryById(id);
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -116,8 +117,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
item.localFilePath,
|
item.localFilePath,
|
||||||
).andThenAsync(
|
).andThenAsync(
|
||||||
(imageBytes) async =>
|
(imageBytes) async =>
|
||||||
await RemoteFileClient(getIt<AccountsService>().currentProfile)
|
await RemoteFileClient(profile).uploadFileAsAttachment(
|
||||||
.uploadFileAsAttachment(
|
|
||||||
bytes: imageBytes,
|
bytes: imageBytes,
|
||||||
album: mediaItems.albumName,
|
album: mediaItems.albumName,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
|
@ -134,7 +134,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await StatusesClient(getIt<AccountsService>().currentProfile)
|
final result = await StatusesClient(profile)
|
||||||
.createNewStatus(
|
.createNewStatus(
|
||||||
text: text,
|
text: text,
|
||||||
spoilerText: spoilerText,
|
spoilerText: spoilerText,
|
||||||
|
@ -142,8 +142,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
mediaIds: mediaIds,
|
mediaIds: mediaIds,
|
||||||
visibility: visibility)
|
visibility: visibility)
|
||||||
.andThenSuccessAsync((item) async {
|
.andThenSuccessAsync((item) async {
|
||||||
await processNewItems(
|
await processNewItems([item], profile.username, null);
|
||||||
[item], getIt<AccountsService>().currentProfile.username, null);
|
|
||||||
return item;
|
return item;
|
||||||
}).andThenSuccessAsync((item) async {
|
}).andThenSuccessAsync((item) async {
|
||||||
if (inReplyToId.isNotEmpty) {
|
if (inReplyToId.isNotEmpty) {
|
||||||
|
@ -208,14 +207,13 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
await MediaUploadAttachmentHelper.getUploadableImageBytes(
|
await MediaUploadAttachmentHelper.getUploadableImageBytes(
|
||||||
item.localFilePath,
|
item.localFilePath,
|
||||||
).andThenAsync(
|
).andThenAsync(
|
||||||
(imageBytes) async =>
|
(imageBytes) async => await RemoteFileClient(profile)
|
||||||
await RemoteFileClient(getIt<AccountsService>().currentProfile)
|
.uploadFileAsAttachment(
|
||||||
.uploadFileAsAttachment(
|
bytes: imageBytes,
|
||||||
bytes: imageBytes,
|
album: mediaItems.albumName,
|
||||||
album: mediaItems.albumName,
|
description: item.description,
|
||||||
description: item.description,
|
fileName: filename,
|
||||||
fileName: filename,
|
visibility: newMediaItemVisibility),
|
||||||
visibility: newMediaItemVisibility),
|
|
||||||
);
|
);
|
||||||
if (uploadResult.isSuccess) {
|
if (uploadResult.isSuccess) {
|
||||||
mediaIds.add(uploadResult.value.scales.first.id);
|
mediaIds.add(uploadResult.value.scales.first.id);
|
||||||
|
@ -226,15 +224,14 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await StatusesClient(getIt<AccountsService>().currentProfile)
|
final result = await StatusesClient(profile)
|
||||||
.editStatus(
|
.editStatus(
|
||||||
id: idForCall,
|
id: idForCall,
|
||||||
text: text,
|
text: text,
|
||||||
spoilerText: spoilerText,
|
spoilerText: spoilerText,
|
||||||
mediaIds: mediaIds)
|
mediaIds: mediaIds)
|
||||||
.andThenSuccessAsync((item) async {
|
.andThenSuccessAsync((item) async {
|
||||||
await processNewItems(
|
await processNewItems([item], profile.username, null);
|
||||||
[item], getIt<AccountsService>().currentProfile.username, null);
|
|
||||||
return item;
|
return item;
|
||||||
}).andThenSuccessAsync((item) async {
|
}).andThenSuccessAsync((item) async {
|
||||||
final inReplyToId = item.parentId;
|
final inReplyToId = item.parentId;
|
||||||
|
@ -267,7 +264,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
FutureResult<List<EntryTreeItem>, ExecError> updateTimeline(
|
FutureResult<List<EntryTreeItem>, ExecError> updateTimeline(
|
||||||
TimelineIdentifiers type, int maxId, int sinceId) async {
|
TimelineIdentifiers type, int maxId, int sinceId) async {
|
||||||
_logger.fine(() => 'Updating timeline');
|
_logger.fine(() => 'Updating timeline');
|
||||||
final client = TimelineClient(getIt<AccountsService>().currentProfile);
|
final client = TimelineClient(profile);
|
||||||
final itemsResult = await client.getTimeline(
|
final itemsResult = await client.getTimeline(
|
||||||
type: type,
|
type: type,
|
||||||
page: PagingData(
|
page: PagingData(
|
||||||
|
@ -282,7 +279,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
itemsResult.value.sort((t1, t2) => t1.id.compareTo(t2.id));
|
itemsResult.value.sort((t1, t2) => t1.id.compareTo(t2.id));
|
||||||
final updatedPosts =
|
final updatedPosts =
|
||||||
await processNewItems(itemsResult.value, client.profile.userId, client);
|
await processNewItems(itemsResult.value, profile.userId, client);
|
||||||
_logger.finest(() {
|
_logger.finest(() {
|
||||||
final postCount = _entries.values.where((e) => e.parentId.isEmpty).length;
|
final postCount = _entries.values.where((e) => e.parentId.isEmpty).length;
|
||||||
final commentCount = _entries.length - postCount;
|
final commentCount = _entries.length - postCount;
|
||||||
|
@ -323,7 +320,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final o in orphans) {
|
for (final o in orphans) {
|
||||||
await StatusesClient(getIt<AccountsService>().currentProfile)
|
await StatusesClient(profile)
|
||||||
.getPostOrComment(o.id, fullContext: true)
|
.getPostOrComment(o.id, fullContext: true)
|
||||||
.andThenSuccessAsync((items) async {
|
.andThenSuccessAsync((items) async {
|
||||||
final parentPostId = items.firstWhere((e) => e.parentId.isEmpty).id;
|
final parentPostId = items.firstWhere((e) => e.parentId.isEmpty).id;
|
||||||
|
@ -417,13 +414,13 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<EntryTreeItem, ExecError> refreshStatusChain(String id) async {
|
FutureResult<EntryTreeItem, ExecError> refreshStatusChain(String id) async {
|
||||||
_logger.finest('Refreshing post: $id');
|
_logger.finest('Refreshing post: $id');
|
||||||
final client = StatusesClient(getIt<AccountsService>().currentProfile);
|
final client = StatusesClient(profile);
|
||||||
final idForCall = mapInteractionId(id);
|
final idForCall = mapInteractionId(id);
|
||||||
var parentId = '';
|
var parentId = '';
|
||||||
final result = await client
|
final result = await client
|
||||||
.getPostOrComment(idForCall, fullContext: false)
|
.getPostOrComment(idForCall, fullContext: false)
|
||||||
.withResult((entries) =>
|
.withResult((entries) =>
|
||||||
parentId = entries.isEmpty ? '' : entries.first.parentId ?? '')
|
parentId = entries.isEmpty ? '' : entries.first.parentId)
|
||||||
.andThenAsync((rootItems) async => await client
|
.andThenAsync((rootItems) async => await client
|
||||||
.getPostOrComment(idForCall, fullContext: true)
|
.getPostOrComment(idForCall, fullContext: true)
|
||||||
.andThenSuccessAsync(
|
.andThenSuccessAsync(
|
||||||
|
@ -439,7 +436,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
await client
|
await client
|
||||||
.getPostOrComment(parentIdForCall, fullContext: false)
|
.getPostOrComment(parentIdForCall, fullContext: false)
|
||||||
.withResult((entries) =>
|
.withResult((entries) =>
|
||||||
parentId = entries.isEmpty ? '' : entries.first.parentId ?? '')
|
parentId = entries.isEmpty ? '' : entries.first.parentId)
|
||||||
.andThenAsync((rootItems) async => await client
|
.andThenAsync((rootItems) async => await client
|
||||||
.getPostOrComment(idForCall, fullContext: true)
|
.getPostOrComment(idForCall, fullContext: true)
|
||||||
.transformAsync(
|
.transformAsync(
|
||||||
|
@ -464,7 +461,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<EntryTreeItem, ExecError> resharePost(String id) async {
|
FutureResult<EntryTreeItem, ExecError> resharePost(String id) async {
|
||||||
_logger.finest('Resharing post: $id');
|
_logger.finest('Resharing post: $id');
|
||||||
final client = StatusesClient(getIt<AccountsService>().currentProfile);
|
final client = StatusesClient(profile);
|
||||||
final idForCall = mapInteractionId(id);
|
final idForCall = mapInteractionId(id);
|
||||||
final result =
|
final result =
|
||||||
await client.resharePost(idForCall).andThenSuccessAsync((item) async {
|
await client.resharePost(idForCall).andThenSuccessAsync((item) async {
|
||||||
|
@ -487,7 +484,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<bool, ExecError> unResharePost(String id) async {
|
FutureResult<bool, ExecError> unResharePost(String id) async {
|
||||||
_logger.finest('Unresharing post: $id');
|
_logger.finest('Unresharing post: $id');
|
||||||
final client = StatusesClient(getIt<AccountsService>().currentProfile);
|
final client = StatusesClient(profile);
|
||||||
final idForCall = mapInteractionId(id);
|
final idForCall = mapInteractionId(id);
|
||||||
final result =
|
final result =
|
||||||
await client.unResharePost(idForCall).andThenSuccessAsync((item) async {
|
await client.unResharePost(idForCall).andThenSuccessAsync((item) async {
|
||||||
|
@ -506,7 +503,6 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<EntryTreeItem, ExecError> toggleFavorited(
|
FutureResult<EntryTreeItem, ExecError> toggleFavorited(
|
||||||
String id, bool newStatus) async {
|
String id, bool newStatus) async {
|
||||||
final profile = getIt<AccountsService>().currentProfile;
|
|
||||||
final interactionClient = InteractionsClient(profile);
|
final interactionClient = InteractionsClient(profile);
|
||||||
final postsClient = StatusesClient(profile);
|
final postsClient = StatusesClient(profile);
|
||||||
final idForCall = mapInteractionId(id);
|
final idForCall = mapInteractionId(id);
|
||||||
|
|
|
@ -6,15 +6,17 @@ import 'package:result_monad/result_monad.dart';
|
||||||
import '../friendica_client/friendica_client.dart';
|
import '../friendica_client/friendica_client.dart';
|
||||||
import '../friendica_client/paged_response.dart';
|
import '../friendica_client/paged_response.dart';
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
import '../globals.dart';
|
import '../models/auth/profile.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../models/follow_request.dart';
|
import '../models/follow_request.dart';
|
||||||
import 'auth_service.dart';
|
|
||||||
|
|
||||||
class FollowRequestsManager extends ChangeNotifier {
|
class FollowRequestsManager extends ChangeNotifier {
|
||||||
static const maxIterations = 20;
|
static const maxIterations = 20;
|
||||||
|
final Profile profile;
|
||||||
final _requests = <String, FollowRequest>{};
|
final _requests = <String, FollowRequest>{};
|
||||||
|
|
||||||
|
FollowRequestsManager(this.profile);
|
||||||
|
|
||||||
List<FollowRequest> get requests => UnmodifiableListView(_requests.values);
|
List<FollowRequest> get requests => UnmodifiableListView(_requests.values);
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
@ -56,9 +58,7 @@ class FollowRequestsManager extends ChangeNotifier {
|
||||||
if (page == null) {
|
if (page == null) {
|
||||||
return buildErrorResult(type: ErrorType.rangeError);
|
return buildErrorResult(type: ErrorType.rangeError);
|
||||||
}
|
}
|
||||||
final result =
|
final result = await RelationshipsClient(profile).getFollowRequests(page);
|
||||||
await RelationshipsClient(getIt<AccountsService>().currentProfile)
|
|
||||||
.getFollowRequests(page);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,10 @@ import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../friendica_client/friendica_client.dart';
|
import '../friendica_client/friendica_client.dart';
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
import '../globals.dart';
|
import '../models/auth/profile.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../models/gallery_data.dart';
|
import '../models/gallery_data.dart';
|
||||||
import '../models/image_entry.dart';
|
import '../models/image_entry.dart';
|
||||||
import 'auth_service.dart';
|
|
||||||
|
|
||||||
class GalleryService extends ChangeNotifier {
|
class GalleryService extends ChangeNotifier {
|
||||||
static const IMAGES_PER_PAGE = 50;
|
static const IMAGES_PER_PAGE = 50;
|
||||||
|
@ -16,6 +15,10 @@ class GalleryService extends ChangeNotifier {
|
||||||
final _images = <String, Set<ImageEntry>>{};
|
final _images = <String, Set<ImageEntry>>{};
|
||||||
var _loaded = false;
|
var _loaded = false;
|
||||||
|
|
||||||
|
final Profile profile;
|
||||||
|
|
||||||
|
GalleryService(this.profile);
|
||||||
|
|
||||||
bool get loaded => _loaded;
|
bool get loaded => _loaded;
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
@ -48,8 +51,7 @@ class GalleryService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<List<GalleryData>, ExecError> updateGalleries() async {
|
FutureResult<List<GalleryData>, ExecError> updateGalleries() async {
|
||||||
final result = await GalleryClient(getIt<AccountsService>().currentProfile)
|
final result = await GalleryClient(profile).getGalleryData();
|
||||||
.getGalleryData();
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -99,8 +101,7 @@ class GalleryService extends ChangeNotifier {
|
||||||
final pagesToUse = nextPageOnly ? [pages.last] : pages;
|
final pagesToUse = nextPageOnly ? [pages.last] : pages;
|
||||||
for (final page in pagesToUse) {
|
for (final page in pagesToUse) {
|
||||||
final result =
|
final result =
|
||||||
await GalleryClient(getIt<AccountsService>().currentProfile)
|
await GalleryClient(profile).getGalleryImages(galleryName, page);
|
||||||
.getGalleryImages(galleryName, page);
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,20 @@ import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../friendica_client/friendica_client.dart';
|
import '../friendica_client/friendica_client.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/connection.dart';
|
import '../models/connection.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../utils/active_profile_selector.dart';
|
import '../utils/active_profile_selector.dart';
|
||||||
import 'auth_service.dart';
|
|
||||||
import 'entry_manager_service.dart';
|
import 'entry_manager_service.dart';
|
||||||
|
|
||||||
class InteractionsManager extends ChangeNotifier {
|
class InteractionsManager extends ChangeNotifier {
|
||||||
final _likesByStatusId = <String, List<Connection>>{};
|
final _likesByStatusId = <String, List<Connection>>{};
|
||||||
final _resharesByStatusId = <String, List<Connection>>{};
|
final _resharesByStatusId = <String, List<Connection>>{};
|
||||||
|
|
||||||
|
final Profile profile;
|
||||||
|
|
||||||
|
InteractionsManager(this.profile);
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_likesByStatusId.clear();
|
_likesByStatusId.clear();
|
||||||
_resharesByStatusId.clear();
|
_resharesByStatusId.clear();
|
||||||
|
@ -40,9 +44,7 @@ class InteractionsManager extends ChangeNotifier {
|
||||||
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
|
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
|
||||||
String statusId) async {
|
String statusId) async {
|
||||||
final idForCall = _mapStatusId(statusId);
|
final idForCall = _mapStatusId(statusId);
|
||||||
final likesResult =
|
final likesResult = await InteractionsClient(profile).getLikes(idForCall);
|
||||||
await InteractionsClient(getIt<AccountsService>().currentProfile)
|
|
||||||
.getLikes(idForCall);
|
|
||||||
if (likesResult.isSuccess) {
|
if (likesResult.isSuccess) {
|
||||||
_likesByStatusId[statusId] = likesResult.value;
|
_likesByStatusId[statusId] = likesResult.value;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -54,8 +56,7 @@ class InteractionsManager extends ChangeNotifier {
|
||||||
String statusId) async {
|
String statusId) async {
|
||||||
final idForCall = _mapStatusId(statusId);
|
final idForCall = _mapStatusId(statusId);
|
||||||
final resharesResult =
|
final resharesResult =
|
||||||
await InteractionsClient(getIt<AccountsService>().currentProfile)
|
await InteractionsClient(profile).getReshares(idForCall);
|
||||||
.getReshares(idForCall);
|
|
||||||
if (resharesResult.isSuccess) {
|
if (resharesResult.isSuccess) {
|
||||||
_resharesByStatusId[statusId] = resharesResult.value;
|
_resharesByStatusId[statusId] = resharesResult.value;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -65,7 +66,7 @@ class InteractionsManager extends ChangeNotifier {
|
||||||
|
|
||||||
String _mapStatusId(String statusId) {
|
String _mapStatusId(String statusId) {
|
||||||
return getIt<ActiveProfileSelector<EntryManagerService>>()
|
return getIt<ActiveProfileSelector<EntryManagerService>>()
|
||||||
.activeEntry
|
.getForProfile(profile)
|
||||||
.transform((m) => m.mapInteractionId(statusId))
|
.transform((m) => m.mapInteractionId(statusId))
|
||||||
.getValueOrElse(() => statusId);
|
.getValueOrElse(() => statusId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import '../friendica_client/paged_response.dart';
|
||||||
import '../friendica_client/pages_manager.dart';
|
import '../friendica_client/pages_manager.dart';
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../models/user_notification.dart';
|
import '../models/user_notification.dart';
|
||||||
import '../serializers/mastodon/follow_request_mastodon_extensions.dart';
|
import '../serializers/mastodon/follow_request_mastodon_extensions.dart';
|
||||||
|
@ -20,16 +21,20 @@ import 'network_status_service.dart';
|
||||||
|
|
||||||
class NotificationsManager extends ChangeNotifier {
|
class NotificationsManager extends ChangeNotifier {
|
||||||
static final _logger = Logger('NotificationManager');
|
static final _logger = Logger('NotificationManager');
|
||||||
|
late final PagesManager<List<UserNotification>, String> _pm;
|
||||||
|
final Profile profile;
|
||||||
final dms = <UserNotification>[];
|
final dms = <UserNotification>[];
|
||||||
final connectionRequests = <UserNotification>[];
|
final connectionRequests = <UserNotification>[];
|
||||||
final unread = <UserNotification>[];
|
final unread = <UserNotification>[];
|
||||||
final read = <UserNotification>[];
|
final read = <UserNotification>[];
|
||||||
|
|
||||||
final _pm = PagesManager<List<UserNotification>, String>(
|
NotificationsManager(this.profile) {
|
||||||
idMapper: (nn) => nn.map((n) => n.id).toList(),
|
_pm = PagesManager<List<UserNotification>, String>(
|
||||||
onRequest: _clientGetNotificationsRequest,
|
idMapper: (nn) => nn.map((n) => n.id).toList(),
|
||||||
);
|
onRequest: (pd) async =>
|
||||||
|
await _clientGetNotificationsRequest(profile, pd));
|
||||||
|
}
|
||||||
|
|
||||||
var _firstLoad = true;
|
var _firstLoad = true;
|
||||||
|
|
||||||
List<UserNotification> get notifications {
|
List<UserNotification> get notifications {
|
||||||
|
@ -68,13 +73,19 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
PagingData? pd;
|
PagingData? pd;
|
||||||
bool initializedFirstPage = false;
|
bool initializedFirstPage = false;
|
||||||
if (page.next != null) {
|
if (page.next != null) {
|
||||||
final response = await _clientGetNotificationsRequest(page.next!);
|
final response = await _clientGetNotificationsRequest(
|
||||||
|
profile,
|
||||||
|
page.next!,
|
||||||
|
);
|
||||||
response.match(
|
response.match(
|
||||||
onSuccess: (response) => pd = response.previous,
|
onSuccess: (response) => pd = response.previous,
|
||||||
onError: (error) =>
|
onError: (error) =>
|
||||||
_logger.severe('Error getting previous page: $error'));
|
_logger.severe('Error getting previous page: $error'));
|
||||||
if (pd != null) {
|
if (pd != null) {
|
||||||
final response = await _clientGetNotificationsRequest(pd!);
|
final response = await _clientGetNotificationsRequest(
|
||||||
|
profile,
|
||||||
|
pd!,
|
||||||
|
);
|
||||||
response.match(
|
response.match(
|
||||||
onSuccess: (response) {
|
onSuccess: (response) {
|
||||||
initializedFirstPage = true;
|
initializedFirstPage = true;
|
||||||
|
@ -84,13 +95,16 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
_logger.severe('Error getting previous page: $error'));
|
_logger.severe('Error getting previous page: $error'));
|
||||||
} else if (pd == null && page.previous != null) {
|
} else if (pd == null && page.previous != null) {
|
||||||
final response = await _clientGetNotificationsRequest(
|
final response = await _clientGetNotificationsRequest(
|
||||||
page.previous!)
|
profile,
|
||||||
.andThenAsync((previousData) async => previousData.next !=
|
page.previous!,
|
||||||
null
|
).andThenAsync((previousData) async => previousData.next != null
|
||||||
? await _clientGetNotificationsRequest(previousData.next!)
|
? await _clientGetNotificationsRequest(
|
||||||
: buildErrorResult(
|
profile,
|
||||||
type: ErrorType.rangeError,
|
previousData.next!,
|
||||||
message: 'No "next" page from previous data either'));
|
)
|
||||||
|
: buildErrorResult(
|
||||||
|
type: ErrorType.rangeError,
|
||||||
|
message: 'No "next" page from previous data either'));
|
||||||
response.match(
|
response.match(
|
||||||
onSuccess: (response) {
|
onSuccess: (response) {
|
||||||
initializedFirstPage = true;
|
initializedFirstPage = true;
|
||||||
|
@ -125,7 +139,10 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final response = await _clientGetNotificationsRequest(page.next!);
|
final response = await _clientGetNotificationsRequest(
|
||||||
|
profile,
|
||||||
|
page.next!,
|
||||||
|
);
|
||||||
response.match(
|
response.match(
|
||||||
onSuccess: (response) =>
|
onSuccess: (response) =>
|
||||||
notificationsFromRefresh.addAll(response.data),
|
notificationsFromRefresh.addAll(response.data),
|
||||||
|
@ -136,16 +153,16 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
|
|
||||||
getIt<NetworkStatusService>().startNotificationUpdate();
|
getIt<NetworkStatusService>().startNotificationUpdate();
|
||||||
await getIt<ActiveProfileSelector<DirectMessageService>>()
|
await getIt<ActiveProfileSelector<DirectMessageService>>()
|
||||||
.activeEntry
|
.getForProfile(profile)
|
||||||
.andThenSuccessAsync((dms) async => await dms.updateThreads());
|
.transformAsync((dms) async => await dms.updateThreads());
|
||||||
|
|
||||||
final useActualRequests = getIt<FriendicaVersionChecker>()
|
final useActualRequests = getIt<FriendicaVersionChecker>()
|
||||||
.canUseFeature(RelaticaFeatures.usingActualFollowRequests);
|
.canUseFeature(RelaticaFeatures.usingActualFollowRequests);
|
||||||
|
|
||||||
if (useActualRequests) {
|
if (useActualRequests) {
|
||||||
await getIt<ActiveProfileSelector<FollowRequestsManager>>()
|
await getIt<ActiveProfileSelector<FollowRequestsManager>>()
|
||||||
.activeEntry
|
.getForProfile(profile)
|
||||||
.andThenSuccessAsync((fm) async => fm.update());
|
.transformAsync((fm) async => fm.update());
|
||||||
}
|
}
|
||||||
|
|
||||||
final notifications = <String, UserNotification>{};
|
final notifications = <String, UserNotification>{};
|
||||||
|
@ -207,8 +224,7 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<bool, ExecError> markSeen(UserNotification notification) async {
|
FutureResult<bool, ExecError> markSeen(UserNotification notification) async {
|
||||||
final result =
|
final result =
|
||||||
await NotificationsClient(getIt<AccountsService>().currentProfile)
|
await NotificationsClient(profile).clearNotification(notification);
|
||||||
.clearNotification(notification);
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -230,10 +246,10 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
|
|
||||||
List<UserNotification> buildUnreadMessageNotifications(
|
List<UserNotification> buildUnreadMessageNotifications(
|
||||||
bool useActualRequests) {
|
bool useActualRequests) {
|
||||||
final myId = getIt<AccountsService>().currentProfile.userId;
|
final myId = profile.userId;
|
||||||
final dmsResult = getIt<ActiveProfileSelector<DirectMessageService>>()
|
final dmsResult = getIt<ActiveProfileSelector<DirectMessageService>>()
|
||||||
.activeEntry
|
.getForProfile(profile)
|
||||||
.andThenSuccess((d) => d.getThreads(unreadyOnly: true).map((t) {
|
.transform((d) => d.getThreads(unreadyOnly: true).map((t) {
|
||||||
final fromAccount =
|
final fromAccount =
|
||||||
t.participants.firstWhere((p) => p.id != myId);
|
t.participants.firstWhere((p) => p.id != myId);
|
||||||
final latestMessage = t.messages
|
final latestMessage = t.messages
|
||||||
|
@ -255,8 +271,8 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
final followRequestResult = !useActualRequests
|
final followRequestResult = !useActualRequests
|
||||||
? []
|
? []
|
||||||
: getIt<ActiveProfileSelector<FollowRequestsManager>>()
|
: getIt<ActiveProfileSelector<FollowRequestsManager>>()
|
||||||
.activeEntry
|
.getForProfile(profile)
|
||||||
.andThenSuccess(
|
.transform(
|
||||||
(fm) => fm.requests.map((r) => r.toUserNotification()).toList())
|
(fm) => fm.requests.map((r) => r.toUserNotification()).toList())
|
||||||
.getValueOrElse(() => []);
|
.getValueOrElse(() => []);
|
||||||
|
|
||||||
|
@ -300,10 +316,7 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
static FutureResult<PagedResponse<List<UserNotification>>, ExecError>
|
static FutureResult<PagedResponse<List<UserNotification>>, ExecError>
|
||||||
_clientGetNotificationsRequest(PagingData page) async {
|
_clientGetNotificationsRequest(Profile profile, PagingData page) async {
|
||||||
final result =
|
return NotificationsClient(profile).getNotifications(page);
|
||||||
await NotificationsClient(getIt<AccountsService>().currentProfile)
|
|
||||||
.getNotifications(page);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../data/interfaces/groups_repo.intf.dart';
|
import '../data/interfaces/groups_repo.intf.dart';
|
||||||
import '../friendica_client/friendica_client.dart';
|
import '../friendica_client/friendica_client.dart';
|
||||||
import '../globals.dart';
|
|
||||||
import '../models/TimelineIdentifiers.dart';
|
import '../models/TimelineIdentifiers.dart';
|
||||||
|
import '../models/auth/profile.dart';
|
||||||
import '../models/entry_tree_item.dart';
|
import '../models/entry_tree_item.dart';
|
||||||
import '../models/exec_error.dart';
|
import '../models/exec_error.dart';
|
||||||
import '../models/group_data.dart';
|
import '../models/group_data.dart';
|
||||||
|
@ -14,7 +14,6 @@ import '../models/media_attachment_uploads/new_entry_media_items.dart';
|
||||||
import '../models/timeline.dart';
|
import '../models/timeline.dart';
|
||||||
import '../models/timeline_entry.dart';
|
import '../models/timeline_entry.dart';
|
||||||
import '../models/visibility.dart';
|
import '../models/visibility.dart';
|
||||||
import 'auth_service.dart';
|
|
||||||
import 'entry_manager_service.dart';
|
import 'entry_manager_service.dart';
|
||||||
|
|
||||||
enum TimelineRefreshType {
|
enum TimelineRefreshType {
|
||||||
|
@ -29,10 +28,11 @@ class TimelineManager extends ChangeNotifier {
|
||||||
final IGroupsRepo groupsRepo;
|
final IGroupsRepo groupsRepo;
|
||||||
final EntryManagerService entryManagerService;
|
final EntryManagerService entryManagerService;
|
||||||
var groupsNotInitialized = true;
|
var groupsNotInitialized = true;
|
||||||
|
final Profile profile;
|
||||||
|
|
||||||
final cachedTimelines = <TimelineIdentifiers, Timeline>{};
|
final cachedTimelines = <TimelineIdentifiers, Timeline>{};
|
||||||
|
|
||||||
TimelineManager(this.groupsRepo, this.entryManagerService);
|
TimelineManager(this.profile, this.groupsRepo, this.entryManagerService);
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
groupsNotInitialized = true;
|
groupsNotInitialized = true;
|
||||||
|
@ -54,9 +54,7 @@ class TimelineManager extends ChangeNotifier {
|
||||||
|
|
||||||
Future<void> _refreshGroupData() async {
|
Future<void> _refreshGroupData() async {
|
||||||
_logger.finest('Refreshing member group data ');
|
_logger.finest('Refreshing member group data ');
|
||||||
await GroupsClient(getIt<AccountsService>().currentProfile)
|
await GroupsClient(profile).getGroups().match(
|
||||||
.getGroups()
|
|
||||||
.match(
|
|
||||||
onSuccess: (groups) {
|
onSuccess: (groups) {
|
||||||
groupsRepo.addAllGroups(groups);
|
groupsRepo.addAllGroups(groups);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
Loading…
Reference in a new issue