mirror of
https://gitlab.com/mysocialportal/relatica
synced 2024-10-18 15:53:32 +00:00
Make AuthService.currentClient a non-Result type
This commit is contained in:
parent
dc0b7e7bfc
commit
a0dc28234b
11 changed files with 100 additions and 235 deletions
|
@ -53,7 +53,6 @@ Future<void> dependencyInjectionInitialization() async {
|
||||||
() => MediaUploadAttachmentHelper());
|
() => MediaUploadAttachmentHelper());
|
||||||
getIt.registerLazySingleton<NotificationsManager>(
|
getIt.registerLazySingleton<NotificationsManager>(
|
||||||
() => NotificationsManager());
|
() => NotificationsManager());
|
||||||
galleryService.getGalleries();
|
|
||||||
getIt.registerLazySingleton<DirectMessageService>(
|
getIt.registerLazySingleton<DirectMessageService>(
|
||||||
() => DirectMessageService());
|
() => DirectMessageService());
|
||||||
getIt.registerLazySingleton<NetworkStatusService>(
|
getIt.registerLazySingleton<NetworkStatusService>(
|
||||||
|
|
|
@ -44,10 +44,8 @@ class _ImageViewerScreenState extends State<ImageViewerScreen> {
|
||||||
buildSnackbar(context, 'Downloading full image to save locally');
|
buildSnackbar(context, 'Downloading full image to save locally');
|
||||||
final appsDir = await getApplicationDocumentsDirectory();
|
final appsDir = await getApplicationDocumentsDirectory();
|
||||||
final filename = p.basename(attachment.fullFileUri.path);
|
final filename = p.basename(attachment.fullFileUri.path);
|
||||||
final bytesResult = await getIt<AuthService>()
|
final bytesResult =
|
||||||
.currentClient
|
await getIt<AuthService>().currentClient.getFileBytes(attachment.uri);
|
||||||
.value
|
|
||||||
.getFileBytes(attachment.uri);
|
|
||||||
if (bytesResult.isFailure && mounted) {
|
if (bytesResult.isFailure && mounted) {
|
||||||
buildSnackbar(context,
|
buildSnackbar(context,
|
||||||
'Error getting full size version of file: ${bytesResult.error}');
|
'Error getting full size version of file: ${bytesResult.error}');
|
||||||
|
|
|
@ -21,8 +21,7 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text('Profile: ${authService.currentClient.credentials.handle}'),
|
||||||
'Profile: ${authService.currentClient.fold(onSuccess: (client) => client.credentials.handle, onError: (error) => 'Error Getting Profile')}'),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -13,19 +13,10 @@ class AuthService extends ChangeNotifier {
|
||||||
FriendicaClient? _friendicaClient;
|
FriendicaClient? _friendicaClient;
|
||||||
bool _loggedIn = false;
|
bool _loggedIn = false;
|
||||||
|
|
||||||
Result<FriendicaClient, ExecError> get currentClient {
|
|
||||||
if (_friendicaClient == null) {
|
|
||||||
return Result.error(ExecError(
|
|
||||||
type: ErrorType.authentication,
|
|
||||||
message: 'Not logged in',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.ok(_friendicaClient!);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool get loggedIn => _loggedIn && _friendicaClient != null;
|
bool get loggedIn => _loggedIn && _friendicaClient != null;
|
||||||
|
|
||||||
|
FriendicaClient get currentClient => _friendicaClient!;
|
||||||
|
|
||||||
String get currentId => _friendicaClient?.credentials.userId ?? '';
|
String get currentId => _friendicaClient?.credentials.userId ?? '';
|
||||||
|
|
||||||
String get currentHandle => _friendicaClient?.credentials.handle ?? '';
|
String get currentHandle => _friendicaClient?.credentials.handle ?? '';
|
||||||
|
|
|
@ -43,10 +43,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
Future<void> acceptFollowRequest(Connection connection) async {
|
Future<void> acceptFollowRequest(Connection connection) async {
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.acceptFollow(connection).match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.acceptFollow(connection))
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
_logger
|
_logger
|
||||||
.finest('Successfully followed ${update.name}: ${update.status}');
|
.finest('Successfully followed ${update.name}: ${update.status}');
|
||||||
|
@ -62,10 +59,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
Future<void> rejectFollowRequest(Connection connection) async {
|
Future<void> rejectFollowRequest(Connection connection) async {
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.rejectFollow(connection).match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.rejectFollow(connection))
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
_logger
|
_logger
|
||||||
.finest('Successfully followed ${update.name}: ${update.status}');
|
.finest('Successfully followed ${update.name}: ${update.status}');
|
||||||
|
@ -81,10 +75,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
Future<void> ignoreFollowRequest(Connection connection) async {
|
Future<void> ignoreFollowRequest(Connection connection) async {
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
'Attempting to accept follow request ${connection.name}: ${connection.status}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.ignoreFollow(connection).match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.ignoreFollow(connection))
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
_logger
|
_logger
|
||||||
.finest('Successfully followed ${update.name}: ${update.status}');
|
.finest('Successfully followed ${update.name}: ${update.status}');
|
||||||
|
@ -100,10 +91,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
Future<void> follow(Connection connection) async {
|
Future<void> follow(Connection connection) async {
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
'Attempting to follow ${connection.name}: ${connection.status}');
|
'Attempting to follow ${connection.name}: ${connection.status}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.followConnection(connection).match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.followConnection(connection))
|
|
||||||
.match(
|
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
_logger
|
_logger
|
||||||
.finest('Successfully followed ${update.name}: ${update.status}');
|
.finest('Successfully followed ${update.name}: ${update.status}');
|
||||||
|
@ -121,7 +109,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
'Attempting to unfollow ${connection.name}: ${connection.status}');
|
'Attempting to unfollow ${connection.name}: ${connection.status}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>()
|
||||||
.currentClient
|
.currentClient
|
||||||
.andThenAsync((client) => client.unFollowConnection(connection))
|
.unFollowConnection(connection)
|
||||||
.match(
|
.match(
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
_logger
|
_logger
|
||||||
|
@ -141,13 +129,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
|
|
||||||
Future<void> updateAllContacts() async {
|
Future<void> updateAllContacts() async {
|
||||||
_logger.fine('Updating all contacts');
|
_logger.fine('Updating all contacts');
|
||||||
final clientResult = getIt<AuthService>().currentClient;
|
final client = getIt<AuthService>().currentClient;
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe(
|
|
||||||
'Unable to update contacts due to client error: ${clientResult.error}');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final client = clientResult.value;
|
|
||||||
final results = <String, Connection>{};
|
final results = <String, Connection>{};
|
||||||
var moreResults = true;
|
var moreResults = true;
|
||||||
var maxId = -1;
|
var maxId = -1;
|
||||||
|
@ -224,8 +206,9 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
FutureResult<bool, ExecError> addUserToGroup(
|
FutureResult<bool, ExecError> addUserToGroup(
|
||||||
GroupData group, Connection connection) async {
|
GroupData group, Connection connection) async {
|
||||||
_logger.finest('Adding ${connection.name} to group: ${group.name}');
|
_logger.finest('Adding ${connection.name} to group: ${group.name}');
|
||||||
final result = await getIt<AuthService>().currentClient.andThenAsync(
|
final result = await getIt<AuthService>()
|
||||||
(client) => client.addConnectionToGroup(group, connection));
|
.currentClient
|
||||||
|
.addConnectionToGroup(group, connection);
|
||||||
result.match(
|
result.match(
|
||||||
onSuccess: (_) => _refreshGroupListData(connection.id, true),
|
onSuccess: (_) => _refreshGroupListData(connection.id, true),
|
||||||
onError: (error) {
|
onError: (error) {
|
||||||
|
@ -240,8 +223,9 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
FutureResult<bool, ExecError> removeUserFromGroup(
|
FutureResult<bool, ExecError> removeUserFromGroup(
|
||||||
GroupData group, Connection connection) async {
|
GroupData group, Connection connection) async {
|
||||||
_logger.finest('Removing ${connection.name} from group: ${group.name}');
|
_logger.finest('Removing ${connection.name} from group: ${group.name}');
|
||||||
final result = await getIt<AuthService>().currentClient.andThenAsync(
|
final result = await getIt<AuthService>()
|
||||||
(client) => client.removeConnectionFromGroup(group, connection));
|
.currentClient
|
||||||
|
.removeConnectionFromGroup(group, connection);
|
||||||
result.match(
|
result.match(
|
||||||
onSuccess: (_) => _refreshGroupListData(connection.id, true),
|
onSuccess: (_) => _refreshGroupListData(connection.id, true),
|
||||||
onError: (error) {
|
onError: (error) {
|
||||||
|
@ -291,7 +275,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
_logger.finest('Refreshing member list data for Connection $id');
|
_logger.finest('Refreshing member list data for Connection $id');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>()
|
||||||
.currentClient
|
.currentClient
|
||||||
.andThenAsync((client) => client.getMemberGroupsForConnection(id))
|
.getMemberGroupsForConnection(id)
|
||||||
.match(
|
.match(
|
||||||
onSuccess: (groups) {
|
onSuccess: (groups) {
|
||||||
groupsRepo.updateConnectionGroupData(id, groups);
|
groupsRepo.updateConnectionGroupData(id, groups);
|
||||||
|
@ -310,7 +294,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
_logger.finest('Refreshing connection data for ${connection.name}');
|
_logger.finest('Refreshing connection data for ${connection.name}');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>()
|
||||||
.currentClient
|
.currentClient
|
||||||
.andThenAsync((client) => client.getConnectionWithStatus(connection))
|
.getConnectionWithStatus(connection)
|
||||||
.match(
|
.match(
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
updateConnection(update);
|
updateConnection(update);
|
||||||
|
@ -326,10 +310,7 @@ class ConnectionsManager extends ChangeNotifier {
|
||||||
|
|
||||||
Future<void> _updateMyGroups(bool withNotification) async {
|
Future<void> _updateMyGroups(bool withNotification) async {
|
||||||
_logger.finest('Refreshing my groups list');
|
_logger.finest('Refreshing my groups list');
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.getGroups().match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.getGroups())
|
|
||||||
.match(
|
|
||||||
onSuccess: (groups) {
|
onSuccess: (groups) {
|
||||||
_logger.finest('Got updated groups:${groups.map((e) => e.name)}');
|
_logger.finest('Got updated groups:${groups.map((e) => e.name)}');
|
||||||
groupsRepo.clearGroups();
|
groupsRepo.clearGroups();
|
||||||
|
|
|
@ -38,7 +38,7 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
Future<void> updateThreads() async {
|
Future<void> updateThreads() async {
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>()
|
||||||
.currentClient
|
.currentClient
|
||||||
.andThenAsync((client) => client.getDirectMessages(PagingData()))
|
.getDirectMessages(PagingData())
|
||||||
.match(
|
.match(
|
||||||
onSuccess: (update) {
|
onSuccess: (update) {
|
||||||
final newThreads = DirectMessageThread.createThreads(update);
|
final newThreads = DirectMessageThread.createThreads(update);
|
||||||
|
@ -61,13 +61,11 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<DirectMessage, ExecError> newThread(
|
FutureResult<DirectMessage, ExecError> newThread(
|
||||||
Connection receiver, String text) async {
|
Connection receiver, String text) async {
|
||||||
final result = await getIt<AuthService>()
|
final result = await getIt<AuthService>().currentClient.postDirectMessage(
|
||||||
.currentClient
|
null,
|
||||||
.andThenAsync((client) => client.postDirectMessage(
|
receiver.id,
|
||||||
null,
|
text,
|
||||||
receiver.id,
|
);
|
||||||
text,
|
|
||||||
));
|
|
||||||
result.match(onSuccess: (newMessage) {
|
result.match(onSuccess: (newMessage) {
|
||||||
DirectMessageThread.createThreads([newMessage]).forEach((thread) {
|
DirectMessageThread.createThreads([newMessage]).forEach((thread) {
|
||||||
_threads[thread.parentUri] = thread;
|
_threads[thread.parentUri] = thread;
|
||||||
|
@ -101,13 +99,11 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await getIt<AuthService>()
|
final result = await getIt<AuthService>().currentClient.postDirectMessage(
|
||||||
.currentClient
|
original.id,
|
||||||
.andThenAsync((client) => client.postDirectMessage(
|
original.senderId,
|
||||||
original.id,
|
text,
|
||||||
original.senderId,
|
);
|
||||||
text,
|
|
||||||
));
|
|
||||||
result.match(onSuccess: (newMessage) {
|
result.match(onSuccess: (newMessage) {
|
||||||
thread.messages.add(newMessage);
|
thread.messages.add(newMessage);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -130,10 +126,7 @@ class DirectMessageService extends ChangeNotifier {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await getIt<AuthService>()
|
await getIt<AuthService>().currentClient.markDirectMessageRead(m).match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.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);
|
||||||
|
|
|
@ -68,15 +68,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 auth = getIt<AuthService>();
|
final result = await getIt<AuthService>().currentClient.deleteEntryById(id);
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.deleteEntryById(id);
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -86,23 +78,14 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
return Result.ok(true);
|
return Result.ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<bool, ExecError> createNewStatus(
|
FutureResult<bool, ExecError> createNewStatus(String text, {
|
||||||
String text, {
|
|
||||||
String spoilerText = '',
|
String spoilerText = '',
|
||||||
String inReplyToId = '',
|
String inReplyToId = '',
|
||||||
required NewEntryMediaItems mediaItems,
|
required NewEntryMediaItems mediaItems,
|
||||||
required List<ImageEntry> existingMediaItems,
|
required List<ImageEntry> existingMediaItems,
|
||||||
}) async {
|
}) async {
|
||||||
_logger.finest('Creating new post: $text');
|
_logger.finest('Creating new post: $text');
|
||||||
final auth = getIt<AuthService>();
|
final client = getIt<AuthService>().currentClient;
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
|
|
||||||
final mediaIds = existingMediaItems.map((m) => m.scales.first.id).toList();
|
final mediaIds = existingMediaItems.map((m) => m.scales.first.id).toList();
|
||||||
for (final item in mediaItems.attachments) {
|
for (final item in mediaItems.attachments) {
|
||||||
if (item.isExistingServerItem) {
|
if (item.isExistingServerItem) {
|
||||||
|
@ -124,10 +107,11 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
final uploadResult =
|
final uploadResult =
|
||||||
await MediaUploadAttachmentHelper.getUploadableImageBytes(
|
await MediaUploadAttachmentHelper.getUploadableImageBytes(
|
||||||
item.localFilePath,
|
item.localFilePath,
|
||||||
).andThenAsync(
|
).andThenAsync(
|
||||||
(imageBytes) async => await client.uploadFileAsAttachment(
|
(imageBytes) async =>
|
||||||
|
await client.uploadFileAsAttachment(
|
||||||
bytes: imageBytes,
|
bytes: imageBytes,
|
||||||
album: mediaItems.albumName,
|
album: mediaItems.albumName,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
|
@ -145,10 +129,10 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
|
|
||||||
final result = await client
|
final result = await client
|
||||||
.createNewStatus(
|
.createNewStatus(
|
||||||
text: text,
|
text: text,
|
||||||
spoilerText: spoilerText,
|
spoilerText: spoilerText,
|
||||||
inReplyToId: inReplyToId,
|
inReplyToId: inReplyToId,
|
||||||
mediaIds: mediaIds)
|
mediaIds: mediaIds)
|
||||||
.andThenSuccessAsync((item) async {
|
.andThenSuccessAsync((item) async {
|
||||||
await processNewItems([item], client.credentials.username, null);
|
await processNewItems([item], client.credentials.username, null);
|
||||||
return item;
|
return item;
|
||||||
|
@ -169,7 +153,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
_logger.finest('${status.id} status created');
|
_logger.finest('${status.id} status created');
|
||||||
return true;
|
return true;
|
||||||
}).mapError(
|
}).mapError(
|
||||||
(error) {
|
(error) {
|
||||||
_logger.finest('Error creating post: $error');
|
_logger.finest('Error creating post: $error');
|
||||||
return ExecError(
|
return ExecError(
|
||||||
type: ErrorType.localError,
|
type: ErrorType.localError,
|
||||||
|
@ -182,14 +166,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 auth = getIt<AuthService>();
|
final client = getIt<AuthService>().currentClient;
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final itemsResult = await client.getTimeline(
|
final itemsResult = await client.getTimeline(
|
||||||
type: type,
|
type: type,
|
||||||
page: PagingData(
|
page: PagingData(
|
||||||
|
@ -203,10 +180,12 @@ 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(
|
||||||
await processNewItems(itemsResult.value, auth.currentId, client);
|
itemsResult.value, client.credentials.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;
|
||||||
final orphanCount = _entries.values
|
final orphanCount = _entries.values
|
||||||
.where(
|
.where(
|
||||||
|
@ -217,11 +196,9 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
return Result.ok(updatedPosts);
|
return Result.ok(updatedPosts);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<EntryTreeItem>> processNewItems(
|
Future<List<EntryTreeItem>> processNewItems(List<TimelineEntry> items,
|
||||||
List<TimelineEntry> items,
|
String currentId,
|
||||||
String currentId,
|
FriendicaClient? client,) async {
|
||||||
FriendicaClient? client,
|
|
||||||
) async {
|
|
||||||
items.sort((i1, i2) => int.parse(i1.id).compareTo(int.parse(i2.id)));
|
items.sort((i1, i2) => int.parse(i1.id).compareTo(int.parse(i2.id)));
|
||||||
final allSeenItems = [...items];
|
final allSeenItems = [...items];
|
||||||
for (final item in items) {
|
for (final item in items) {
|
||||||
|
@ -248,7 +225,9 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
await client
|
await client
|
||||||
?.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;
|
||||||
_parentPostIds[o.id] = parentPostId;
|
_parentPostIds[o.id] = parentPostId;
|
||||||
allSeenItems.addAll(items);
|
allSeenItems.addAll(items);
|
||||||
for (final item in items) {
|
for (final item in items) {
|
||||||
|
@ -276,7 +255,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
for (final item in seenItemsCopy) {
|
for (final item in seenItemsCopy) {
|
||||||
if (item.parentId.isEmpty) {
|
if (item.parentId.isEmpty) {
|
||||||
final postNode =
|
final postNode =
|
||||||
_postNodes.putIfAbsent(item.id, () => _Node(item.id));
|
_postNodes.putIfAbsent(item.id, () => _Node(item.id));
|
||||||
postNodesToReturn.add(postNode);
|
postNodesToReturn.add(postNode);
|
||||||
allSeenItems.remove(item);
|
allSeenItems.remove(item);
|
||||||
} else {
|
} else {
|
||||||
|
@ -318,35 +297,31 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
'Completed processing new items ${client == null ? 'sub level' : 'top level'}');
|
'Completed processing new items ${client == null
|
||||||
|
? 'sub level'
|
||||||
|
: 'top level'}');
|
||||||
return updatedPosts;
|
return updatedPosts;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 auth = getIt<AuthService>();
|
final client = getIt<AuthService>().currentClient;
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client
|
final result = await client
|
||||||
.getPostOrComment(id, fullContext: false)
|
.getPostOrComment(id, fullContext: false)
|
||||||
.andThenAsync((rootItems) async => await client
|
.andThenAsync((rootItems) async =>
|
||||||
.getPostOrComment(id, fullContext: true)
|
await client
|
||||||
.andThenSuccessAsync(
|
.getPostOrComment(id, fullContext: true)
|
||||||
(contextItems) async => [...rootItems, ...contextItems]))
|
.andThenSuccessAsync(
|
||||||
|
(contextItems) async => [...rootItems, ...contextItems]))
|
||||||
.andThenSuccessAsync((items) async {
|
.andThenSuccessAsync((items) async {
|
||||||
await processNewItems(items, client.credentials.username, null);
|
await processNewItems(items, client.credentials.username, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
return result.mapValue((_) {
|
return result.mapValue((_) {
|
||||||
_logger.finest('$id post updated');
|
_logger.finest('$id post updated');
|
||||||
return _nodeToTreeItem(_getPostRootNode(id)!, auth.currentId);
|
return _nodeToTreeItem(_getPostRootNode(id)!, client.credentials.userId);
|
||||||
}).mapError(
|
}).mapError(
|
||||||
(error) {
|
(error) {
|
||||||
_logger.finest('$id error updating: $error');
|
_logger.finest('$id error updating: $error');
|
||||||
return ExecError(
|
return ExecError(
|
||||||
type: ErrorType.localError,
|
type: ErrorType.localError,
|
||||||
|
@ -358,24 +333,17 @@ 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 auth = getIt<AuthService>();
|
final client = getIt<AuthService>().currentClient;
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result =
|
final result =
|
||||||
await client.resharePost(id).andThenSuccessAsync((item) async {
|
await client.resharePost(id).andThenSuccessAsync((item) async {
|
||||||
await processNewItems([item], client.credentials.username, null);
|
await processNewItems([item], client.credentials.username, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
return result.mapValue((_) {
|
return result.mapValue((_) {
|
||||||
_logger.finest('$id post updated after reshare');
|
_logger.finest('$id post updated after reshare');
|
||||||
return _nodeToTreeItem(_postNodes[id]!, auth.currentId);
|
return _nodeToTreeItem(_postNodes[id]!, client.credentials.userId);
|
||||||
}).mapError(
|
}).mapError(
|
||||||
(error) {
|
(error) {
|
||||||
_logger.finest('$id error updating: $error');
|
_logger.finest('$id error updating: $error');
|
||||||
return ExecError(
|
return ExecError(
|
||||||
type: ErrorType.localError,
|
type: ErrorType.localError,
|
||||||
|
@ -387,16 +355,11 @@ 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 auth = getIt<AuthService>();
|
final client = getIt<AuthService>()
|
||||||
final clientResult = auth.currentClient;
|
.currentClient;
|
||||||
if (clientResult.isFailure) {
|
final result = await client
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
.unResharePost(id)
|
||||||
return clientResult.errorCast();
|
.andThenSuccessAsync((item) async {
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result =
|
|
||||||
await client.unResharePost(id).andThenSuccessAsync((item) async {
|
|
||||||
await processNewItems([item], client.credentials.username, null);
|
await processNewItems([item], client.credentials.username, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -410,16 +373,12 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
return Result.ok(true);
|
return Result.ok(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<EntryTreeItem, ExecError> toggleFavorited(
|
FutureResult<EntryTreeItem, ExecError> toggleFavorited(String id,
|
||||||
String id, bool newStatus) async {
|
bool newStatus) async {
|
||||||
final auth = getIt<AuthService>();
|
final client = getIt<AuthService>()
|
||||||
final clientResult = auth.currentClient;
|
.currentClient;
|
||||||
if (clientResult.isFailure) {
|
final result = await client
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
.changeFavoriteStatus(id, newStatus);
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.changeFavoriteStatus(id, newStatus);
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -431,7 +390,7 @@ class EntryManagerService extends ChangeNotifier {
|
||||||
: _postNodes[update.parentId]!.getChildById(update.id)!;
|
: _postNodes[update.parentId]!.getChildById(update.id)!;
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
return Result.ok(_nodeToTreeItem(node, auth.currentId));
|
return Result.ok(_nodeToTreeItem(node, client.credentials.userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
EntryTreeItem _nodeToTreeItem(_Node node, String currentId) {
|
EntryTreeItem _nodeToTreeItem(_Node node, String currentId) {
|
||||||
|
@ -508,7 +467,7 @@ class _Node {
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is _Node && runtimeType == other.runtimeType && id == other.id;
|
other is _Node && runtimeType == other.runtimeType && id == other.id;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => id.hashCode;
|
int get hashCode => id.hashCode;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
import 'package:result_monad/result_monad.dart';
|
import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../friendica_client/paging_data.dart';
|
import '../friendica_client/paging_data.dart';
|
||||||
|
@ -11,7 +10,6 @@ import 'auth_service.dart';
|
||||||
|
|
||||||
class GalleryService extends ChangeNotifier {
|
class GalleryService extends ChangeNotifier {
|
||||||
static const IMAGES_PER_PAGE = 50;
|
static const IMAGES_PER_PAGE = 50;
|
||||||
static final _logger = Logger('$GalleryService');
|
|
||||||
final _galleries = <String, GalleryData>{};
|
final _galleries = <String, GalleryData>{};
|
||||||
final _galleryPages = <String, List<PagingData>>{};
|
final _galleryPages = <String, List<PagingData>>{};
|
||||||
final _images = <String, Set<ImageEntry>>{};
|
final _images = <String, Set<ImageEntry>>{};
|
||||||
|
@ -41,15 +39,7 @@ class GalleryService extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<List<GalleryData>, ExecError> updateGalleries() async {
|
FutureResult<List<GalleryData>, ExecError> updateGalleries() async {
|
||||||
final auth = getIt<AuthService>();
|
final result = await getIt<AuthService>().currentClient.getGalleryData();
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.getGalleryData();
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -86,13 +76,6 @@ class GalleryService extends ChangeNotifier {
|
||||||
{required String galleryName,
|
{required String galleryName,
|
||||||
required bool withNextPage,
|
required bool withNextPage,
|
||||||
bool nextPageOnly = true}) async {
|
bool nextPageOnly = true}) async {
|
||||||
final auth = getIt<AuthService>();
|
|
||||||
final clientResult = auth.currentClient;
|
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final pages = _galleryPages.putIfAbsent(galleryName, () => []);
|
final pages = _galleryPages.putIfAbsent(galleryName, () => []);
|
||||||
if (pages.isEmpty) {
|
if (pages.isEmpty) {
|
||||||
pages.add(PagingData(offset: 0, limit: IMAGES_PER_PAGE));
|
pages.add(PagingData(offset: 0, limit: IMAGES_PER_PAGE));
|
||||||
|
@ -101,12 +84,13 @@ class GalleryService extends ChangeNotifier {
|
||||||
pages.add(PagingData(offset: offset, limit: IMAGES_PER_PAGE));
|
pages.add(PagingData(offset: offset, limit: IMAGES_PER_PAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final imageSet = _images.putIfAbsent(galleryName, () => {});
|
final imageSet = _images.putIfAbsent(galleryName, () => {});
|
||||||
|
|
||||||
final pagesToUse = nextPageOnly ? [pages.last] : pages;
|
final pagesToUse = nextPageOnly ? [pages.last] : pages;
|
||||||
for (final page in pagesToUse) {
|
for (final page in pagesToUse) {
|
||||||
final result = await client.getGalleryImages(galleryName, page);
|
final result = await getIt<AuthService>()
|
||||||
|
.currentClient
|
||||||
|
.getGalleryImages(galleryName, page);
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
import 'package:result_monad/result_monad.dart';
|
import 'package:result_monad/result_monad.dart';
|
||||||
|
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
|
@ -8,7 +7,6 @@ import '../models/exec_error.dart';
|
||||||
import 'auth_service.dart';
|
import 'auth_service.dart';
|
||||||
|
|
||||||
class InteractionsManager extends ChangeNotifier {
|
class InteractionsManager extends ChangeNotifier {
|
||||||
static final _logger = Logger('$InteractionsManager');
|
|
||||||
final _likesByStatusId = <String, List<Connection>>{};
|
final _likesByStatusId = <String, List<Connection>>{};
|
||||||
final _resharesByStatusId = <String, List<Connection>>{};
|
final _resharesByStatusId = <String, List<Connection>>{};
|
||||||
|
|
||||||
|
@ -32,15 +30,8 @@ class InteractionsManager extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
|
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
|
||||||
String statusId) async {
|
String statusId) async {
|
||||||
final auth = getIt<AuthService>();
|
final likesResult =
|
||||||
final clientResult = auth.currentClient;
|
await getIt<AuthService>().currentClient.getLikes(statusId);
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final likesResult = await client.getLikes(statusId);
|
|
||||||
if (likesResult.isSuccess) {
|
if (likesResult.isSuccess) {
|
||||||
_likesByStatusId[statusId] = likesResult.value;
|
_likesByStatusId[statusId] = likesResult.value;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -50,15 +41,8 @@ class InteractionsManager extends ChangeNotifier {
|
||||||
|
|
||||||
FutureResult<List<Connection>, ExecError> updateResharesForStatus(
|
FutureResult<List<Connection>, ExecError> updateResharesForStatus(
|
||||||
String statusId) async {
|
String statusId) async {
|
||||||
final auth = getIt<AuthService>();
|
final resharesResult =
|
||||||
final clientResult = auth.currentClient;
|
await getIt<AuthService>().currentClient.getReshares(statusId);
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final resharesResult = await client.getReshares(statusId);
|
|
||||||
if (resharesResult.isSuccess) {
|
if (resharesResult.isSuccess) {
|
||||||
_resharesByStatusId[statusId] = resharesResult.value;
|
_resharesByStatusId[statusId] = resharesResult.value;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -127,15 +127,9 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<bool, ExecError> markSeen(UserNotification notification) async {
|
FutureResult<bool, ExecError> markSeen(UserNotification notification) async {
|
||||||
final auth = getIt<AuthService>();
|
final result = await getIt<AuthService>()
|
||||||
final clientResult = auth.currentClient;
|
.currentClient
|
||||||
if (clientResult.isFailure) {
|
.clearNotification(notification);
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.clearNotification(notification);
|
|
||||||
if (result.isSuccess) {
|
if (result.isSuccess) {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
@ -145,15 +139,8 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureResult<List<UserNotification>, ExecError> markAllAsRead() async {
|
FutureResult<List<UserNotification>, ExecError> markAllAsRead() async {
|
||||||
final auth = getIt<AuthService>();
|
final result =
|
||||||
final clientResult = auth.currentClient;
|
await getIt<AuthService>().currentClient.clearNotifications();
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.clearNotifications();
|
|
||||||
if (result.isFailure) {
|
if (result.isFailure) {
|
||||||
return result.errorCast();
|
return result.errorCast();
|
||||||
}
|
}
|
||||||
|
@ -188,15 +175,8 @@ class NotificationsManager extends ChangeNotifier {
|
||||||
|
|
||||||
static FutureResult<PagedResponse<List<UserNotification>>, ExecError>
|
static FutureResult<PagedResponse<List<UserNotification>>, ExecError>
|
||||||
_clientGetNotificationsRequest(PagingData page) async {
|
_clientGetNotificationsRequest(PagingData page) async {
|
||||||
final auth = getIt<AuthService>();
|
final result =
|
||||||
final clientResult = auth.currentClient;
|
await getIt<AuthService>().currentClient.getNotifications(page);
|
||||||
if (clientResult.isFailure) {
|
|
||||||
_logger.severe('Error getting Friendica client: ${clientResult.error}');
|
|
||||||
return clientResult.errorCast();
|
|
||||||
}
|
|
||||||
|
|
||||||
final client = clientResult.value;
|
|
||||||
final result = await client.getNotifications(page);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,10 +45,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 getIt<AuthService>()
|
await getIt<AuthService>().currentClient.getGroups().match(
|
||||||
.currentClient
|
|
||||||
.andThenAsync((client) => client.getGroups())
|
|
||||||
.match(
|
|
||||||
onSuccess: (groups) {
|
onSuccess: (groups) {
|
||||||
_groups.clear();
|
_groups.clear();
|
||||||
for (final group in groups) {
|
for (final group in groups) {
|
||||||
|
|
Loading…
Reference in a new issue