// In some apps, these two things are probably the inverse of eachother. Maybe they could be combined? `isNotificationOwnedByThisPage`
// Note: the filtering can only be done by the focused tab, click listening can be done by any tab
beamsClient.addNotificationFilter(notification => {
// Should the given notification be shown if this tab has focus?
// The in-focus tab is asked. The notification is dropped at the first filter to say no (false)
return getOrderId() !== notification.data.order_id
})
beamsClient.addNotificationClickHandler(notification => {
// Should clicking the given notification give focus to this tab?
// The first listener/tab that says yes (true) gets the focus, and the rest aren't asked
if (getOrderId() === notification.data.order_id) {
// Update page
// E.g. navigate to the message that the notification corresponds to
// Tell the Beams Service Worker that this tab should be given the focus
return true
}
return false
})
// Maybe rather than the return value determining the focus, the function could receive an
// event with `event.takeFocus()` grabbing the focus.