Пример #1
0
    // Add contact to contact list
    void AddNewContact()
    {
        var rm  = new RosterManager(xmppClient);
        var pm  = new PresenceManager(xmppClient);
        Jid jid = ReceiverName.text;

        if (string.IsNullOrEmpty(NickName.text))
        {
            rm.Add(jid, ReceiverName.text);
        }
        else
        {
            rm.Add(jid, NickName.text);
        }
        pm.Subscribe(jid);
    }
Пример #2
0
        private void addToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            var input = new FrmAddUser(_dictContactGroups, true, xmppClient);

            if (input.ShowDialog() == DialogResult.OK)
            {
                _dictContactGroups = input.DictContactGroups;
                var rm  = new RosterManager(xmppClient);
                Jid jid = input.Address;
                rm.Add(jid, input.Name, input.Group);

                var    pm     = new PresenceManager(xmppClient);
                string reason = input.Message;
                pm.Subscribe(jid, reason, input.Name);
            }
        }
Пример #3
0
        /// <summary>
        /// Add new contact by jid
        /// </summary>
        /// <param name="jid"></param>
        public void Add(string jid)
        {
            rosterManager.Add(jid);

            presenceManager.Subscribe(jid);
        }
Пример #4
0
        private void xmppClient_OnPresence(object sender, PresenceEventArgs e)
        {
            DisplayEvent(string.Format("OnPresence\t{0}", e.Presence.From));

            if (e.Presence.Type == PresenceType.Subscribe)
            {
                //presenceManager.ApproveSubscriptionRequest(e.Presence.From);
                var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem;
                if (item != null)
                {
                    var pm = new PresenceManager(xmppClient);
                    pm.ApproveSubscriptionRequest(e.Presence.From);
                }
                else
                {
                    var input = new FrmAddUser(_dictContactGroups, true, xmppClient);
                    input.Address = e.Presence.From;
                    if (input.ShowDialog() == DialogResult.OK)
                    {
                        _dictContactGroups = input.DictContactGroups;
                        var rm  = new RosterManager(xmppClient);
                        Jid jid = input.Address;
                        rm.Add(jid, input.Name, input.Group);

                        var pm = new PresenceManager(xmppClient);
                        pm.ApproveSubscriptionRequest(e.Presence.From);
                        //string reason = input.Message;
                        //pm.Subscribe(jid, reason, input.Name);
                    }
                }
            }
            else if (e.Presence.Type == PresenceType.Subscribed)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
            }
            else if (e.Presence.Type == PresenceType.Unsubscribe)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
                var rm  = new RosterManager(xmppClient);
                Jid jid = e.Presence.From;
                rm.Remove(jid);
            }
            else if (e.Presence.Type == PresenceType.Unsubscribed)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
                var rm  = new RosterManager(xmppClient);
                Jid jid = e.Presence.From;
                rm.Remove(jid);
            }
            else
            {
                var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem;
                if (item != null)
                {
                    item.ImageIndex = Util.GetRosterImageIndex(e.Presence);
                    string resource = e.Presence.From.Resource;
                    if (e.Presence.Type != PresenceType.Unavailable)
                    {
                        if (!item.Resources.Contains(resource))
                        {
                            item.Resources.Add(resource);
                        }
                    }
                    else
                    {
                        if (item.Resources.Contains(resource))
                        {
                            item.Resources.Remove(resource);
                        }
                    }
                }
            }
        }
Пример #5
0
        private void xmppClient_OnPresence(object sender, PresenceEventArgs e)
        {
            DisplayEvent(string.Format("OnPresence\t{0}", e.Presence.From));

            if (e.Presence.Type == PresenceType.Subscribe)
            {
                //presenceManager.ApproveSubscriptionRequest(e.Presence.From);
                var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem;
                if (item != null)
                {
                    var pm = new PresenceManager(xmppClient);
                    pm.ApproveSubscriptionRequest(e.Presence.From);
                }
                else
                {
                    var input = new FrmAddUser(_dictContactGroups, true, xmppClient);
                    input.Address = e.Presence.From;
                    if (input.ShowDialog() == DialogResult.OK)
                    {
                        _dictContactGroups = input.DictContactGroups;
                        var rm = new RosterManager(xmppClient);
                        Jid jid = input.Address;
                        rm.Add(jid, input.Name, input.Group);

                        var pm = new PresenceManager(xmppClient);
                        pm.ApproveSubscriptionRequest(e.Presence.From);
                        //string reason = input.Message;
                        //pm.Subscribe(jid, reason, input.Name);
                    }
                }
            }
            else if (e.Presence.Type == PresenceType.Subscribed)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
            }
            else if (e.Presence.Type == PresenceType.Unsubscribe)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
                var rm = new RosterManager(xmppClient);
                Jid jid = e.Presence.From;
                rm.Remove(jid);
            }
            else if (e.Presence.Type == PresenceType.Unsubscribed)
            {
                var pm = new PresenceManager(xmppClient);
                pm.ApproveSubscriptionRequest(e.Presence.From);
                var rm = new RosterManager(xmppClient);
                Jid jid = e.Presence.From;
                rm.Remove(jid);
            }
            else
            {
                var item = listContacts.Items[e.Presence.From.Bare] as RosterListViewItem;
                if (item != null)
                {
                    item.ImageIndex = Util.GetRosterImageIndex(e.Presence);
                    string resource = e.Presence.From.Resource;
                    if (e.Presence.Type != PresenceType.Unavailable)
                    {
                        if (!item.Resources.Contains(resource))
                            item.Resources.Add(resource);
                    }
                    else
                    {
                        if (item.Resources.Contains(resource))
                            item.Resources.Remove(resource);
                    }
                }
            }
        }
Пример #6
0
        private void addToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            var input = new FrmAddUser(_dictContactGroups, true, xmppClient);
            if (input.ShowDialog() == DialogResult.OK)
            {
                _dictContactGroups = input.DictContactGroups;
                var rm = new RosterManager(xmppClient);
                Jid jid = input.Address;
                rm.Add(jid, input.Name, input.Group);

                var pm = new PresenceManager(xmppClient);
                string reason = input.Message;
                pm.Subscribe(jid, reason, input.Name);
            }
        }