示例#1
0
        /// <summary>
        /// We received a message
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msg"></param>
        private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            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 OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // check for xData Message
            Element e = msg.SelectSingleElement(typeof(Data));

            if (e != null)
            {
                Data xdata = e as Data;
                if (xdata.Type == XDataFormType.form)
                {
                    frmXData fXData = new frmXData(xdata);
                    fXData.Text = "xData Form from " + msg.From.ToString();
                    fXData.Show();
                }
            }
            else
            {
                if (!Util.Forms.ContainsKey(msg.From.Bare))
                {
                    ListViewItem itm  = FindRosterListViewItem(msg.From);
                    string       nick = itm == null ? msg.From.Bare : itm.Text;

                    frmChat f = new frmChat(msg.From, XmppCon, nick);
                    f.Show();
                    f.IncomingMessage(msg);
                }
            }
        }
示例#2
0
文件: frmMain.cs 项目: don59/agsXmpp
		/// <summary>
		/// We received a message
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="msg"></param>
		private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
		{
			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 OnMessageDelegate(XmppCon_OnMessage), new object[]{sender, msg});
				return;
			}

			// check for xData Message
			Element e = msg.SelectSingleElement(typeof(Data));
			if (e != null)
			{	
				Data xdata = e as Data;
				if (xdata.Type == XDataFormType.form)
				{
					frmXData fXData = new frmXData(xdata);
					fXData.Text = "xData Form from " + msg.From.ToString();
					fXData.Show();
				}
			}
			else
			{
				if (!Util.Forms.ContainsKey(msg.From.Bare))
				{
					ListViewItem itm = FindRosterListViewItem(msg.From);
					string nick =  itm == null ? msg.From.Bare : itm.Text;
				
					frmChat f = new frmChat(msg.From, XmppCon, nick);
					f.Show();
					f.IncomingMessage(msg);
				}
			}
		}
示例#3
0
文件: frmMain.cs 项目: don59/agsXmpp
        /// <summary>
		/// We received a message
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="msg"></param>
		private void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
		{
            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 OnMessageDelegate(XmppCon_OnMessage), new object[] { sender, msg });
                return;
            }

            // Dont handle GroupChat Messages here, they have their own callbacks in the
            // GroupChat Form
            if (msg.Type == MessageType.groupchat)
                return;

            if (msg.Type == MessageType.error)
            {
                //Handle errors here
                // we dont handle them in this example
                return;
            }			

			// check for xData Message
			
			if (msg.HasTag(typeof(Data)))
			{	
                Element e = msg.SelectSingleElement(typeof(Data));                
				Data xdata = e as Data;
				if (xdata.Type == XDataFormType.form)
				{
					frmXData fXData = new frmXData(xdata);
					fXData.Text = "xData Form from " + msg.From.ToString();
					fXData.Show();
				}
			}
            else if(msg.HasTag(typeof(agsXMPP.protocol.extensions.ibb.Data)))
            {
                // ignore IBB messages
                return;
            }
			else
			{
                if (msg.Body != null)
                {
                    if (!Util.ChatForms.ContainsKey(msg.From.Bare))
                    {
                        RosterNode rn = rosterControl.GetRosterItem(msg.From);
                        string nick = msg.From.Bare;
                        if (rn != null)
                            nick = rn.Text;

                        frmChat f = new frmChat(msg.From, XmppCon, nick);
                        f.Show();
                        f.IncomingMessage(msg);
                    }
                }
			}
		}