Skip to content

Commit 0eaaae7

Browse files
committed
feat: expose external parameter to contact event
1 parent f18f6eb commit 0eaaae7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ console.log(`Contact was ${updated ? 'updated' : 'not updated'}.`)
254254

255255
### `contacts.listener`
256256

257-
This module exposes an `EventEmitter`, which can be used to listen to potential changes to the `CNContactStore`. When a contact is changed either with methods contained in this module, or manually by a user, the `contact-changed` event will be emitted.
257+
This module exposes an `EventEmitter`, which can be used to listen to potential changes to the `CNContactStore`. When a contact is changed either with methods contained in this module, or manually by a user, the `contact-changed` event will be emitted with one parameter `external`. This signifies whether or not the change to contact data originated outside the current app.
258258

259259
Owing to the underlying architecture of this module, the listener must be manually managed; before use you must initialize it with `listener.setup()` and when you are finished listening for events you must remove it with `listener.remove()`. To check if a listener is currently active, use `listener.isListening()`.
260260

@@ -274,8 +274,8 @@ addNewContact({
274274
emailAddresses: ['[email protected]'],
275275
})
276276

277-
listener.once('contact-changed', () => {
278-
console.log('A contact was changed!')
277+
listener.once('contact-changed', (external) => {
278+
console.log(`A contact was changed ${external ? 'outside of' : 'within'} this app!`)
279279
listener.remove()
280280
})
281281
```

contacts.mm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,16 @@ CNAuthorizationStatus AuthStatus() {
665665
return;
666666

667667
contacts_ref.Reset();
668-
auto callback = [](Napi::Env env, Napi::Function js_cb,
669-
const char *value) {
670-
js_cb.Call({Napi::String::New(env, value)});
668+
bool external =
669+
[[info objectForKey:@"CNNotificationOriginationExternally"]
670+
boolValue];
671+
672+
auto callback = [external](Napi::Env env, Napi::Function js_cb,
673+
const char *value) {
674+
js_cb.Call({Napi::String::New(env, value),
675+
Napi::Boolean::New(env, external)});
671676
};
677+
672678
ts_fn.BlockingCall("contact-changed", callback);
673679
}];
674680

0 commit comments

Comments
 (0)