Exemple #1
0
 public void OnPresence(Client client, Presence presence)
 {
     var clientContext = SessionModel.GetClientContext(client);
     if (clientContext.Jid.Equals(presence.From, new CaseInsensitiveComparer()))
     {
         return;
     }
     var fromJid = presence.From.ToString().ToLower();
     var capsKey = new CapsSource(client, fromJid);
     ProcessedPresence(capsKey, presence);
 }
Exemple #2
0
 public bool HasFeature(IInterlocutorResource interlocutorResource, string uri)
 {
     var client = ModelContext.GetClientByContact(interlocutorResource.Interlocutor);
     var jid = interlocutorResource.Jid.ToString().ToLower();
     var key = new CapsSource(client, jid);
     CapsInfo capsInfo;
     if (!_presentCaps.TryGetValue(key, out capsInfo))
     {
         return false;
     }
     return _discoveryDataAccess.HasFeature(capsInfo, uri);
 }
        public void RequestFeatures(CapsSource source, CapsInfo info)
        {
            if (_pendingRequests.Contains(info))
            {
                return;
            }
            _pendingRequests.Add(info);
            var connection = GetConnection(source.Client);
            var requestId = Guid.NewGuid().ToString("N");
            _requestIdToCapsInfo.Add(requestId, info);

            var iq = new DiscoInfoIq(IqType.get);
            iq.Id = requestId;
            iq.From = connection.MyJID;
            iq.To = new Jid(source.EntityJid);
            if (info.Hash != null && info.Node != null && info.Version != null)
            {
                iq.Query.Node = string.Format("{0}#{1}", info.Node, info.Version);
            }
            connection.Send(iq);
        }
Exemple #4
0
        private void ProcessedPresence(CapsSource capsKey, Presence presence)
        {
            var capabilities = presence.Capabilities;
            if (capabilities == null)
            {
                _presentCaps.Remove(capsKey);
                return;
            }
            var version = capabilities.Version;
            var hash = capabilities.Hash;
            var node = capabilities.Node;
            var info = new CapsInfo
            {
                Version = version,
                Hash = hash,
                Node = node,
            };

            if (_presentCaps.ContainsKey(capsKey))
            {
                var prevCaps = _presentCaps[capsKey];
                if (prevCaps == info)
                {
                    return;
                }
            }
            _presentCaps[capsKey] = info;

            if (!_discoveryDataAccess.HasCaps(info))
            {
                _discoveryNetAccess.RequestFeatures(capsKey, info);
            }
        }
Exemple #5
0
 protected bool Equals(CapsSource other)
 {
     return Equals(Client, other.Client) && string.Equals(EntityJid, other.EntityJid);
 }