Rename AuthService to AccountsService

codemagic-setup
Hank Grabowski 2023-02-25 18:06:24 -05:00
rodzic c2e083e068
commit d2f5c347bc
19 zmienionych plików z 69 dodań i 61 usunięć

Wyświetl plik

@ -27,7 +27,7 @@ import 'services/timeline_manager.dart';
final _logger = Logger('DI_Init');
Future<void> dependencyInjectionInitialization() async {
final authService = AuthService();
final authService = AccountsService();
final secretsService = SecretsService();
final entryManagerService = EntryManagerService();
final timelineManager = TimelineManager();
@ -47,7 +47,7 @@ Future<void> dependencyInjectionInitialization() async {
getIt.registerSingleton(galleryService);
getIt.registerSingleton<EntryManagerService>(entryManagerService);
getIt.registerSingleton<SecretsService>(secretsService);
getIt.registerSingleton<AuthService>(authService);
getIt.registerSingleton<AccountsService>(authService);
getIt.registerSingleton<TimelineManager>(timelineManager);
getIt.registerLazySingleton<MediaUploadAttachmentHelper>(
() => MediaUploadAttachmentHelper());

Wyświetl plik

@ -52,8 +52,8 @@ class App extends StatelessWidget {
create: (_) => getIt<SettingsService>(),
lazy: true,
),
ChangeNotifierProvider<AuthService>(
create: (_) => getIt<AuthService>(),
ChangeNotifierProvider<AccountsService>(
create: (_) => getIt<AccountsService>(),
lazy: true,
),
ChangeNotifierProvider<ConnectionsManager>(

Wyświetl plik

@ -44,7 +44,7 @@ class ScreenPaths {
}
bool needAuthChangeInitialized = true;
final _authService = getIt<AuthService>();
final _authService = getIt<AccountsService>();
final allowedLoggedOut = [
ScreenPaths.splash,
ScreenPaths.signin,

Wyświetl plik

@ -46,7 +46,7 @@ class _ImageViewerScreenState extends State<ImageViewerScreen> {
final appsDir = await getApplicationDocumentsDirectory();
final filename = p.basename(attachment.fullFileUri.path);
final bytesResult =
await RemoteFileClient(getIt<AuthService>().currentCredentials)
await RemoteFileClient(getIt<AccountsService>().currentCredentials)
.getFileBytes(attachment.uri);
if (bytesResult.isFailure && mounted) {
buildSnackbar(context,

Wyświetl plik

@ -34,7 +34,7 @@ class MenusScreen extends StatelessWidget {
buildMenuButton('Logout', () async {
final confirm = await showYesNoDialog(context, 'Log out account?');
if (confirm == true) {
await getIt<AuthService>().signOut();
await getIt<AccountsService>().signOut();
}
}),
];

Wyświetl plik

@ -47,8 +47,9 @@ class _MessageThreadScreenState extends State<MessageThreadScreen> {
) {
return result.fold(
onSuccess: (thread) {
final yourId = getIt<AuthService>().currentCredentials.userId;
final yourAvatarUrl = getIt<AuthService>().currentCredentials.avatar;
final yourId = getIt<AccountsService>().currentCredentials.userId;
final yourAvatarUrl =
getIt<AccountsService>().currentCredentials.avatar;
final participants =
Map.fromEntries(thread.participants.map((p) => MapEntry(p.id, p)));
return Center(

Wyświetl plik

@ -14,7 +14,7 @@ class ProfileScreen extends StatefulWidget {
class _ProfileScreenState extends State<ProfileScreen> {
@override
Widget build(BuildContext context) {
final authService = context.watch<AuthService>();
final authService = context.watch<AccountsService>();
return Scaffold(
appBar: StandardAppBar.build(context, 'Profile'),
body: Center(

Wyświetl plik

@ -146,7 +146,7 @@ class _SignInScreenState extends State<SignInScreen> {
userId: '',
avatar: '');
final result = await getIt<AuthService>().signIn(creds);
final result = await getIt<AccountsService>().signIn(creds);
if (result.isFailure) {
buildSnackbar(context, 'Error signing in: ${result.error}');
}

Wyświetl plik

@ -43,7 +43,7 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
final manager = context.watch<ConnectionsManager>();
final body = manager.getById(widget.userId).fold(onSuccess: (profile) {
final notMyProfile =
getIt<AuthService>().currentCredentials.userId != profile.id;
getIt<AccountsService>().currentCredentials.userId != profile.id;
return RefreshIndicator(
onRefresh: () async {

Wyświetl plik

@ -41,14 +41,14 @@ extension DirectMessageFriendicaExtension on DirectMessage {
final String parentUri = json['friendica_parent_uri'];
final cm = getIt<ConnectionsManager>();
if (getIt<AuthService>().currentCredentials.userId != senderId) {
if (getIt<AccountsService>().currentCredentials.userId != senderId) {
final s = ConnectionFriendicaExtensions.fromJson(json['sender']);
if (cm.getById(s.id).isFailure) {
cm.addConnection(s);
}
}
if (getIt<AuthService>().currentCredentials.userId != recipientId) {
if (getIt<AccountsService>().currentCredentials.userId != recipientId) {
final r = ConnectionFriendicaExtensions.fromJson(json['recipient']);
if (cm.getById(r.id).isFailure) {
cm.addConnection(r);

Wyświetl plik

@ -20,7 +20,7 @@ extension ConnectionMastodonExtensions on Connection {
if (handleFromJson.contains('@')) {
handle = handleFromJson;
} else {
final server = getIt<AuthService>().currentCredentials.serverName;
final server = getIt<AccountsService>().currentCredentials.serverName;
handle = '$handleFromJson@$server';
}

Wyświetl plik

@ -9,7 +9,7 @@ import '../models/exec_error.dart';
import 'secrets_service.dart';
import 'timeline_manager.dart';
class AuthService extends ChangeNotifier {
class AccountsService extends ChangeNotifier {
Credentials? _currentCredentials;
bool _loggedIn = false;

Wyświetl plik

@ -44,7 +44,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> acceptFollowRequest(Connection connection) async {
_logger.finest(
'Attempting to accept follow request ${connection.name}: ${connection.status}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.acceptFollow(connection)
.match(
onSuccess: (update) {
@ -62,7 +62,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> rejectFollowRequest(Connection connection) async {
_logger.finest(
'Attempting to accept follow request ${connection.name}: ${connection.status}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.rejectFollow(connection)
.match(
onSuccess: (update) {
@ -80,7 +80,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> ignoreFollowRequest(Connection connection) async {
_logger.finest(
'Attempting to accept follow request ${connection.name}: ${connection.status}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.ignoreFollow(connection)
.match(
onSuccess: (update) {
@ -98,7 +98,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> follow(Connection connection) async {
_logger.finest(
'Attempting to follow ${connection.name}: ${connection.status}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.followConnection(connection)
.match(
onSuccess: (update) {
@ -116,7 +116,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> unfollow(Connection connection) async {
_logger.finest(
'Attempting to unfollow ${connection.name}: ${connection.status}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.unFollowConnection(connection)
.match(
onSuccess: (update) {
@ -137,7 +137,8 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> updateAllContacts() async {
_logger.fine('Updating all contacts');
final client = RelationshipsClient(getIt<AuthService>().currentCredentials);
final client =
RelationshipsClient(getIt<AccountsService>().currentCredentials);
final results = <String, Connection>{};
var moreResults = true;
var maxId = -1;
@ -214,8 +215,9 @@ class ConnectionsManager extends ChangeNotifier {
FutureResult<bool, ExecError> addUserToGroup(
GroupData group, Connection connection) async {
_logger.finest('Adding ${connection.name} to group: ${group.name}');
final result = await GroupsClient(getIt<AuthService>().currentCredentials)
.addConnectionToGroup(group, connection);
final result =
await GroupsClient(getIt<AccountsService>().currentCredentials)
.addConnectionToGroup(group, connection);
result.match(
onSuccess: (_) => _refreshGroupListData(connection.id, true),
onError: (error) {
@ -230,8 +232,9 @@ class ConnectionsManager extends ChangeNotifier {
FutureResult<bool, ExecError> removeUserFromGroup(
GroupData group, Connection connection) async {
_logger.finest('Removing ${connection.name} from group: ${group.name}');
final result = await GroupsClient(getIt<AuthService>().currentCredentials)
.removeConnectionFromGroup(group, connection);
final result =
await GroupsClient(getIt<AccountsService>().currentCredentials)
.removeConnectionFromGroup(group, connection);
result.match(
onSuccess: (_) => _refreshGroupListData(connection.id, true),
onError: (error) {
@ -279,7 +282,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> _refreshGroupListData(String id, bool withNotification) async {
_logger.finest('Refreshing member list data for Connection $id');
await GroupsClient(getIt<AuthService>().currentCredentials)
await GroupsClient(getIt<AccountsService>().currentCredentials)
.getMemberGroupsForConnection(id)
.match(
onSuccess: (groups) {
@ -297,7 +300,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> _refreshConnection(
Connection connection, bool withNotification) async {
_logger.finest('Refreshing connection data for ${connection.name}');
await RelationshipsClient(getIt<AuthService>().currentCredentials)
await RelationshipsClient(getIt<AccountsService>().currentCredentials)
.getConnectionWithStatus(connection)
.match(
onSuccess: (update) {
@ -314,7 +317,7 @@ class ConnectionsManager extends ChangeNotifier {
Future<void> _updateMyGroups(bool withNotification) async {
_logger.finest('Refreshing my groups list');
await GroupsClient(getIt<AuthService>().currentCredentials)
await GroupsClient(getIt<AccountsService>().currentCredentials)
.getGroups()
.match(
onSuccess: (groups) {

Wyświetl plik

@ -37,7 +37,7 @@ class DirectMessageService extends ChangeNotifier {
}
Future<void> updateThreads() async {
await DirectMessagingClient(getIt<AuthService>().currentCredentials)
await DirectMessagingClient(getIt<AccountsService>().currentCredentials)
.getDirectMessages(PagingData())
.match(
onSuccess: (update) {
@ -62,7 +62,7 @@ class DirectMessageService extends ChangeNotifier {
FutureResult<DirectMessage, ExecError> newThread(
Connection receiver, String text) async {
final result =
await DirectMessagingClient(getIt<AuthService>().currentCredentials)
await DirectMessagingClient(getIt<AccountsService>().currentCredentials)
.postDirectMessage(
null,
receiver.id,
@ -102,7 +102,7 @@ class DirectMessageService extends ChangeNotifier {
}
final result =
await DirectMessagingClient(getIt<AuthService>().currentCredentials)
await DirectMessagingClient(getIt<AccountsService>().currentCredentials)
.postDirectMessage(
original.id,
original.senderId,
@ -130,7 +130,7 @@ class DirectMessageService extends ChangeNotifier {
return;
}
await DirectMessagingClient(getIt<AuthService>().currentCredentials)
await DirectMessagingClient(getIt<AccountsService>().currentCredentials)
.markDirectMessageRead(m)
.match(
onSuccess: (update) {

Wyświetl plik

@ -43,7 +43,7 @@ class EntryManagerService extends ChangeNotifier {
Result<EntryTreeItem, ExecError> getPostTreeEntryBy(String id) {
_logger.finest('Getting post: $id');
final currentId = getIt<AuthService>().currentCredentials.userId;
final currentId = getIt<AccountsService>().currentCredentials.userId;
final postNode = _getPostRootNode(id);
if (postNode == null) {
return Result.error(ExecError(
@ -68,8 +68,9 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<bool, ExecError> deleteEntryById(String id) async {
_logger.finest('Delete entry: $id');
final result = await StatusesClient(getIt<AuthService>().currentCredentials)
.deleteEntryById(id);
final result =
await StatusesClient(getIt<AccountsService>().currentCredentials)
.deleteEntryById(id);
if (result.isFailure) {
return result.errorCast();
}
@ -112,7 +113,7 @@ class EntryManagerService extends ChangeNotifier {
item.localFilePath,
).andThenAsync(
(imageBytes) async =>
await RemoteFileClient(getIt<AuthService>().currentCredentials)
await RemoteFileClient(getIt<AccountsService>().currentCredentials)
.uploadFileAsAttachment(
bytes: imageBytes,
album: mediaItems.albumName,
@ -129,15 +130,16 @@ class EntryManagerService extends ChangeNotifier {
}
}
final result = await StatusesClient(getIt<AuthService>().currentCredentials)
.createNewStatus(
text: text,
spoilerText: spoilerText,
inReplyToId: inReplyToId,
mediaIds: mediaIds)
.andThenSuccessAsync((item) async {
final result =
await StatusesClient(getIt<AccountsService>().currentCredentials)
.createNewStatus(
text: text,
spoilerText: spoilerText,
inReplyToId: inReplyToId,
mediaIds: mediaIds)
.andThenSuccessAsync((item) async {
await processNewItems(
[item], getIt<AuthService>().currentCredentials.username, null);
[item], getIt<AccountsService>().currentCredentials.username, null);
return item;
}).andThenSuccessAsync((item) async {
if (inReplyToId.isNotEmpty) {
@ -169,7 +171,7 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<List<EntryTreeItem>, ExecError> updateTimeline(
TimelineIdentifiers type, int maxId, int sinceId) async {
_logger.fine(() => 'Updating timeline');
final client = TimelineClient(getIt<AuthService>().currentCredentials);
final client = TimelineClient(getIt<AccountsService>().currentCredentials);
final itemsResult = await client.getTimeline(
type: type,
page: PagingData(
@ -225,7 +227,7 @@ class EntryManagerService extends ChangeNotifier {
}
for (final o in orphans) {
await StatusesClient(getIt<AuthService>().currentCredentials)
await StatusesClient(getIt<AccountsService>().currentCredentials)
.getPostOrComment(o.id, fullContext: true)
.andThenSuccessAsync((items) async {
final parentPostId = items.firstWhere((e) => e.parentId.isEmpty).id;
@ -304,7 +306,7 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<EntryTreeItem, ExecError> refreshStatusChain(String id) async {
_logger.finest('Refreshing post: $id');
final client = StatusesClient(getIt<AuthService>().currentCredentials);
final client = StatusesClient(getIt<AccountsService>().currentCredentials);
final result = await client
.getPostOrComment(id, fullContext: false)
.andThenAsync((rootItems) async => await client
@ -331,7 +333,7 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<EntryTreeItem, ExecError> resharePost(String id) async {
_logger.finest('Resharing post: $id');
final client = StatusesClient(getIt<AuthService>().currentCredentials);
final client = StatusesClient(getIt<AccountsService>().currentCredentials);
final result =
await client.resharePost(id).andThenSuccessAsync((item) async {
await processNewItems([item], client.credentials.username, null);
@ -353,7 +355,7 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<bool, ExecError> unResharePost(String id) async {
_logger.finest('Unresharing post: $id');
final client = StatusesClient(getIt<AuthService>().currentCredentials);
final client = StatusesClient(getIt<AccountsService>().currentCredentials);
final result =
await client.unResharePost(id).andThenSuccessAsync((item) async {
await processNewItems([item], client.credentials.username, null);
@ -371,7 +373,8 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<EntryTreeItem, ExecError> toggleFavorited(
String id, bool newStatus) async {
final client = InteractionsClient(getIt<AuthService>().currentCredentials);
final client =
InteractionsClient(getIt<AccountsService>().currentCredentials);
final result = await client.changeFavoriteStatus(id, newStatus);
if (result.isFailure) {
return result.errorCast();

Wyświetl plik

@ -40,8 +40,9 @@ class GalleryService extends ChangeNotifier {
}
FutureResult<List<GalleryData>, ExecError> updateGalleries() async {
final result = await GalleryClient(getIt<AuthService>().currentCredentials)
.getGalleryData();
final result =
await GalleryClient(getIt<AccountsService>().currentCredentials)
.getGalleryData();
if (result.isFailure) {
return result.errorCast();
}
@ -91,7 +92,7 @@ class GalleryService extends ChangeNotifier {
final pagesToUse = nextPageOnly ? [pages.last] : pages;
for (final page in pagesToUse) {
final result =
await GalleryClient(getIt<AuthService>().currentCredentials)
await GalleryClient(getIt<AccountsService>().currentCredentials)
.getGalleryImages(galleryName, page);
if (result.isFailure) {
return result.errorCast();

Wyświetl plik

@ -32,7 +32,7 @@ class InteractionsManager extends ChangeNotifier {
FutureResult<List<Connection>, ExecError> updateLikesForStatus(
String statusId) async {
final likesResult =
await InteractionsClient(getIt<AuthService>().currentCredentials)
await InteractionsClient(getIt<AccountsService>().currentCredentials)
.getLikes(statusId);
if (likesResult.isSuccess) {
_likesByStatusId[statusId] = likesResult.value;
@ -44,7 +44,7 @@ class InteractionsManager extends ChangeNotifier {
FutureResult<List<Connection>, ExecError> updateResharesForStatus(
String statusId) async {
final resharesResult =
await InteractionsClient(getIt<AuthService>().currentCredentials)
await InteractionsClient(getIt<AccountsService>().currentCredentials)
.getReshares(statusId);
if (resharesResult.isSuccess) {
_resharesByStatusId[statusId] = resharesResult.value;

Wyświetl plik

@ -129,7 +129,7 @@ class NotificationsManager extends ChangeNotifier {
FutureResult<bool, ExecError> markSeen(UserNotification notification) async {
final result =
await NotificationsClient(getIt<AuthService>().currentCredentials)
await NotificationsClient(getIt<AccountsService>().currentCredentials)
.clearNotification(notification);
if (result.isSuccess) {
notifyListeners();
@ -141,7 +141,7 @@ class NotificationsManager extends ChangeNotifier {
FutureResult<List<UserNotification>, ExecError> markAllAsRead() async {
final result =
await NotificationsClient(getIt<AuthService>().currentCredentials)
await NotificationsClient(getIt<AccountsService>().currentCredentials)
.clearNotifications();
if (result.isFailure) {
return result.errorCast();
@ -153,7 +153,7 @@ class NotificationsManager extends ChangeNotifier {
}
List<UserNotification> buildUnreadMessageNotifications() {
final myId = getIt<AuthService>().currentCredentials.userId;
final myId = getIt<AccountsService>().currentCredentials.userId;
final result =
getIt<DirectMessageService>().getThreads(unreadyOnly: true).map((t) {
final fromAccount = t.participants.firstWhere((p) => p.id != myId);
@ -178,7 +178,7 @@ class NotificationsManager extends ChangeNotifier {
static FutureResult<PagedResponse<List<UserNotification>>, ExecError>
_clientGetNotificationsRequest(PagingData page) async {
final result =
await NotificationsClient(getIt<AuthService>().currentCredentials)
await NotificationsClient(getIt<AccountsService>().currentCredentials)
.getNotifications(page);
return result;
}

Wyświetl plik

@ -46,7 +46,7 @@ class TimelineManager extends ChangeNotifier {
Future<void> _refreshGroupData() async {
_logger.finest('Refreshing member group data ');
await GroupsClient(getIt<AuthService>().currentCredentials)
await GroupsClient(getIt<AccountsService>().currentCredentials)
.getGroups()
.match(
onSuccess: (groups) {