Esempio n. 1
0
        /// <summary>
        ///   Sends the message.
        /// </summary>
        /// <param name = "message">The message.</param>
        public string SendMessage(string message)
        {
            if (session == null)
            {
                throw new InvalidOperationException("Chat session is closed.");
            }

            var body = new MessageBody
            {
                Value = message
            };

            var chatMessage = new Message
            {
                ID   = XmppIdentifierGenerator.Generate(),
                Type = MessageType.Chat,
                From = session.UserId.ToString(),
                To   = Contact.ContactId.ToString(),
            };

            if (Contact.SupportsChatStateNotifications)
            {
                chatMessage.Items.Add(CreateChatStateNotification(XmppChatStateNotification.Active));
            }

            chatMessage.Items.Add(body);

            session.Send(chatMessage);

            return(chatMessage.ID);
        }
        private void DiscoverCapabilities()
        {
            var requestIq = new IQ();
            var request   = new ServiceQuery();

            request.Node   = Capabilities.DiscoveryInfoNode;
            requestIq.From = session.UserId;
            requestIq.ID   = XmppIdentifierGenerator.Generate();
            requestIq.To   = ResourceId;
            requestIq.Type = IQType.Get;

            requestIq.Items.Add(request);

            pendingMessages.Add(requestIq.ID);

            session.Send(requestIq);
        }
Esempio n. 3
0
        /// <summary>
        ///   Refreshes the blocked contacts list
        /// </summary>
        /// <returns></returns>
        public XmppRoster RefreshBlockedContacts()
        {
#warning TODO: Check if contact list should be stored in a separated collection or the information should be injected into XmppContact class
            if (session.ServiceDiscovery.SupportsBlocking)
            {
                var iq = new IQ
                {
                    ID   = XmppIdentifierGenerator.Generate(),
                    Type = IQType.Get
                };

                iq.Items.Add(new BlockList());

                session.Send(iq);
            }

            return(this);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        ///   Adds to group.
        /// </summary>
        /// <param name = "groupName">Name of the group.</param>
        public void AddToGroup(string groupName)
        {
            var iq    = new IQ();
            var query = new RosterQuery();
            var item  = new RosterItem();

            if (!Groups.Contains(groupName))
            {
                Groups.Add(groupName);
            }

            iq.Type = IQType.Set;

            item.Jid          = ContactId.BareIdentifier;
            item.Name         = Name;
            item.Subscription = (RosterSubscriptionType)Subscription;

            item.Groups.Add(groupName);

            query.Items.Add(item);
            iq.Items.Add(query);

            session.Send(iq);
        }