diff --git a/lib/data/repositories/contacts.dart b/lib/data/repositories/contacts.dart index 27908fd..789ff59 100644 --- a/lib/data/repositories/contacts.dart +++ b/lib/data/repositories/contacts.dart @@ -218,7 +218,7 @@ class ContactsRepository { _contactsStreamController.add(c); } - await _updateFromSystemContacts(); + await updateFromSystemContacts(); FlutterContacts.addListener(_systemContactsChangedCallback); // Update the contacts from DHT and subscribe to future updates @@ -322,7 +322,7 @@ class ContactsRepository { // Delay to avoid system update coming in before other updates await Future.delayed(const Duration(milliseconds: 100)); final oldProfileContact = _contacts[profileContactId]; - await _updateFromSystemContacts(); + await updateFromSystemContacts(); if (oldProfileContact != null && oldProfileContact != _contacts[profileContactId]) { // Trigger update of share profiles and all that jazz @@ -371,7 +371,7 @@ class ContactsRepository { /// Update all system contacts in case they changed and add missing ones // TODO: Test that there can be coagulate contacts with a system contact that isn't actually in the system - Future _updateFromSystemContacts() async { + Future updateFromSystemContacts() async { // Try if permissions are granted try { var systemContacts = await systemContactsStorage.getContacts(); diff --git a/lib/ui/locations/cubit.g.dart b/lib/ui/locations/cubit.g.dart index f2e07e6..e5f851f 100644 --- a/lib/ui/locations/cubit.g.dart +++ b/lib/ui/locations/cubit.g.dart @@ -12,10 +12,17 @@ LocationsState _$LocationsStateFromJson(Map json) => (e) => ContactTemporaryLocation.fromJson( e as Map)) ?? const [], + circleMembersips: + (json['circle_membersips'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + const {}, ); Map _$LocationsStateToJson(LocationsState instance) => { 'temporary_locations': instance.temporaryLocations.map((e) => e.toJson()).toList(), + 'circle_membersips': instance.circleMembersips, }; diff --git a/lib/ui/profile/cubit.dart b/lib/ui/profile/cubit.dart index f1dce1c..b5cf3f2 100644 --- a/lib/ui/profile/cubit.dart +++ b/lib/ui/profile/cubit.dart @@ -52,7 +52,12 @@ class ProfileCubit extends Cubit { Future promptCreate() async { if (await FlutterContacts.requestPermission()) { emit(state.copyWith(status: ProfileStatus.create)); - await setContact((await FlutterContacts.openExternalInsert())?.id); + final newContactId = (await FlutterContacts.openExternalInsert())?.id; + if (newContactId != null) { + // TODO: Can we be more trageted here, to only update the one contact id? + await contactsRepository.updateFromSystemContacts(); + } + await setContact(newContactId); } } diff --git a/lib/ui/profile/cubit.g.dart b/lib/ui/profile/cubit.g.dart index c6f69b3..e700ab8 100644 --- a/lib/ui/profile/cubit.g.dart +++ b/lib/ui/profile/cubit.g.dart @@ -17,7 +17,10 @@ ProfileState _$ProfileStateFromJson(Map json) => ProfileState( ? null : ProfileSharingSettings.fromJson( json['sharing_settings'] as Map), - circles: Map.from(json['circles'] as Map), + circles: (json['circles'] as Map?)?.map( + (k, e) => MapEntry(k, e as String), + ) ?? + const {}, permissionsGranted: json['permissions_granted'] as bool? ?? false, ); diff --git a/lib/ui/profile/page.dart b/lib/ui/profile/page.dart index 5c9bf92..604255a 100644 --- a/lib/ui/profile/page.dart +++ b/lib/ui/profile/page.dart @@ -484,16 +484,18 @@ class ProfileViewState extends State { 'profile or pick an existing contact that ' 'contains your data from the address book.', textScaler: TextScaler.linear(1.2))), - // TODO: Only display them when permissions granted, unless creation is possible in coagulate only if (state.permissionsGranted) ...[ - // Re-enable when fixed: https://github.com/QuisApp/flutter_contacts/issues/100 - // TextButton( - // onPressed: context.read().promptCreate, - // child: const Text('Create Profile', - // textScaler: TextScaler.linear(1.2))), - // Container( - // padding: const EdgeInsets.all(8), - // child: const Text('or', textScaler: TextScaler.linear(1.2))), + // Re-enable for Android when fixed: https://github.com/QuisApp/flutter_contacts/issues/100 + if (Platform.isIOS) + TextButton( + onPressed: context.read().promptCreate, + child: const Text('Create Profile', + textScaler: TextScaler.linear(1.2))), + if (Platform.isIOS) + Container( + padding: const EdgeInsets.all(8), + child: + const Text('or', textScaler: TextScaler.linear(1.2))), TextButton( onPressed: context.read().promptPick, child: const Text('Pick Contact as Profile',