Realm global event listener


#1

Node version v8.11.3
Npm version v6.2.0
Npm package realm v2.14.0

I have a global event listener which listens to events on all users realms

Realm.Sync.addListener(realms://${SERVER}, adminUser, NOTIFIER_PATH, 'change', handleChange)

Which works perfectly, but when I want to open users realm as some admin user and change something, the change that is made this way also triggers the callback and I have no way of knowing if the change was made by the realm owner (regular user) or the server (admin user).

Realm.open({sync: {url:realms://${SERVER}/${userId}/user-realm, user: adminUser}})

I am aware that using change_event.realm object from the event listener callback to write the changes will not trigger the callback again (not cause a recursion) but I have the need to sometimes make the changes to users realms outside this callback. Which, as I already said, I do by opening a connection to that users realm as an admin user and use that instance to write the changes.
So my question is, is there another way of doing this so it does not trigger the listener callback? Or at least is there a way of distinguishing the realm user that made the change in the listener callback?


#2

@miloban Not at this time - if you want to ignore events then you should build it into your global event listener with a bunch of if/then/else statements that ignore events you know will be written by your admin app. You can build this in your dataModel as well - essentially a field that says if(Person.shouldIgnore == true) return;