Remove currentHandle/server/avatar/id from AuthService

codemagic-setup
Hank Grabowski 2023-02-24 16:08:14 -05:00
rodzic f3d195c9c0
commit c03a5b7b19
7 zmienionych plików z 45 dodań i 60 usunięć

Wyświetl plik

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

Wyświetl plik

@ -42,7 +42,8 @@ class _UserProfileScreenState extends State<UserProfileScreen> {
Widget build(BuildContext context) {
final manager = context.watch<ConnectionsManager>();
final body = manager.getById(widget.userId).fold(onSuccess: (profile) {
final notMyProfile = getIt<AuthService>().currentId != profile.id;
final notMyProfile =
getIt<AuthService>().currentClient.credentials.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>().currentId != senderId) {
if (getIt<AuthService>().currentClient.credentials.userId != senderId) {
final s = ConnectionFriendicaExtensions.fromJson(json['sender']);
if (cm.getById(s.id).isFailure) {
cm.addConnection(s);
}
}
if (getIt<AuthService>().currentId != recipientId) {
if (getIt<AuthService>().currentClient.credentials.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>().currentServer;
final server = getIt<AuthService>().currentClient.serverName;
handle = '$handleFromJson@$server';
}

Wyświetl plik

@ -16,15 +16,7 @@ class AuthService extends ChangeNotifier {
bool get loggedIn => _loggedIn && _friendicaClient != null;
FriendicaClient get currentClient => _friendicaClient!;
String get currentId => _friendicaClient?.credentials.userId ?? '';
String get currentHandle => _friendicaClient?.credentials.handle ?? '';
String get currentServer => _friendicaClient?.credentials.serverName ?? '';
String get currentAvatarUrl => _friendicaClient?.credentials.avatar ?? '';
Future<bool> getStoredLoginState() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getBool('logged-in') ?? false;

Wyświetl plik

@ -43,7 +43,7 @@ class EntryManagerService extends ChangeNotifier {
Result<EntryTreeItem, ExecError> getPostTreeEntryBy(String id) {
_logger.finest('Getting post: $id');
final auth = getIt<AuthService>();
final currentId = getIt<AuthService>().currentClient.credentials.userId;
final postNode = _getPostRootNode(id);
if (postNode == null) {
return Result.error(ExecError(
@ -52,7 +52,7 @@ class EntryManagerService extends ChangeNotifier {
));
}
return Result.ok(_nodeToTreeItem(postNode, auth.currentId));
return Result.ok(_nodeToTreeItem(postNode, currentId));
}
Result<TimelineEntry, ExecError> getEntryById(String id) {
@ -78,7 +78,8 @@ class EntryManagerService extends ChangeNotifier {
return Result.ok(true);
}
FutureResult<bool, ExecError> createNewStatus(String text, {
FutureResult<bool, ExecError> createNewStatus(
String text, {
String spoilerText = '',
String inReplyToId = '',
required NewEntryMediaItems mediaItems,
@ -107,11 +108,10 @@ class EntryManagerService extends ChangeNotifier {
}
final uploadResult =
await MediaUploadAttachmentHelper.getUploadableImageBytes(
await MediaUploadAttachmentHelper.getUploadableImageBytes(
item.localFilePath,
).andThenAsync(
(imageBytes) async =>
await client.uploadFileAsAttachment(
(imageBytes) async => await client.uploadFileAsAttachment(
bytes: imageBytes,
album: mediaItems.albumName,
description: item.description,
@ -129,10 +129,10 @@ class EntryManagerService extends ChangeNotifier {
final result = await client
.createNewStatus(
text: text,
spoilerText: spoilerText,
inReplyToId: inReplyToId,
mediaIds: mediaIds)
text: text,
spoilerText: spoilerText,
inReplyToId: inReplyToId,
mediaIds: mediaIds)
.andThenSuccessAsync((item) async {
await processNewItems([item], client.credentials.username, null);
return item;
@ -153,7 +153,7 @@ class EntryManagerService extends ChangeNotifier {
_logger.finest('${status.id} status created');
return true;
}).mapError(
(error) {
(error) {
_logger.finest('Error creating post: $error');
return ExecError(
type: ErrorType.localError,
@ -183,9 +183,7 @@ class EntryManagerService extends ChangeNotifier {
final updatedPosts = await processNewItems(
itemsResult.value, client.credentials.userId, client);
_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 orphanCount = _entries.values
.where(
@ -196,9 +194,11 @@ class EntryManagerService extends ChangeNotifier {
return Result.ok(updatedPosts);
}
Future<List<EntryTreeItem>> processNewItems(List<TimelineEntry> items,
String currentId,
FriendicaClient? client,) async {
Future<List<EntryTreeItem>> processNewItems(
List<TimelineEntry> items,
String currentId,
FriendicaClient? client,
) async {
items.sort((i1, i2) => int.parse(i1.id).compareTo(int.parse(i2.id)));
final allSeenItems = [...items];
for (final item in items) {
@ -225,9 +225,7 @@ class EntryManagerService extends ChangeNotifier {
await client
?.getPostOrComment(o.id, fullContext: true)
.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;
allSeenItems.addAll(items);
for (final item in items) {
@ -255,7 +253,7 @@ class EntryManagerService extends ChangeNotifier {
for (final item in seenItemsCopy) {
if (item.parentId.isEmpty) {
final postNode =
_postNodes.putIfAbsent(item.id, () => _Node(item.id));
_postNodes.putIfAbsent(item.id, () => _Node(item.id));
postNodesToReturn.add(postNode);
allSeenItems.remove(item);
} else {
@ -297,9 +295,7 @@ class EntryManagerService extends ChangeNotifier {
.toList();
_logger.finest(
'Completed processing new items ${client == null
? 'sub level'
: 'top level'}');
'Completed processing new items ${client == null ? 'sub level' : 'top level'}');
return updatedPosts;
}
@ -308,11 +304,10 @@ class EntryManagerService extends ChangeNotifier {
final client = getIt<AuthService>().currentClient;
final result = await client
.getPostOrComment(id, fullContext: false)
.andThenAsync((rootItems) async =>
await client
.getPostOrComment(id, fullContext: true)
.andThenSuccessAsync(
(contextItems) async => [...rootItems, ...contextItems]))
.andThenAsync((rootItems) async => await client
.getPostOrComment(id, fullContext: true)
.andThenSuccessAsync(
(contextItems) async => [...rootItems, ...contextItems]))
.andThenSuccessAsync((items) async {
await processNewItems(items, client.credentials.username, null);
});
@ -321,7 +316,7 @@ class EntryManagerService extends ChangeNotifier {
_logger.finest('$id post updated');
return _nodeToTreeItem(_getPostRootNode(id)!, client.credentials.userId);
}).mapError(
(error) {
(error) {
_logger.finest('$id error updating: $error');
return ExecError(
type: ErrorType.localError,
@ -335,7 +330,7 @@ class EntryManagerService extends ChangeNotifier {
_logger.finest('Resharing post: $id');
final client = getIt<AuthService>().currentClient;
final result =
await client.resharePost(id).andThenSuccessAsync((item) async {
await client.resharePost(id).andThenSuccessAsync((item) async {
await processNewItems([item], client.credentials.username, null);
});
@ -343,7 +338,7 @@ class EntryManagerService extends ChangeNotifier {
_logger.finest('$id post updated after reshare');
return _nodeToTreeItem(_postNodes[id]!, client.credentials.userId);
}).mapError(
(error) {
(error) {
_logger.finest('$id error updating: $error');
return ExecError(
type: ErrorType.localError,
@ -355,11 +350,9 @@ class EntryManagerService extends ChangeNotifier {
FutureResult<bool, ExecError> unResharePost(String id) async {
_logger.finest('Unresharing post: $id');
final client = getIt<AuthService>()
.currentClient;
final result = await client
.unResharePost(id)
.andThenSuccessAsync((item) async {
final client = getIt<AuthService>().currentClient;
final result =
await client.unResharePost(id).andThenSuccessAsync((item) async {
await processNewItems([item], client.credentials.username, null);
});
@ -373,12 +366,10 @@ class EntryManagerService extends ChangeNotifier {
return Result.ok(true);
}
FutureResult<EntryTreeItem, ExecError> toggleFavorited(String id,
bool newStatus) async {
final client = getIt<AuthService>()
.currentClient;
final result = await client
.changeFavoriteStatus(id, newStatus);
FutureResult<EntryTreeItem, ExecError> toggleFavorited(
String id, bool newStatus) async {
final client = getIt<AuthService>().currentClient;
final result = await client.changeFavoriteStatus(id, newStatus);
if (result.isFailure) {
return result.errorCast();
}
@ -467,7 +458,7 @@ class _Node {
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is _Node && runtimeType == other.runtimeType && id == other.id;
other is _Node && runtimeType == other.runtimeType && id == other.id;
@override
int get hashCode => id.hashCode;

Wyświetl plik

@ -151,7 +151,7 @@ class NotificationsManager extends ChangeNotifier {
}
List<UserNotification> buildUnreadMessageNotifications() {
final myId = getIt<AuthService>().currentId;
final myId = getIt<AuthService>().currentClient.credentials.userId;
final result =
getIt<DirectMessageService>().getThreads(unreadyOnly: true).map((t) {
final fromAccount = t.participants.firstWhere((p) => p.id != myId);