Search in sources :

Example 11 with IChatSession

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

the class SmpResponseActivity method respondSmp.

private void respondSmp(String sid, String answer) {
    ImApp app = (ImApp) getApplication();
    IOtrChatSession iOtrSession;
    try {
        IChatSession chatSession = app.getChatSession(mProviderId, -1, Address.stripResource(sid));
        iOtrSession = chatSession.getDefaultOtrChatSession();
        if (iOtrSession == null) {
            OtrDebugLogger.log("no session in progress for provider " + mProviderId);
            return;
        }
        iOtrSession.respondSmpVerification(answer);
    } catch (RemoteException e) {
        OtrDebugLogger.log("could not respond to SMP", e);
    }
}
Also used : IOtrChatSession(org.awesomeapp.messenger.crypto.IOtrChatSession) ImApp(org.awesomeapp.messenger.ImApp) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession)

Example 12 with IChatSession

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

the class ContactDisplayActivity method startChat.

public void startChat() {
    if (mConn == null)
        return;
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        if (manager != null) {
            IChatSession session = manager.getChatSession(mUsername);
            if (session == null) {
                new ChatSessionInitTask(((ImApp) getApplication()), mProviderId, mAccountId, Imps.Contacts.TYPE_NORMAL, false) {

                    @Override
                    protected void onPostExecute(Long chatId) {
                        super.onPostExecute(chatId);
                        if (mContactId == -1) {
                            Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
                            intent.putExtra("id", chatId);
                            startActivity(intent);
                            finish();
                        }
                    }
                }.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(mUsername)));
            // Toast.makeText(this, getString(R.string.message_waiting_for_friend), Toast.LENGTH_LONG).show();
            } else {
                Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
                intent.putExtra("id", session.getId());
                startActivity(intent);
                finish();
            }
        }
    } catch (RemoteException re) {
    }
    if (mContactId != -1) {
        Intent intent = new Intent(ContactDisplayActivity.this, ConversationDetailActivity.class);
        intent.putExtra("id", mContactId);
        startActivity(intent);
        finish();
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) ChatSessionInitTask(org.awesomeapp.messenger.tasks.ChatSessionInitTask) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) Intent(android.content.Intent) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) Contact(org.awesomeapp.messenger.model.Contact)

Example 13 with IChatSession

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

the class ContactDisplayActivity method initSmp.

private void initSmp(String question, String answer) {
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        IChatSession session = manager.getChatSession(mUsername);
        IOtrChatSession iOtrSession = session.getDefaultOtrChatSession();
        iOtrSession.initSmpVerification(question, answer);
    } catch (RemoteException e) {
        Log.e(ImApp.LOG_TAG, "error init SMP", e);
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) IOtrChatSession(org.awesomeapp.messenger.crypto.IOtrChatSession) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession)

Example 14 with IChatSession

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

the class GroupDisplayActivity method inviteContacts.

public void inviteContacts(ArrayList<String> invitees) {
    if (mConn == null)
        return;
    try {
        IChatSessionManager manager = mConn.getChatSessionManager();
        IChatSession session = manager.getChatSession(mAddress);
        for (String invitee : invitees) {
            session.inviteContact(invitee);
            GroupMemberDisplay member = new GroupMemberDisplay();
            XmppAddress address = new XmppAddress(invitee);
            member.username = address.getBareAddress();
            member.nickname = address.getUser();
            try {
                member.avatar = DatabaseUtils.getAvatarFromAddress(getContentResolver(), member.username, ImApp.SMALL_AVATAR_WIDTH, ImApp.SMALL_AVATAR_HEIGHT);
            } catch (DecoderException e) {
                e.printStackTrace();
            }
            mMembers.add(member);
        }
        mRecyclerView.getAdapter().notifyDataSetChanged();
    } catch (Exception e) {
        Log.e(ImApp.LOG_TAG, "error inviting contacts to group", e);
    }
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) DecoderException(org.apache.commons.codec.DecoderException) XmppAddress(org.awesomeapp.messenger.plugin.xmpp.XmppAddress) IChatSession(org.awesomeapp.messenger.service.IChatSession) DecoderException(org.apache.commons.codec.DecoderException) RemoteException(android.os.RemoteException)

Example 15 with IChatSession

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

the class MainActivity method startGroupChat.

public void startGroupChat(String room, String server, String nickname, final ArrayList<String> invitees, IImConnection conn) {
    mLastConnGroup = conn;
    new AsyncTask<String, Long, String>() {

        private ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(MainActivity.this);
            dialog.setMessage(getString(R.string.connecting_to_group_chat_));
            dialog.setCancelable(true);
            dialog.show();
        }

        @Override
        protected String doInBackground(String... params) {
            String subject = params[0];
            String chatRoom = "group" + UUID.randomUUID().toString().substring(0, 8);
            String server = params[1];
            try {
                IChatSessionManager manager = mLastConnGroup.getChatSessionManager();
                String roomAddress = (chatRoom + '@' + server).toLowerCase(Locale.US);
                String nickname = params[2];
                IChatSession session = manager.getChatSession(roomAddress);
                if (session == null) {
                    session = manager.createMultiUserChatSession(roomAddress, subject, nickname, true);
                    if (session != null) {
                        mRequestedChatId = session.getId();
                        publishProgress(mRequestedChatId);
                    } else {
                        return getString(R.string.unable_to_create_or_join_group_chat);
                    }
                } else {
                    mRequestedChatId = session.getId();
                    publishProgress(mRequestedChatId);
                }
                if (invitees != null && invitees.size() > 0) {
                    // wait a second for the server to sort itself out
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                    }
                    for (String invitee : invitees) session.inviteContact(invitee);
                }
                return null;
            } catch (RemoteException e) {
                return e.toString();
            }
        }

        @Override
        protected void onProgressUpdate(Long... showChatId) {
            showChat(showChatId[0]);
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
            if (result != null) {
            // mHandler.showServiceErrorAlert(result);
            }
        }
    }.executeOnExecutor(ImApp.sThreadPoolExecutor, room, server, nickname);
}
Also used : IChatSessionManager(org.awesomeapp.messenger.service.IChatSessionManager) ProgressDialog(android.app.ProgressDialog) RemoteException(android.os.RemoteException) IChatSession(org.awesomeapp.messenger.service.IChatSession) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

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