Search in sources :

Example 6 with XmppConnection

use of de.pixart.messenger.xmpp.XmppConnection in project Pix-Art-Messenger by kriztan.

the class ShareWithActivity method share.

private void share(final Conversation conversation) {
    if (share.uris.size() != 0 && !hasStoragePermission(REQUEST_STORAGE_PERMISSION)) {
        mPendingConversation = conversation;
        return;
    }
    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) {
        PresenceSelector.OnPresenceSelected callback = () -> {
            attachmentCounter.set(share.uris.size());
            if (share.image) {
                Log.d(Config.LOGTAG, "ShareWithActivity share() image " + share.uris.size() + " uri(s) " + share.uris.toString());
                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()) {
                    final Uri uri = i.next();
                    delegateUriPermissionsToService(uri);
                    xmppConnectionService.attachImageToConversation(conversation, uri, attachFileCallback);
                }
            } else {
                Log.d(Config.LOGTAG, "ShareWithActivity share() file " + share.uris.size() + " uri(s) " + share.uris.toString());
                replaceToast(getString(R.string.preparing_file));
                final Uri uri = share.uris.get(0);
                delegateUriPermissionsToService(uri);
                xmppConnectionService.attachFileToConversation(conversation, uri, share.type, attachFileCallback);
                finish();
            }
        };
        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 PresenceSelector.OnPresenceSelected callback = new PresenceSelector.OnPresenceSelected() {

                private void finishAndSend(Message 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(() -> finishAndSend(message));
                    }

                    @Override
                    public void error(final int errorCode, Message object) {
                        runOnUiThread(() -> {
                            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());
                    }
                    xmppConnectionService.sendMessage(message);
                    finishAndSend(message);
                }
            };
            if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
                selectPresence(conversation, callback);
            } else {
                callback.onPresenceSelected();
            }
        } else {
            final PresenceSelector.OnPresenceSelected callback = () -> {
                Message message = new Message(conversation, share.text, conversation.getNextEncryption());
                if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
                    message.setCounterpart(conversation.getNextCounterpart());
                }
                xmppConnectionService.sendMessage(message);
                replaceToast(getString(R.string.shared_text_with_x, conversation.getName()));
                switchToConversation(message.getConversation());
            };
            if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
                selectPresence(conversation, callback);
            } else {
                callback.onPresenceSelected();
            }
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Message(de.pixart.messenger.entities.Message) Uri(android.net.Uri) XmppConnection(de.pixart.messenger.xmpp.XmppConnection) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) Iterator(java.util.Iterator) PendingIntent(android.app.PendingIntent)

Example 7 with XmppConnection

use of de.pixart.messenger.xmpp.XmppConnection in project Pix-Art-Messenger by kriztan.

the class ManageAccountActivity method enableAccount.

private void enableAccount(Account account) {
    account.setOption(Account.OPTION_DISABLED, false);
    final XmppConnection connection = account.getXmppConnection();
    if (connection != null) {
        connection.resetEverything();
    }
    if (!xmppConnectionService.updateAccount(account)) {
        Toast.makeText(this, R.string.unable_to_update_account, Toast.LENGTH_SHORT).show();
    }
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection)

Example 8 with XmppConnection

use of de.pixart.messenger.xmpp.XmppConnection in project Pix-Art-Messenger by kriztan.

the class NotificationService method push.

public void push(final Message message) {
    synchronized (CATCHUP_LOCK) {
        final XmppConnection connection = message.getConversation().getAccount().getXmppConnection();
        if (connection.isWaitingForSmCatchup()) {
            connection.incrementSmCatchupMessageCounter();
            pushFromBacklog(message);
        } else {
            pushNow(message);
        }
    }
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection)

Example 9 with XmppConnection

use of de.pixart.messenger.xmpp.XmppConnection in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method disconnect.

private void disconnect(Account account, boolean force) {
    if ((account.getStatus() == Account.State.ONLINE) || (account.getStatus() == Account.State.DISABLED)) {
        final XmppConnection connection = account.getXmppConnection();
        if (!force) {
            List<Conversation> conversations = getConversations();
            for (Conversation conversation : conversations) {
                if (conversation.getAccount() == account) {
                    if (conversation.getMode() == Conversation.MODE_MULTI) {
                        leaveMuc(conversation, true);
                    } else {
                        if (conversation.endOtrIfNeeded()) {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": ended otr session with " + conversation.getJid());
                        }
                    }
                }
            }
            sendOfflinePresence(account);
        }
        connection.disconnect(force);
    }
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) Conversation(de.pixart.messenger.entities.Conversation)

Example 10 with XmppConnection

use of de.pixart.messenger.xmpp.XmppConnection in project Pix-Art-Messenger by kriztan.

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(de.pixart.messenger.xmpp.XmppConnection) Account(de.pixart.messenger.entities.Account) Conversation(de.pixart.messenger.entities.Conversation)

Aggregations

XmppConnection (de.pixart.messenger.xmpp.XmppConnection)15 Account (de.pixart.messenger.entities.Account)5 PendingIntent (android.app.PendingIntent)3 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)3 Conversation (de.pixart.messenger.entities.Conversation)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 Uri (android.net.Uri)1 Handler (android.os.Handler)1 MenuItem (android.view.MenuItem)1 Contact (de.pixart.messenger.entities.Contact)1 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)1 Message (de.pixart.messenger.entities.Message)1 TransferablePlaceholder (de.pixart.messenger.entities.TransferablePlaceholder)1 PresenceSelector (de.pixart.messenger.ui.util.PresenceSelector)1 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)1 Iterator (java.util.Iterator)1