diff --git a/conversations/reachability-indicator/process-user-updates/meta.json b/conversations/reachability-indicator/process-user-updates/meta.json new file mode 100644 index 000000000..b2a342481 --- /dev/null +++ b/conversations/reachability-indicator/process-user-updates/meta.json @@ -0,0 +1,5 @@ +{ + "title": "Handle Reachability updates on client side", + "description": "Handle an UpdateReason change and process the Reachability Indicators", + "type": "mobile" +} diff --git a/conversations/reachability-indicator/process-user-updates/process-user-updates.js b/conversations/reachability-indicator/process-user-updates/process-user-updates.js new file mode 100644 index 000000000..c92c59dd0 --- /dev/null +++ b/conversations/reachability-indicator/process-user-updates/process-user-updates.js @@ -0,0 +1,18 @@ +// function called after client init to set up event handlers +function registerEventHandlers() { + user = conversationsClient.user; + // Register User updated event handler + user.on('updated', function(event) { + handleUserUpdate(event.user, event.updateReasons) + }); +} + +// function to handle User updates +function handleUserUpdate(user, updateReasons) { + // loop over each reason and check for reachability change + updateReasons.forEach(function(reason) { + if (reason == 'online') { + //do something + } + }); +}