Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #198 from krawieck/hotfix/sub-id
Browse files Browse the repository at this point in the history
  • Loading branch information
krawieck authored Apr 6, 2021
2 parents 6e7957f + 88e1f83 commit c32caa2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/add_instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions lib/stores/accounts_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions lib/util/cleanup_url.dart
Original file line number Diff line number Diff line change
@@ -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 '';
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c32caa2

Please sign in to comment.