Reputation: 17894
I am using the @protocol in a Flutter app and was wondering if there was a way to verify if another @sign exists before trying to share a key with it. For now I made a function that will try to share a key with the specified @sign. If there is an AtLookUpException, I consider the user non-existent:
/// Check if user exists in this namespace by trying to share a key with them
Future<bool> checkForUser(String atSign) async {
/// Do test send to see if @ sign exists
AtKey testKey = AtKey();
testKey.key = 'test';
testKey.sharedWith = atSign;
try {
await atProtocolService.atClientImpl.put(testKey, 'Are you there?');
return true;
} on AtLookUpException catch (e){
print('AtLookUpException: '+ e.errorMessage);
return false;
}
}
For further verification, you could check the error message of the AtLookUpException which will look like this:
Secondary server not found: No secondary url found for atsign: @bob
Is this the best or quickest way to do this?
Upvotes: 1
Views: 56
Reputation: 36
There is a library available to you that you can use:
https://github.com/atsign-foundation/at_libraries/tree/master/at_server_status
Feel free to adapt any part of the code as you like to fit your use case.
As always, your feedback is welcome.
Upvotes: 1