Search in sources :

Example 16 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class XmppConnection method handleChatState.

private void handleChatState(String from, String chatStateXml) throws RemoteException {
    Presence p = null;
    Contact contact = mContactListManager.getContact(from);
    if (contact == null)
        return;
    boolean isTyping = false;
    // handle is-typing, probably some indication on screen
    if (chatStateXml.contains("'error'") || chatStateXml.contains("'cancel'")) {
    // do nothing
    } else if (chatStateXml.contains(ChatState.active.toString())) {
        p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.inactive.toString())) {
        p = new Presence(Presence.AWAY, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.composing.toString())) {
        p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
        isTyping = true;
        p.setLastSeen(new Date());
    } else if (chatStateXml.contains(ChatState.inactive.toString()) || chatStateXml.contains(ChatState.paused.toString())) {
    } else if (chatStateXml.contains(ChatState.gone.toString())) {
    }
    IChatSession csa = mSessionManager.getAdapter().getChatSession(from);
    if (csa != null)
        csa.setContactTyping(contact, isTyping);
    if (p != null) {
        String[] presenceParts = from.split("/");
        if (presenceParts.length > 1)
            p.setResource(presenceParts[1]);
        contact.setPresence(p);
        Collection<Contact> contactsUpdate = new ArrayList<Contact>();
        contactsUpdate.add(contact);
        mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
    }
}
Also used : ArrayList(java.util.ArrayList) Presence(org.awesomeapp.messenger.model.Presence) IChatSession(org.awesomeapp.messenger.service.IChatSession) Date(java.util.Date) Contact(org.awesomeapp.messenger.model.Contact)

Example 17 with IChatSession

use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.

the class ChatSessionManagerAdapter method createChatSession.

public IChatSession createChatSession(String contactAddress, boolean isNewSession) {
    ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
    Contact contact = listManager.getContactByAddress(Address.stripResource(contactAddress));
    if (contact == null) {
        try {
            contact = new Contact(new XmppAddress(contactAddress), contactAddress, Imps.Contacts.TYPE_NORMAL);
        // long contactId = listManager.queryOrInsertContact(contact);
        // String[] address = {Address.stripResource(contactAddress)};
        // contact = listManager.createTemporaryContacts(address)[0];
        } catch (IllegalArgumentException e) {
            mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress, new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
            return null;
        }
    }
    if (contact != null) {
        ChatSession session = getChatSessionManager().createChatSession(contact, isNewSession);
        return getChatSessionAdapter(session, isNewSession);
    } else
        return null;
}
Also used : XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IChatSession(org.awesomeapp.messenger.service.IChatSession) ChatSession(org.awesomeapp.messenger.model.ChatSession) Contact(org.awesomeapp.messenger.model.Contact) ImErrorInfo(org.awesomeapp.messenger.model.ImErrorInfo)

Aggregations

IChatSession (org.awesomeapp.messenger.service.IChatSession)17 RemoteException (android.os.RemoteException)14 IChatSessionManager (org.awesomeapp.messenger.service.IChatSessionManager)10 IOException (java.io.IOException)4 XmppAddress (org.awesomeapp.messenger.plugin.xmpp.XmppAddress)4 Intent (android.content.Intent)3 DecoderException (org.apache.commons.codec.DecoderException)3 ImApp (org.awesomeapp.messenger.ImApp)3 Contact (org.awesomeapp.messenger.model.Contact)3 IImConnection (org.awesomeapp.messenger.service.IImConnection)3 CursorIndexOutOfBoundsException (android.database.CursorIndexOutOfBoundsException)2 Uri (android.net.Uri)2 IOtrChatSession (org.awesomeapp.messenger.crypto.IOtrChatSession)2 ChatSession (org.awesomeapp.messenger.model.ChatSession)2 IContactListManager (org.awesomeapp.messenger.service.IContactListManager)2 Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 Paint (android.graphics.Paint)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1