public void closeChatSession(ChatSessionAdapter adapter) {
   synchronized (mActiveSessions) {
     ChatSession session = adapter.getAdaptee();
     mSessionManager.closeChatSession(session);
     mActiveSessions.remove(adapter.getAddress());
   }
 }
  public ChatSessionManagerAdapter(ImConnectionAdapter connection) {
    mConnection = connection;
    ImConnection connAdaptee = connection.getAdaptee();
    mSessionManager = connAdaptee.getChatSessionManager();
    mActiveSessions = new HashMap<String, ChatSessionAdapter>();
    mSessionListenerAdapter = new ChatSessionListenerAdapter();
    mSessionManager.addChatSessionListener(mSessionListenerAdapter);

    if ((connAdaptee.getCapability() & ImConnection.CAPABILITY_GROUP_CHAT) != 0) {
      mGroupManager = connAdaptee.getChatGroupManager();
      mGroupManager.addGroupListener(new ChatGroupListenerAdpater());
    }
  }
 public IChatSession createChatSession(String contactAddress) {
   ContactListManagerAdapter listManager =
       (ContactListManagerAdapter) mConnection.getContactListManager();
   Contact contact = listManager.getContactByAddress(contactAddress);
   if (contact == null) {
     try {
       contact = listManager.createTemporaryContact(contactAddress);
     } catch (IllegalArgumentException e) {
       mSessionListenerAdapter.notifyChatSessionCreateFailed(
           contactAddress,
           new ImErrorInfo(
               ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
       return null;
     }
   }
   ChatSession session = mSessionManager.createChatSession(contact);
   return getChatSessionAdapter(session);
 }