pull refresh on session screen
This commit is contained in:
@@ -382,6 +382,50 @@ class SessionService {
|
||||
await _loadPreferredRelaysIfAvailable();
|
||||
}
|
||||
|
||||
/// Refreshes the current user's Nostr profile and preferred relays.
|
||||
///
|
||||
/// Re-fetches the profile from relays and reloads preferred relays from NIP-05.
|
||||
///
|
||||
/// Throws [SessionException] if refresh fails or if no user is logged in.
|
||||
Future<void> refreshNostrProfile() async {
|
||||
if (_currentUser == null) {
|
||||
throw SessionException('No user logged in.');
|
||||
}
|
||||
|
||||
if (_nostrService == null) {
|
||||
throw SessionException('Nostr service not available');
|
||||
}
|
||||
|
||||
// Only refresh if user has Nostr profile (logged in with Nostr)
|
||||
if (_currentUser!.nostrProfile == null && _currentUser!.nostrPrivateKey == null) {
|
||||
throw SessionException('User is not logged in with Nostr');
|
||||
}
|
||||
|
||||
try {
|
||||
// Re-fetch profile from relays
|
||||
NostrProfile? profile;
|
||||
try {
|
||||
profile = await _nostrService!.fetchProfile(_currentUser!.id);
|
||||
} catch (e) {
|
||||
debugPrint('Warning: Failed to refresh Nostr profile: $e');
|
||||
// Continue without profile update - offline-first behavior
|
||||
}
|
||||
|
||||
// Update user with refreshed profile
|
||||
if (profile != null) {
|
||||
_currentUser = _currentUser!.copyWith(nostrProfile: profile);
|
||||
}
|
||||
|
||||
// Reload preferred relays from NIP-05 if available
|
||||
await _loadPreferredRelaysIfAvailable();
|
||||
} catch (e) {
|
||||
if (e is SessionException) {
|
||||
rethrow;
|
||||
}
|
||||
throw SessionException('Failed to refresh Nostr profile: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal method to load preferred relays from NIP-05 if available.
|
||||
Future<void> _loadPreferredRelaysIfAvailable() async {
|
||||
if (_currentUser == null || _nostrService == null) {
|
||||
|
||||
Reference in New Issue
Block a user