fix: prevent insertion of duplicate phone numbers when calling updateContact #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the issue where we'd see vCards with multiple identical phone numbers for the same contact (sometimes formatted differently, e.g. with
+1
).I've traced the error back to
react-native-contacts
creating new phone number entries in the database.The issue has been solved but we forked
react-native-contacts
in early 2019 and haven't rebased/merged since then. Relevant github issue:morenoh149#332
The tl:dr is: previously,
updateContact
would expect the phone number entries to have theid
attached to it so it could update that number - without anid
, it would insert a new row instead. SinceupdateContact
expects the entire contact to be passed in as an argument, contributors found that a good solution was to delete all existing numbers and then insert the new number.This PR patches the
updateContact
method with these change.To test: you can confirm the behaviour of this bug currently by adding logs before the
updateContact
call in react-native in LightOS (insrc/lib/LightOS/Contacts.js
), as well as logging the response (the library responds with the updated contact). You can see before and after editing a contact (you don't have to even make any changes, a call toupdateContact
will cause the bug) that the vcard exported from the dash will have an extra TEL entry. As well, the response toupdateContact
will show the duplicate row(s).Then, you can
rm -rf node_modules
, update the branch specified inpackage.json
fromlightos
tofix/number-upsert
,yarn install
, clear the build cache and rebuild. Upon running the same tests, you'll see that the contact always only has 1 number in the vcard and in the response fromreact-native-contacts
.