diff --git a/lib/models/user.dart b/lib/models/user.dart index ed1e22d..407b234 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -105,6 +105,16 @@ class User extends base.User with DataModelMixin { settings = belongsTo(map['settings']), super.fromJson(); + User.fromPubkey(String pubkey) + : this.fromJson({ + 'id': pubkey, + 'kind': 0, + 'pubkey': pubkey.hexKey, + 'created_at': DateTime.now().millisecondsSinceEpoch ~/ 1000, + 'content': '{}', + 'tags': [], + }); + Map toJson() => super.toMap(); @DataRelationship(inverse: 'followers') @@ -173,13 +183,8 @@ mixin UserAdapter on NostrAdapter { if (publicKey.startsWith('npub')) { publicKey = publicKey.hexKey; - } else { - // If it's not an npub we treat the string as NIP-05 - if (!publicKey.contains('@')) { - // If it does not have a @, we treat the string as a domain name - publicKey = '_@$publicKey'; - } - + } else if (publicKey.contains('@')) { + // If it's not an npub and it has a @ instead, we treat the string as NIP-05 final [username, domain] = publicKey.split('@'); publicKey = await sendRequest( Uri.parse('https://$domain/.well-known/nostr.json?name=$username'), diff --git a/lib/navigation/app_initializer.dart b/lib/navigation/app_initializer.dart index e499efe..875abad 100644 --- a/lib/navigation/app_initializer.dart +++ b/lib/navigation/app_initializer.dart @@ -50,16 +50,10 @@ final appInitializer = FutureProvider((ref) async { await amberSigner.initialize(); // Set up anon user (pubkey derives from pkSigner secret key) - final anonPubkey = - 'c86eda2daae768374526bc54903f388d9a866c00740ec8db418d7ef2dca77b5b'; - anonUser ??= User.fromJson({ - 'id': anonPubkey, - 'kind': 0, - 'pubkey': anonPubkey, - 'created_at': DateTime.now().millisecondsSinceEpoch ~/ 1000, - 'content': '{}', - 'tags': [], - }).init().saveLocal(); + anonUser ??= User.fromPubkey( + 'c86eda2daae768374526bc54903f388d9a866c00740ec8db418d7ef2dca77b5b') + .init() + .saveLocal(); // App-wide listeners diff --git a/lib/widgets/sign_in_container.dart b/lib/widgets/sign_in_container.dart index 0d71bb1..36ea33e 100644 --- a/lib/widgets/sign_in_container.dart +++ b/lib/widgets/sign_in_container.dart @@ -147,15 +147,9 @@ class SignInDialogBox extends HookConsumerWidget { // If user was not found on relays, we create a // local user to represent this new npub - user ??= User.fromJson({ - 'id': signedInNpub.hexKey, - 'kind': 0, - 'pubkey': signedInNpub.hexKey, - 'created_at': - DateTime.now().millisecondsSinceEpoch ~/ 1000, - 'content': '{}', - 'tags': [], - }).init().saveLocal(); + user ??= User.fromPubkey(signedInNpub.hexKey) + .init() + .saveLocal(); final settings = ref.settings.findOneLocalById('_')!; settings.signInMethod = SignInMethod.nip55;