Smack

org.jivesoftware.smack
Class Chat

java.lang.Object
  extended by org.jivesoftware.smack.Chat

public class Chat
extends Object

A chat is a series of messages sent between two users. Each chat has a unique thread ID, which is used to track which messages are part of a particular conversation. Some messages are sent without a thread ID, and some clients don't send thread IDs at all. Therefore, if a message without a thread ID arrives it is routed to the most recently created Chat with the message sender.

Author:
Matt Tucker

Method Summary
 void addMessageListener(MessageListener listener)
          Adds a packet listener that will be notified of any new messages in the chat.
 PacketCollector createCollector()
          Creates a PacketCollector which will accumulate the Messages for this chat.
 boolean equals(Object obj)
           
 Collection<MessageListener> getListeners()
          Returns an unmodifiable collection of all of the listeners registered with this chat.
 String getParticipant()
          Returns the name of the user the chat is with.
 String getThreadID()
          Returns the thread id associated with this chat, which corresponds to the thread field of XMPP messages.
 void removeMessageListener(MessageListener listener)
           
 void sendMessage(Message message)
          Sends a message to the other chat participant.
 void sendMessage(String text)
          Sends the specified text as a message to the other chat participant.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getThreadID

public String getThreadID()
Returns the thread id associated with this chat, which corresponds to the thread field of XMPP messages. This method may return null if there is no thread ID is associated with this Chat.

Returns:
the thread ID of this chat.

getParticipant

public String getParticipant()
Returns the name of the user the chat is with.

Returns:
the name of the user the chat is occuring with.

sendMessage

public void sendMessage(String text)
                 throws XMPPException
Sends the specified text as a message to the other chat participant. This is a convenience method for:
     Message message = chat.createMessage();
     message.setBody(messageText);
     chat.sendMessage(message);
 

Parameters:
text - the text to send.
Throws:
XMPPException - if sending the message fails.

sendMessage

public void sendMessage(Message message)
                 throws XMPPException
Sends a message to the other chat participant. The thread ID, recipient, and message type of the message will automatically set to those of this chat.

Parameters:
message - the message to send.
Throws:
XMPPException - if an error occurs sending the message.

addMessageListener

public void addMessageListener(MessageListener listener)
Adds a packet listener that will be notified of any new messages in the chat.

Parameters:
listener - a packet listener.

removeMessageListener

public void removeMessageListener(MessageListener listener)

getListeners

public Collection<MessageListener> getListeners()
Returns an unmodifiable collection of all of the listeners registered with this chat.

Returns:
an unmodifiable collection of all of the listeners registered with this chat.

createCollector

public PacketCollector createCollector()
Creates a PacketCollector which will accumulate the Messages for this chat. Always cancel PacketCollectors when finished with them as they will accumulate messages indefinitely.

Returns:
the PacketCollector which returns Messages for this chat.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

Smack

Copyright © 2003-2007 Jive Software.