Hi,
I'm using UCMA 4.0 and I have an application endpoint established and receiving notifications when a user’s presence has changed. The presence notification supplied to the event handler contains an aggregated state. This is fine most of the time, but when a user has set their status to “Do Not Disturb” and then goes idle then the application endpoint gets a notification with an aggregated state of “Away”. This isn’t ideal because there is no way to tell if they still have their state set to “Do Not Disturb”.
The way I’ve worked around this is as follows (code below):
On each presence notification to the application endpoint, a user endpoint is established for that user. It then subscribes and unsubscribes to the LocalOwnerPresence before closing the endpoint again. This means it receives a single notification with the LocalOwnerPresence details contained in it, which can be used to establish the UserPresenceState rather than just using the AggregatedPresenceState.
void PresenceView_PresenceNotificationReceived(object sender, RemotePresentitiesNotificationEventArgs e) { foreach (var notification in e.Notifications) { var userendpoint = PlatformService.OpenUserEndpoint(notification.PresentityUri, false); try { userendpoint.LocalOwnerPresence.PresenceNotificationReceived += new EventHandler<LocalPresentityNotificationEventArgs>(LocalOwnerPresence_PresenceNotificationReceived); userendpoint.LocalOwnerPresence.EndSubscribe(userendpoint.LocalOwnerPresence.BeginSubscribe(null, null)); userendpoint.LocalOwnerPresence.EndUnsubscribe(userendpoint.LocalOwnerPresence.BeginUnsubscribe(null, null)); userendpoint.LocalOwnerPresence.PresenceNotificationReceived -= new EventHandler<LocalPresentityNotificationEventArgs>(LocalOwnerPresence_PresenceNotificationReceived); } finally { PlatformService.CloseUserEndpoint(userendpoint); } } } void LocalOwnerPresence_PresenceNotificationReceived(object sender, LocalPresentityNotificationEventArgs e) { var presence = (sender as LocalOwnerPresence); if (presence != null) { EntityUpdateService.UpdateEntityPresence(presence.SubscriberEndpoint.OwnerUri, e.AggregatedPresenceState, e.UserPresenceState); } }
This seems like it a very inefficient way of processing the notifications – I haven’t done any testing on large systems yet, but it doesn’t feel like opening a user endpoint for each notification is a good idea. Is there a simpler/more efficient way to achieve this?
Thanks very much,
Richard