/// <summary> /// Insert the given message into the history. The timestamp on the message will be used, if /// included, otherwise the current time will be used. /// Messages without bodies will be ignored. /// </summary> /// <param name="msg"></param> public void InsertMessage(Message msg) { string body = msg.Body; if (body == null) return; // typing indicator, e.g. string nick = (m_nick == null) ? msg.From.Resource : m_nick; AppendMaybeScroll(m_recvColor, nick + ":", body); }
/// <summary> /// Create an x:data form from the given message stanza. /// </summary> /// <param name="parent">Original stanza</param> public XDataForm(Msg parent) : this(FindData(parent) as Data) { m_stanza = (Packet) parent.CloneNode(true); Data d = FindData(m_stanza); Debug.Assert(d != null); m_parent = (Element)d.ParentNode; m_parent.RemoveChild(d); }
/// <summary> /// Sends a certain type of message packet to another user. /// </summary> /// <param name="t">The type of message.</param> /// <param name="to">The JID to send the message to.</param> /// <param name="body">The body of the message.</param> public void Message(MessageType t, string to, string body) { if (IsAuthenticated) { Message msg = new Message(Document) {Type = t, To = to, Body = body}; Write(msg); } else { throw new InvalidOperationException("Client must be authenticated before sending messages."); } }
/// <summary> /// Invite a user to join the room. /// </summary> /// <param name="invitee">The JID of the person to invite</param> /// <param name="reason">The reason for the invite, or null for none.</param> public void Invite(JID invitee, string reason) { if (m_state != STATE.running) throw new InvalidOperationException("Must be in running state to send invite: " + m_state.ToString()); if (invitee == null) throw new ArgumentNullException("invitee"); /* <message from='[email protected]/desktop' to='*****@*****.**'> <x xmlns='http://jabber.org/protocol/muc#user'> <invite to='*****@*****.**'> <reason> Hey Hecate, this is the place for all good witches! </reason> </invite> </x> </message> */ Message m = new Message(m_manager.Stream.Document); m.To = m_room; UserX x = new UserX(m_manager.Stream.Document); x.AddInvite(invitee, reason); m.AddChild(x); m_manager.Write(m); }
private void m_stream_OnProtocol(object sender, System.Xml.XmlElement rp) { // There isn't always a from address. iq:roster, for example. string af = rp.GetAttribute("from"); if (af == "") return; JID from = new JID(af); if (from.Bare != (string)m_room) return; // not for this room. switch (rp.LocalName) { case "presence": Presence p = (Presence)rp; if (p.Error != null) { m_state = STATE.error; if (OnPresenceError != null) OnPresenceError(this, p); return; } ParticipantCollection.Modification mod = ParticipantCollection.Modification.NONE; RoomParticipant party = m_participants.Modify(p, out mod); // if this is ours if (p.From == m_jid) { switch (m_state) { case STATE.join: OnJoinPresence(p); break; case STATE.leaving: OnLeavePresence(p); break; case STATE.running: if (p.Type == PresenceType.unavailable) OnLeavePresence(p); break; } } else { switch (mod) { case ParticipantCollection.Modification.NONE: if (OnParticipantPresenceChange != null) OnParticipantPresenceChange(this, party); break; case ParticipantCollection.Modification.JOIN: if (OnParticipantJoin != null) OnParticipantJoin(this, party); break; case ParticipantCollection.Modification.LEAVE: if (OnParticipantLeave != null) OnParticipantLeave(this, party); break; } } break; case "message": Message m = (Message)rp; if (m.Type == MessageType.groupchat) { if (m.Subject != null) { if (OnSubjectChange != null) OnSubjectChange(this, m); m_subject = m; } else if (m.From == m_jid) { if (OnSelfMessage != null) OnSelfMessage(this, m); } else { if (OnRoomMessage != null) OnRoomMessage(this, m); } } else { if (m.From.Resource == null) { // room notification of some kind if (OnAdminMessage != null) OnAdminMessage(this, m); } else { if (OnPrivateMessage != null) OnPrivateMessage(this, m); } } break; case "iq": // TODO: IQs the room sends to us. break; } }
/// <summary> /// Sends a message to everyone currently in the room. /// </summary> /// <param name="body">The message text to send.</param> public void PublicMessage(string body) { if (m_state != STATE.running) throw new InvalidOperationException("Must be in running state to send message: " + m_state.ToString()); /* <message to='*****@*****.**' type='groupchat'> <body>Harpier cries: 'tis time, 'tis time.</body> </message> */ if (body == null) throw new ArgumentNullException("body"); Message m = new Message(m_manager.Stream.Document); m.To = m_room; m.Type = MessageType.groupchat; m.Body = body; m_manager.Write(m); }
/// <summary> /// Sends a private message to a single user in the room. /// </summary> /// <param name="nick">The nickname of the user to send a private message to.</param> /// <param name="body">The message body to send.</param> public void PrivateMessage(string nick, string body) { if (m_state != STATE.running) throw new InvalidOperationException("Must be in running state to send message: " + m_state.ToString()); /* <message to='[email protected]/firstwitch' type='chat'> <body>I'll give thee a wind.</body> </message> */ if (nick == null) throw new ArgumentNullException("nick"); if (body == null) throw new ArgumentNullException("body"); Message m = new Message(m_manager.Stream.Document); m.To = new JID(m_room.User, m_room.Server, nick); m.Type = MessageType.chat; m.Body = body; m_manager.Write(m); }
private void jc_OnMessage(object sender, Message msg) { Data x = msg["x", URI.XDATA] as Data; if (x != null) { muzzle.XDataForm f = new muzzle.XDataForm(msg); f.ShowDialog(this); jc.Write(f.GetResponse()); } else MessageBox.Show(this, msg.Body, msg.From, MessageBoxButtons.OK); }
private void muc_OnInvite(object sender, Message msg) { Room r = sender as Room; r.Join(); }
private void btnSend_Click(object sender, System.EventArgs e) { Message msg = new Message(m_jc.Document); msg.To = txtTo.Text; if (txtSubject.Text != "") msg.Subject = txtSubject.Text; msg.Body = txtBody.Text; m_jc.Write(msg); this.Close(); }