Search in sources :

Example 1 with XmppConnection

use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.

the class XmppConnectionService method reconnectAccount.

private void reconnectAccount(final Account account, final boolean force, final boolean interactive) {
    synchronized (account) {
        XmppConnection connection = account.getXmppConnection();
        if (connection == null) {
            connection = createConnection(account);
            account.setXmppConnection(connection);
        }
        boolean hasInternet = hasInternetConnection();
        if (!account.isOptionSet(Account.OPTION_DISABLED) && hasInternet) {
            if (!force) {
                disconnect(account, false);
            }
            Thread thread = new Thread(connection);
            connection.setInteractive(interactive);
            connection.prepareNewConnection();
            connection.interrupt();
            thread.start();
            scheduleWakeUpCall(Config.CONNECT_DISCO_TIMEOUT, account.getUuid().hashCode());
        } else {
            disconnect(account, force || account.getTrueStatus().isError() || !hasInternet);
            account.getRoster().clearPresences();
            connection.resetEverything();
            final AxolotlService axolotlService = account.getAxolotlService();
            if (axolotlService != null) {
                axolotlService.resetBrokenness();
            }
            if (!hasInternet) {
                account.setStatus(Account.State.NO_INTERNET);
            }
        }
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService)

Example 2 with XmppConnection

use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.

the class XmppConnectionService method createConnection.

public XmppConnection createConnection(final Account account) {
    final SharedPreferences sharedPref = getPreferences();
    String resource;
    try {
        resource = sharedPref.getString("resource", getString(R.string.default_resource)).toLowerCase(Locale.ENGLISH);
        if (resource.trim().isEmpty()) {
            throw new Exception();
        }
    } catch (Exception e) {
        resource = "conversations";
    }
    account.setResource(resource);
    final XmppConnection connection = new XmppConnection(account, this);
    connection.setOnMessagePacketReceivedListener(this.mMessageParser);
    connection.setOnStatusChangedListener(this.statusListener);
    connection.setOnPresencePacketReceivedListener(this.mPresenceParser);
    connection.setOnUnregisteredIqPacketReceivedListener(this.mIqParser);
    connection.setOnJinglePacketReceivedListener(this.jingleListener);
    connection.setOnBindListener(this.mOnBindListener);
    connection.setOnMessageAcknowledgeListener(this.mOnMessageAcknowledgedListener);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mMessageArchiveService);
    connection.addOnAdvancedStreamFeaturesAvailableListener(this.mAvatarService);
    AxolotlService axolotlService = account.getAxolotlService();
    if (axolotlService != null) {
        connection.addOnAdvancedStreamFeaturesAvailableListener(axolotlService);
    }
    return connection;
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) SharedPreferences(android.content.SharedPreferences) OtrException(net.java.otr4j.OtrException) FileNotFoundException(java.io.FileNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException)

Example 3 with XmppConnection

use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.

the class XmppConnectionService method sendCreateAccountWithCaptchaPacket.

public void sendCreateAccountWithCaptchaPacket(Account account, String id, Data data) {
    final XmppConnection connection = account.getXmppConnection();
    if (connection != null) {
        IqPacket request = mIqGenerator.generateCreateAccountWithCaptcha(account, id, data);
        connection.sendUnmodifiedIqPacket(request, connection.registrationResponseListener);
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 4 with XmppConnection

use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.

the class XmppConnectionService method switchToForeground.

private void switchToForeground() {
    final boolean broadcastLastActivity = broadcastLastActivity();
    for (Conversation conversation : getConversations()) {
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            conversation.getMucOptions().resetChatState();
        } else {
            conversation.setIncomingChatState(Config.DEFAULT_CHATSTATE);
        }
    }
    for (Account account : getAccounts()) {
        if (account.getStatus() == Account.State.ONLINE) {
            account.deactivateGracePeriod();
            final XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                if (connection.getFeatures().csi()) {
                    connection.sendActive();
                }
                if (broadcastLastActivity) {
                    //send new presence but don't include idle because we are not
                    sendPresence(account, false);
                }
            }
        }
    }
    Log.d(Config.LOGTAG, "app switched into foreground");
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation)

Example 5 with XmppConnection

use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.

the class ShareWithActivity method share.

private void share(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final XmppConnection connection = account.getXmppConnection();
    final long max = connection == null ? -1 : connection.getFeatures().getMaxHttpUploadSize();
    mListView.setEnabled(false);
    if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP && !hasPgp()) {
        if (share.uuid == null) {
            showInstallPgpDialog();
        } else {
            Toast.makeText(this, R.string.openkeychain_not_installed, Toast.LENGTH_SHORT).show();
            finish();
        }
        return;
    }
    if (share.uris.size() != 0) {
        OnPresenceSelected callback = new OnPresenceSelected() {

            @Override
            public void onPresenceSelected() {
                attachmentCounter.set(share.uris.size());
                if (share.image) {
                    share.multiple = share.uris.size() > 1;
                    replaceToast(getString(share.multiple ? R.string.preparing_images : R.string.preparing_image));
                    for (Iterator<Uri> i = share.uris.iterator(); i.hasNext(); i.remove()) {
                        ShareWithActivity.this.xmppConnectionService.attachImageToConversation(conversation, i.next(), attachFileCallback);
                    }
                } else {
                    replaceToast(getString(R.string.preparing_file));
                    ShareWithActivity.this.xmppConnectionService.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback);
                }
            }
        };
        if (account.httpUploadAvailable() && ((share.image && !neverCompressPictures()) || conversation.getMode() == Conversation.MODE_MULTI || FileBackend.allFilesUnderSize(this, share.uris, max)) && conversation.getNextEncryption() != Message.ENCRYPTION_OTR) {
            callback.onPresenceSelected();
        } else {
            selectPresence(conversation, callback);
        }
    } else {
        if (mReturnToPrevious && this.share.text != null && !this.share.text.isEmpty()) {
            final OnPresenceSelected callback = new OnPresenceSelected() {

                private void finishAndSend(Message message) {
                    xmppConnectionService.sendMessage(message);
                    replaceToast(getString(R.string.shared_text_with_x, conversation.getName()));
                    finish();
                }

                private UiCallback<Message> messageEncryptionCallback = new UiCallback<Message>() {

                    @Override
                    public void success(final Message message) {
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                finishAndSend(message);
                            }
                        });
                    }

                    @Override
                    public void error(final int errorCode, Message object) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                replaceToast(getString(errorCode));
                                finish();
                            }
                        });
                    }

                    @Override
                    public void userInputRequried(PendingIntent pi, Message object) {
                        finish();
                    }
                };

                @Override
                public void onPresenceSelected() {
                    final int encryption = conversation.getNextEncryption();
                    Message message = new Message(conversation, share.text, encryption);
                    Log.d(Config.LOGTAG, "on presence selected encrpytion=" + encryption);
                    if (encryption == Message.ENCRYPTION_PGP) {
                        replaceToast(getString(R.string.encrypting_message));
                        xmppConnectionService.getPgpEngine().encrypt(message, messageEncryptionCallback);
                        return;
                    }
                    if (encryption == Message.ENCRYPTION_OTR) {
                        message.setCounterpart(conversation.getNextCounterpart());
                    }
                    finishAndSend(message);
                }
            };
            if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
                selectPresence(conversation, callback);
            } else {
                callback.onPresenceSelected();
            }
        } else {
            switchToConversation(conversation, this.share.text, true);
        }
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Uri(android.net.Uri) XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) PendingIntent(android.app.PendingIntent)

Aggregations

XmppConnection (eu.siacs.conversations.xmpp.XmppConnection)10 Account (eu.siacs.conversations.entities.Account)5 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2 Conversation (eu.siacs.conversations.entities.Conversation)2 PendingIntent (android.app.PendingIntent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 MenuItem (android.view.MenuItem)1 Message (eu.siacs.conversations.entities.Message)1 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)1 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)1 FileNotFoundException (java.io.FileNotFoundException)1 CertificateException (java.security.cert.CertificateException)1 OtrException (net.java.otr4j.OtrException)1