diff --git a/CHANGELOG.md b/CHANGELOG.md index beea2069..e1b7d89b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Fixed + +- Some actions would pass the wrong user id around causing infinite spinners, this is now fixed + ## v0.4.0 - 2021-04-05 ### Added diff --git a/lib/pages/add_instance.dart b/lib/pages/add_instance.dart index 6cebf78d..5aafa13f 100644 --- a/lib/pages/add_instance.dart +++ b/lib/pages/add_instance.dart @@ -25,7 +25,7 @@ class AddInstancePage extends HookWidget { final debounce = useDebounce(() async { if (prevInput == instanceController.text) return; - final inst = cleanUpUrl(instanceController.text); + final inst = normalizeInstanceHost(instanceController.text); if (inst.isEmpty) { isSite.value = null; return; @@ -47,7 +47,7 @@ class AddInstancePage extends HookWidget { instanceController.removeListener(debounce); }; }, []); - final inst = cleanUpUrl(instanceController.text); + final inst = normalizeInstanceHost(instanceController.text); handleOnAdd() async { try { await accountsStore.addInstance(inst, assumeValid: true); diff --git a/lib/stores/accounts_store.dart b/lib/stores/accounts_store.dart index 8e4c7f29..6166f1d5 100644 --- a/lib/stores/accounts_store.dart +++ b/lib/stores/accounts_store.dart @@ -11,7 +11,7 @@ part 'accounts_store.g.dart'; /// Store that manages all accounts @JsonSerializable() class AccountsStore extends ChangeNotifier { - static const prefsKey = 'v2:AccountsStore'; + static const prefsKey = 'v3:AccountsStore'; static final _prefs = SharedPreferences.getInstance(); /// Map containing JWT tokens of specific users. @@ -206,7 +206,9 @@ class AccountsStore extends ChangeNotifier { final userData = await lemmy.run(GetSite(auth: token.raw)).then((value) => value.myUser); - tokens[instanceHost][userData.person.name] = token; + tokens[instanceHost][userData.person.name] = token.copyWith( + payload: token.payload.copyWith(sub: userData.person.id), + ); await _assignDefaultAccounts(); notifyListeners(); diff --git a/lib/util/cleanup_url.dart b/lib/util/cleanup_url.dart index f8182fdb..98ef12b8 100644 --- a/lib/util/cleanup_url.dart +++ b/lib/util/cleanup_url.dart @@ -1,9 +1,9 @@ -/// Returns host of a url without a leading 'www.' or protocol if present also -/// removes trailing '/' -String cleanUpUrl(String url) { +/// Returns a normalized host of a (maybe) url without a leading www. +String normalizeInstanceHost(String maybeUrl) { try { - return urlHost(url.startsWith('https://') ? url : 'https://$url'); - } on FormatException catch (_) { + return urlHost( + maybeUrl.startsWith('https://') ? maybeUrl : 'https://$maybeUrl'); + } on FormatException { return ''; } } diff --git a/pubspec.lock b/pubspec.lock index 2c806945..5c24b4b2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -412,7 +412,7 @@ packages: name: lemmy_api_client url: "https://pub.dartlang.org" source: hosted - version: "0.13.0" + version: "0.14.0" logging: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 14eae0b9..b5b2e592 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,7 +44,7 @@ dependencies: # utils timeago: ^2.0.27 fuzzy: <1.0.0 - lemmy_api_client: ^0.13.0 + lemmy_api_client: ^0.14.0 intl: ^0.17.0 matrix4_transform: ^1.1.7 json_annotation: ^4.0.1