如何用agsXmpp检索某人的头像/照片 [英] How to retrieve Someone's Avatar/Photo with agsXmpp

查看:214
本文介绍了如何用agsXmpp检索某人的头像/照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  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);
}
}

我想我无法撤销哈希,但我想要得到一个人的头像/照片。

解决方案

您需要处理来自XMPP连接的VCard事件和响应:

  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();






$ b

以上是来自AGSXMPP的最小解决方案示例下载。请注意,它发生在用户为用户请求VCARD时。然而,您可以随时发起请求。

  private void VcardResult(object sender,IQ iq,object data)
{
if(InvokeRequired)
{
// Windows窗体不是线程安全的,我们需要调用这个:(
//我们不在UI线程中,所以我们需要调用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。全名;
txtNickname.Text = vcard.Nickname;
txtBirthday.Text = vcard.Birthday.ToString();
txtDescription.Text = vcard.Description;
照片照片= vcard .Photo;
if(photo!= null)
picPhoto.Image = vcard.Photo.Image;
}


}
}

当有人从XMPP请求VCARD信息并且IQ类型与正确的数据匹配时,会发生这种情况。然后,您可以从 vcard.Photo



中吸引照片。


$ b

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

第一行是对XMPP服务器的请求,VCARD表单用于请求用户信息。

在那里的第二行设置另一个抓取器(各种回调),表单用于等待信息到达,然后解析出必要的信息。在这种情况下,抓取器采用新形式,因此主应用程序不必担心解析该信息。



您可以查看整个源代码通过将AGSXMPP zip文件解压缩到本地驱动器,然后查看Samples \VS2008\miniclient文件夹。


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?

解决方案

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.

这篇关于如何用agsXmpp检索某人的头像/照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆