-
Notifications
You must be signed in to change notification settings - Fork 14
Update profile name immediately after editing #559
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,62 @@ class MetadataCacheNotifier extends Notifier<MetadataCacheState> { | |
| final _logger = Logger('MetadataCacheNotifier'); | ||
|
|
||
| @override | ||
| MetadataCacheState build() => const MetadataCacheState(); | ||
| MetadataCacheState build() { | ||
| // Listen for active account changes to keep cache in sync with latest metadata | ||
| ref.listen(activeAccountProvider, (previous, next) { | ||
| next.when( | ||
| data: (activeAccountState) { | ||
| final account = activeAccountState.account; | ||
| final metadata = activeAccountState.metadata; | ||
|
|
||
| if (account != null && metadata != null) { | ||
| _updateCacheForActiveAccount(account.pubkey, metadata); | ||
| } | ||
| }, | ||
| loading: () {}, | ||
| error: (_, _) {}, | ||
| ); | ||
| }); | ||
|
|
||
| return const MetadataCacheState(); | ||
| } | ||
|
|
||
| /// Update cache for active account when metadata changes | ||
| Future<void> _updateCacheForActiveAccount(String pubkey, FlutterMetadata metadata) async { | ||
| try { | ||
| // Get standardized npub for consistent caching | ||
| final standardNpub = await _getStandardizedNpub(pubkey); | ||
|
|
||
| // Check if we already have the same metadata cached to avoid unnecessary rebuilds | ||
| final existingCached = state.cache[standardNpub]; | ||
| if (existingCached != null && !existingCached.isExpired) { | ||
| final existing = existingCached.contactModel; | ||
| if (existing.displayName == metadata.displayName && | ||
| existing.about == metadata.about && | ||
| existing.nip05 == metadata.nip05) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Create contact model from updated metadata | ||
| final contactModel = ContactModel.fromMetadata( | ||
| publicKey: standardNpub, | ||
| metadata: metadata, | ||
| ); | ||
|
|
||
| // Update the cache | ||
| final newCache = Map<String, CachedMetadata>.from(state.cache); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're trying to completely remove the CachedMetadata from the app altogether. Can you maybe sync with Josefina about this? The new |
||
| newCache[standardNpub] = CachedMetadata( | ||
| contactModel: contactModel, | ||
| cachedAt: DateTime.now(), | ||
| ); | ||
|
|
||
| state = state.copyWith(cache: newCache); | ||
| _logger.info('Updated cache for active account: $standardNpub'); | ||
| } catch (e) { | ||
| _logger.warning('Failed to update cache for active account $pubkey: $e'); | ||
| } | ||
| } | ||
|
|
||
| /// Normalize a public key string to consistent format | ||
| String _normalizePublicKey(String publicKey) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nice. I have a concern though: are we sure activeAccountProvider only rebuilds on metadata change? If yes, cool but if not, I'm not sure we want to run the operation everytime. The upside is that this operation is not expensive so I'll just leave this as a question/comment/discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I didn't care about this since it's just a map write and the metadata will be removed soon. But you're right, so I added a comparison.