How to retrieve Someone's Avatar/Photo with agsXmpp

拟墨画扇 提交于 2019-12-11 06:12:25

问题


this is what I have so far:

void xmppConnection_OnReadXml(object sender, string xml)
    {
        if (xml.Contains(XmlTags.PhotoOpen))
        {
            int startIndex = xml.IndexOf(XmlTags.PhotoOpen) + XmlTags.PhotoOpen.Length;
            int length = xml.IndexOf(XmlTags.PhotoClose) - startIndex;
            string photoHash = xml.Substring(startIndex, length);
        }
    }

I guess I can't undo the hash, but I want to the get a person's avatar/photo. How do I achieve this?


回答1:


You need to handle the VCard events and responses from XMPP connection:

        private void vcardToolStripMenuItem_Click(object sender, EventArgs e)
    {
        RosterNode node = rosterControl.SelectedItem();
        if (node != null)
        {
            frmVcard f = new frmVcard(node.RosterItem.Jid, XmppCon);
            f.Show();
        }
    }

The above is from the miniclient solution example from the AGSXMPP download. Note, it happens when a user request a VCARD for a user. You can initiate that request whenever you want, however.

private void VcardResult(object sender, IQ iq, object data)
    {
        if (InvokeRequired)
        {
            // Windows Forms are not Thread Safe, we need to invoke this :(
            // We're not in the UI thread, so we need to call BeginInvoke               
            BeginInvoke(new IqCB(VcardResult), new object[] { sender, iq, data });
            return;
        }
        if (iq.Type == IqType.result)
        {
            Vcard vcard = iq.Vcard;
            if (vcard!=null)
            {
                txtFullname.Text    = vcard.Fullname;
                txtNickname.Text    = vcard.Nickname;
                txtBirthday.Text    = vcard.Birthday.ToString();
                txtDescription.Text = vcard.Description;
                Photo photo = vcard.Photo;
                if (photo != null)
                    picPhoto.Image      = vcard.Photo.Image;
            }


        }
    }

That is what happens when someone requests the VCARD information from XMPP and the IQ type matches the proper data. You can thenpull the photo from vcard.Photo.

You trigger the pull with:

VcardIq viq = new VcardIq(IqType.get, new Jid(jid.Bare));
con.IqGrabber.SendIq(viq, new IqCB(VcardResult), null);     

The first line there is the request to the XMPP server, that the VCARD form uses to request user information.

The second line there, sets up another grabber (callback of sorts), that the form uses to wait for the information to arrive, and then parse out the necessary information. IN this case, the grabber is in a new form, so that the main application doesn't have to worry about parsing that information.

You can look at the entire source by extracting the AGSXMPP zip file to your local drive, and looking in the Samples\VS2008\miniclient folder.




回答2:


You can click link:http://forum.ag-software.de/thread/192-How-to-save-vcard-data



来源:https://stackoverflow.com/questions/6403088/how-to-retrieve-someones-avatar-photo-with-agsxmpp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!