使用xmpp将聊天发送到会议

时间:2013-05-31 11:29:10

标签: wpf xmpp

我多年来一直试图调试这个。但我不能把它发送到会议。在正常的聊天工作中发送。但不是在会议上。这是我的代码。

_connection.Send(new agsXMPP.protocol.client.Message(new Jid(CurrentContactWindow.Jid), MessageType.chat, Txt_Message.Text));

我使用此代码检索jid以进行正常聊天。

void XmppCon_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
    {
        if (msg.Body != null)
        {
            if (msg.Type == MessageType.groupchat)
            {
                System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
                {
                    _groupMessageView.Add(new GroupMessageView() { Name = msg.From, Message = msg.Body, IsMe = false, DateCreated = DateTime.Now });
                });
                ConstructChatView(false);
            }
            else
            {//this is for normal chat
                var emailMatches = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase).Matches(new Jid(msg.From.ToString()));
                var fromJid = emailMatches.Count > 0 ? emailMatches[0].ToString() : "";

                var message = new Nesv.vChat.Domain.Models.Message()
                {
                    GroupName = fromJid,
                    From = fromJid,
                    Body = msg.Body,
                    IsFromMe = false
                };
                UpdateMessageOnWindow(message);
            }
        }

        if (msg.Type == MessageType.normal)
        {
            try
            {
                var conference = (Conference)msg.LastNode;
                var chatroom = conference.Chatroom;
                var mucManager = new MucManager(_connection);
                mucManager.JoinRoom(chatroom, _connection.Username, true);


                //Get users
                _connection.PresenceGrabber.Add(chatroom, new PresenceCB(PresenceCallback), null);

                System.Windows.Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate()
                {//this is for conference/groupchat
                    _contactView.Add(new ContactView() { Jid = msg.From, Name = chatroom.User, isGroupChat = true });
                });


               // mucManager.

                // sample send message
                //_connection.Send(new agsXMPP.protocol.client.Message(chatroom, MessageType.groupchat, "XOXOXOXOXOX"));
            }
            catch { }
        }
        PrintEvent(msg.Body);
    }

有什么想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个:

_connection.Send(new agsXMPP.protocol.client.Message
(new Jid(CurrentContactWindow.Jid),
agsXMPP.protocol.client.MessageType.groupchat, Txt_Message.Text));