public class Chat
extends java.lang.Object
In some situations, it is better to have all messages from the other user delivered
to a Chat rather than just the messages that have a particular thread ID. To
enable this behavior, call setFilteredOnThreadID(boolean)
with
false as the parameter.
XMPPConnection.createChat(String)
Constructor and Description |
---|
Chat(XMPPConnection connection,
java.lang.String participant)
Creates a new chat with the specified user.
|
Chat(XMPPConnection connection,
java.lang.String participant,
java.lang.String threadID)
Creates a new chat with the specified user and thread ID.
|
Modifier and Type | Method and Description |
---|---|
void |
addMessageListener(PacketListener listener)
Adds a packet listener that will be notified of any new messages in the
chat.
|
Message |
createMessage()
Creates a new Message to the chat participant.
|
void |
finalize() |
java.lang.String |
getParticipant()
Returns the name of the user the chat is with.
|
java.lang.String |
getThreadID()
Returns the thread id associated with this chat, which corresponds to the
thread field of XMPP messages.
|
static boolean |
isFilteredOnThreadID()
Returns true if only messages that have a matching threadID will be delivered to Chat
instances.
|
Message |
nextMessage()
Returns the next available message in the chat.
|
Message |
nextMessage(long timeout)
Returns the next available message in the chat.
|
Message |
pollMessage()
Polls for and returns the next message, or null if there isn't
a message immediately available.
|
void |
sendMessage(Message message)
Sends a message to the other chat participant.
|
void |
sendMessage(java.lang.String text)
Sends the specified text as a message to the other chat participant.
|
static void |
setFilteredOnThreadID(boolean value)
Sets whether only messages that have a matching threadID will be delivered to Chat instances.
|
public Chat(XMPPConnection connection, java.lang.String participant)
connection
- the connection the chat will use.participant
- the user to chat with.public Chat(XMPPConnection connection, java.lang.String participant, java.lang.String threadID)
connection
- the connection the chat will use.participant
- the user to chat with.threadID
- the thread ID to use.public static boolean isFilteredOnThreadID()
public static void setFilteredOnThreadID(boolean value)
value
- true if messages delivered to Chat instances are filtered on thread ID.public java.lang.String getThreadID()
public java.lang.String getParticipant()
public void sendMessage(java.lang.String text) throws XMPPException
Message message = chat.createMessage(); message.setBody(messageText); chat.sendMessage(message);
text
- the text to send.XMPPException
- if sending the message fails.public Message createMessage()
sendMessage(Message)
public void sendMessage(Message message) throws XMPPException
createMessage
method.message
- the message to send.XMPPException
- if an error occurs sending the message.public Message pollMessage()
nextMessage()
method since it's non-blocking.
In other words, the method call will always return immediately, whereas the
nextMessage method will return only when a message is available (or after
a specific timeout).public Message nextMessage()
public Message nextMessage(long timeout)
timeout
- the maximum amount of time to wait for the next message.public void addMessageListener(PacketListener listener)
listener
- a packet listener.public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
Copyright © 2003 Jive Software.