Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,21 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/sqflite_darwin/darwin"

SPEC CHECKSUMS:
audio_session: 9bb7f6c970f21241b19f5a3658097ae459681ba0
emoji_picker_flutter: ece213fc274bdddefb77d502d33080dc54e616cc
audio_session: 19e9480dbdd4e5f6c4543826b2e8b0e4ab6145fe
emoji_picker_flutter: 8e50ec5caac456a23a78637e02c6293ea0ac8771
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: c32d145d68aeda5502d5f543ee38c192065986cf
flutter_secure_storage: 1ed9476fba7e7a782b22888f956cce43e2c62f13
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
just_audio: 4e391f57b79cad2b0674030a00453ca5ce817eed
mobile_scanner: 9157936403f5a0644ca3779a38ff8404c5434a93
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
rust_lib_whitenoise: 22de658398f8e36a1a396d35b6b6547a0732e6bb
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
flutter_native_splash: df59bb2e1421aa0282cb2e95618af4dcb0c56c29
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
just_audio: a42c63806f16995daf5b219ae1d679deb76e6a79
mobile_scanner: 77265f3dc8d580810e91849d4a0811a90467ed5e
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
rust_lib_whitenoise: 69ef24b69b2aba78a7ebabc09a504b5a39177d21
share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d

PODFILE CHECKSUM: 251cb053df7158f337c0712f2ab29f4e0fa474ce

Expand Down
57 changes: 56 additions & 1 deletion lib/config/providers/metadata_cache_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

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.

Copy link
Member Author

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.

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);
Copy link
Member

Choose a reason for hiding this comment

The 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 userMetadata method on the bridge is only hitting a sqlite db so it's going to be SUPER fast. e.g. it never hits relays. So I think that you can probably vastly simplify this and just call that method whenever you want the user's metadata anywhere in the app.

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) {
Expand Down
1 change: 1 addition & 0 deletions lib/ui/settings/general_settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class _GeneralSettingsScreenState extends ConsumerState<GeneralSettingsScreen> {
Map<String, ContactModel> _accountContactModels = {}; // Cache for contact models
ProviderSubscription<AsyncValue<ActiveAccountState>>? _activeAccountSubscription;
PackageInfo? _packageInfo;

@override
void initState() {
super.initState();
Expand Down