FileDocCategorySizeDatePackage
ChatSession.javaAPI DocAndroid 1.5 API4567Wed May 06 22:42:46 BST 2009com.android.im.engine

ChatSession

public class ChatSession extends Object
A ChatSession represents a conversation between two users. A ChatSession has a unique participant which is either another user or a group.

Fields Summary
private ImEntity
mParticipant
private ChatSessionManager
mManager
private CopyOnWriteArrayList
mListeners
private Vector
mHistoryMessages
Constructors Summary
ChatSession(ImEntity participant, ChatSessionManager manager)
Creates a new ChatSession with a particular participant.

param
participant the participant with who the user communicates.
param
connection the underlying network connection.

        mParticipant = participant;
        mManager = manager;
        mListeners = new CopyOnWriteArrayList<MessageListener>();
        mHistoryMessages = new Vector<Message>();
    
Methods Summary
public synchronized voidaddMessageListener(MessageListener listener)
Adds a MessageListener so that it can be notified of any new message in this session.

param
listener

        if ((listener != null) && !mListeners.contains(listener)) {
            mListeners.add(listener);
        }
    
public java.util.ListgetHistoryMessages()
Returns a unmodifiable list of the history messages in this session.

return
a unmodifiable list of the history messages in this session.

        return Collections.unmodifiableList(mHistoryMessages);
    
public ImEntitygetParticipant()

        return mParticipant;
    
public voidonReceiveMessage(Message msg)
Called by ChatSessionManager when received a message of the ChatSession. All the listeners registered in this session will be notified.

param
msg the received message.

        mHistoryMessages.add(msg);

        for (MessageListener listener : mListeners) {
            listener.onIncomingMessage(this, msg);
        }
    
public voidonSendMessageError(java.lang.String msgId, ImErrorInfo error)

        for(Message msg : mHistoryMessages){
            if(msgId.equals(msg.getID())){
                onSendMessageError(msg, error);
                return;
            }
        }
        Log.i("ChatSession", "Message has been removed when we get delivery error:"
                + error);
    
public voidonSendMessageError(Message message, ImErrorInfo error)
Called by ChatSessionManager when an error occurs to send a message.

param
message
param
error the error information.

        for (MessageListener listener : mListeners) {
            listener.onSendMessageError(this, message, error);
        }
    
public synchronized voidremoveMessageListener(MessageListener listener)
Removes a listener from this session.

param
listener

        mListeners.remove(listener);
    
public voidsendMessageAsync(java.lang.String text)
Sends a text message to other participant(s) in this session asynchronously. TODO: more docs on async callbacks.

param
text the text to send.

        Message message = new Message(text);
        sendMessageAsync(message);
    
public voidsendMessageAsync(Message msg)
Sends a message to other participant(s) in this session asynchronously. TODO: more docs on async callbacks.

param
msg the message to send.

        msg.setTo(mParticipant.getAddress());

        mHistoryMessages.add(msg);
        mManager.sendMessageAsync(this, msg);
    
public voidsetParticipant(ImEntity participant)

        mParticipant = participant;