mirror of
https://github.com/zapstore/zapstore.git
synced 2026-10-05 20:48:24 +00:00
Add User.fromPubkey constructor
This commit is contained in:
+12
-7
@@ -105,6 +105,16 @@ class User extends base.User with DataModelMixin<User> {
|
||||
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<String, dynamic> toJson() => super.toMap();
|
||||
|
||||
@DataRelationship(inverse: 'followers')
|
||||
@@ -173,13 +183,8 @@ mixin UserAdapter on NostrAdapter<User> {
|
||||
|
||||
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<dynamic>(
|
||||
Uri.parse('https://$domain/.well-known/nostr.json?name=$username'),
|
||||
|
||||
@@ -50,16 +50,10 @@ final appInitializer = FutureProvider<void>((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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user