예제 #1
0
        /// <summary>
        /// Gets whether or not the contact is available.
        /// </summary>
        /// <param name="localEndpoint"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        async Task<bool> GetAvailableAsync(LocalEndpoint localEndpoint, CancellationToken cancellationToken)
        {
            // obtain presense state
            var presence = await localEndpoint
                .GetPresenceContext()
                .GetPresenceStateAsync(Endpoint.Uri, cancellationToken);
            
            // assume present if no status at all; failsafe
            if (presence == null)
                return true;

            // currently online
            if (presence.Availability == PresenceAvailability.IdleOnline ||
                presence.Availability == PresenceAvailability.None ||
                presence.Availability == PresenceAvailability.Online)
                return true;

            // active within 30 seconds
            if (DateTime.UtcNow - presence.LastActive <= TimeSpan.FromSeconds(30))
                return true;

            return false;
        }