Exemplo n.º 1
0
        /// <summary>
        ///   Gets the presence of the given user.
        /// </summary>
        /// <param name = "targetJid">User JID</param>
        public void GetPresence(XmppJid targetJid)
        {
            var presence = new Presence
                               {
                                   Id = XmppIdentifierGenerator.Generate(),
                                   Type = PresenceType.Probe,
                                   From = session.UserId,
                                   To = targetJid
                               };

            session.Send(presence);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Request subscription to the given user
        /// </summary>
        /// <param name = "contactId"></param>
        public void RequestSubscription(XmppJid jid)
        {
            var presence = new Presence
                               {
                                   Type = PresenceType.Subscribe,
                                   To = jid
                               };

            session.Send(presence);
        }
Exemplo n.º 3
0
        /// <summary>
        ///   Sets the presence as Unavailable
        /// </summary>
        public void SetUnavailable()
        {
            var presence = new Presence
                               {
                                   Type = PresenceType.Unavailable
                               };

            session.Send(presence);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Subscribes to presence updates of the current user
        /// </summary>
        /// <param name = "jid"></param>
        public void Unsuscribed(XmppJid jid)
        {
            var presence = new Presence
                               {
                                   Type = PresenceType.Unsubscribed,
                                   To = jid
                               };

            session.Send(presence);
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Sets the initial presence against the given user.
        /// </summary>
        /// <param name = "target">JID of the target user.</param>
        public void SetInitialPresence(XmppJid target)
        {
            var presence = new Presence();

            if (target != null && target.ToString().Length > 0)
            {
                presence.To = target.ToString();
            }

            session.Send(presence);
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Sets the presence state with the given state, status message and priority
        /// </summary>
        /// <param name = "showAs"></param>
        /// <param name = "statusMessage"></param>
        /// <param name = "priority"></param>
        public void SetPresence(XmppPresenceState showAs, string statusMessage, int priority)
        {
            var presence = new Presence();
            var status = new Status();

            status.Value = statusMessage;
            presence.Id = XmppIdentifierGenerator.Generate();

            presence.Items.Add((ShowType) showAs);
            presence.Items.Add(status);

            session.Send(presence);
        }
Exemplo n.º 7
0
        internal void UpdatePresence(XmppJid jid, Presence presence)
        {
            lock (syncObject)
            {
                XmppContactResource resource = resources
                    .Where(contactResource => contactResource.ResourceId.Equals(jid))
                    .SingleOrDefault();

                if (resource == null)
                {
                    resource = new XmppContactResource(session, this, jid);
                    resources.Add(resource);
                }

                resource.Update(presence);

                // Remove the resource information if the contact has gone offline
                if (!resource.IsDefaultResource &&
                    resource.Presence.PresenceStatus == XmppPresenceState.Offline)
                {
                    resources.Remove(resource);
                }

                //NotifyPropertyChanged(() => Presence);
                //NotifyPropertyChanged(() => Resource);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///   Processes the presence message.
        /// </summary>
        /// <param name = "presence">The presence.</param>
        /// <returns></returns>
        private bool ProcessPresenceMessage(Presence presence)
        {
            onPresenceMessage.OnNext(presence);

            return true;
        }
Exemplo n.º 9
0
        internal void Update(Presence presence)
        {
            Presence.Update(presence);

            if (IsDefaultResource && Presence.PresenceStatus == XmppPresenceState.Offline)
            {
                string cachedHash = session.AvatarStorage.GetAvatarHash(ResourceId.BareIdentifier);

                // Grab stored images for offline users
                if (!String.IsNullOrEmpty(cachedHash))
                {
                    // Dipose Avatar Streams
                    DisposeAvatarStream();

                    // Update the avatar hash and file Paths
                    avatarHash = cachedHash;
                    Avatar = session.AvatarStorage.ReadAvatar(ResourceId.BareIdentifier);
                }
            }

            foreach (object item in presence.Items)
            {
                if (item is Error)
                {
            #warning TODO: Handle the error
                }
                else if (item is VCardAvatar)
                {
                    var vcard = (VCardAvatar) item;

                    if (vcard.Photo != null && vcard.Photo.Length > 0)
                    {
                        if (!String.IsNullOrEmpty(vcard.Photo))
                        {
                            // Check if we have the avatar cached
                            string cachedHash = session.AvatarStorage.GetAvatarHash(ResourceId.BareIdentifier);

                            if (cachedHash == vcard.Photo)
                            {
                                // Dispose Avatar Streams
                                DisposeAvatarStream();

                                // Update the avatar hash and file Paths
                                avatarHash = vcard.Photo;
                                Avatar = session.AvatarStorage.ReadAvatar(ResourceId.BareIdentifier);
                            }
                            else
                            {
                                // Update the avatar hash
                                avatarHash = vcard.Photo;

                                // Avatar is not cached request the new avatar information
                                RequestAvatar();
                            }
                        }
                    }
                }
                else if (item is EntityCapabilities)
                {
                    var caps = (EntityCapabilities) item;

                    // Request capabilities only if they aren't cached yet for this resource
                    // or the verfiication string differs from the one that is cached
                    if (Capabilities == null || Capabilities.VerificationString != caps.VerificationString)
                    {
                        Capabilities.Node = caps.Node;
                        Capabilities.HashAlgorithmName = caps.HashAlgorithmName;
                        Capabilities.VerificationString = caps.VerificationString;
                        Capabilities.Identities.Clear();
                        Capabilities.Features.Clear();

                        // Check if we have the capabilities in the storage
                        if (session.ClientCapabilitiesStorage.Exists(caps.Node, caps.VerificationString))
                        {
                            Capabilities = session.ClientCapabilitiesStorage.Get(caps.Node, caps.VerificationString);
                        }
                        else if ((contact.Subscription == XmppContactSubscriptionType.Both ||
                                  contact.Subscription == XmppContactSubscriptionType.To) &&
                                 (!presence.TypeSpecified || presence.Type == PresenceType.Unavailable))
                        {
                            // Discover Entity Capabilities Extension Features
                            DiscoverCapabilities();
                        }

                        // NotifyPropertyChanged(() => Capabilities);
                    }
                }
            }
        }
Exemplo n.º 10
0
        internal void AddDefaultResource()
        {
            var defaultPresence = new Presence();
            var contactResource = new XmppContactResource(session, this, ContactId);
            var resourceJid = new XmppJid(contactId.UserName, ContactId.DomainName, Guid.NewGuid().ToString());

            // Add a default resource
            defaultPresence.TypeSpecified = true;
            defaultPresence.From = resourceJid;
            defaultPresence.Type = PresenceType.Unavailable;

            defaultPresence.Items.Add(XmppContactResource.DefaultPresencePriorityValue);

            contactResource.Update(defaultPresence);

            resources.Add(contactResource);
        }
Exemplo n.º 11
0
        public void AdvertiseCapabilities()
        {
            if (!String.IsNullOrEmpty(ServiceDiscoveryName) &&
                !String.IsNullOrEmpty(Node) &&
                Identities.Count > 0)
            {
                var presence = new Presence
                                   {
                                       Id = XmppIdentifierGenerator.Generate()
                                   };

                if (session.Capabilities != null)
                {
                    presence.Items.Add(GetEntityCapabilities());
                }

                session.Send(presence);
            }
        }
Exemplo n.º 12
0
        private void OnPresenceMessageReceived(Presence message)
        {
            //<presence to='[email protected]/Home' from='[email protected]/carlosga'>
            //    <x xmlns='http://jabber.org/protocol/muc#user'>
            //        <item jid='[email protected]/Home' affiliation='owner' role='moderator'/>
            //        <status code='110'/>
            //    </x>
            //</presence>

            if (message.Items != null && message.Items.Count > 0)
            {
                foreach (object item in message.Items)
                {
                    if (item is MucUser)
                    {
                        ProcessMucUser(item as MucUser);
                    }
                }
            }

            createChatRoomEvent.Set();
            seekEnterChatRoomEvent.Set();
        }
Exemplo n.º 13
0
        /// <summary>
        ///   Enters to the chat room
        /// </summary>
        /// <returns></returns>
        public XmppChatRoom Enter()
        {
            var presence = new Presence
                               {
                                   From = Session.UserId,
                                   To = Identifier
                               };

            presence.Items.Add(new Muc());

            Session.Send(presence);

            createChatRoomEvent.WaitOne();

            return this;
        }
Exemplo n.º 14
0
        /// <summary>
        ///   Closes the chatroom
        /// </summary>
        public void Close()
        {
            var presence = new Presence
                               {
                                   Id = XmppIdentifierGenerator.Generate(),
                                   To = Identifier,
                                   Type = PresenceType.Unavailable
                               };

            PendingMessages.Add(presence.Id);

            Session.Send(presence);
        }
Exemplo n.º 15
0
        internal void Update(Presence presence)
        {
            if (presence.TypeSpecified &&
                presence.Type == PresenceType.Unavailable)
            {
                PresenceStatus = XmppPresenceState.Offline;
            }
            else
            {
                PresenceStatus = XmppPresenceState.Available;
            }

            foreach (object item in presence.Items)
            {
                if (item is sbyte)
                {
                    Priority = (sbyte) item;
                }
                if (item is int)
                {
                    Priority = (int) item;
                }
                else if (item is ShowType)
                {
                    PresenceStatus = DecodeShowAs((ShowType) item);
                }
                else if (item is Status)
                {
                    StatusMessage = ((Status) item).Value;
                }
            }
        }