Search in sources :

Example 11 with XmppConnection

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

the class ContactDetailsActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.contact_details, menu);
    MenuItem block = menu.findItem(R.id.action_block);
    MenuItem unblock = menu.findItem(R.id.action_unblock);
    MenuItem edit = menu.findItem(R.id.action_edit_contact);
    if (contact == null) {
        return true;
    }
    final XmppConnection connection = contact.getAccount().getXmppConnection();
    if (connection != null && connection.getFeatures().blocking()) {
        if (this.contact.isBlocked()) {
            block.setVisible(false);
        } else {
            unblock.setVisible(false);
        }
    } else {
        unblock.setVisible(false);
        block.setVisible(false);
    }
    if (!contact.showInRoster()) {
        edit.setVisible(false);
    }
    return super.onCreateOptionsMenu(menu);
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) MenuItem(android.view.MenuItem)

Example 12 with XmppConnection

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

the class ConversationFragment method resendMessage.

public void resendMessage(final Message message) {
    if (message.isFileOrImage()) {
        DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
        if (file.exists()) {
            final Conversation conversation = message.getConversation();
            final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection();
            if (!message.hasFileOnRemoteHost() && xmppConnection != null && !xmppConnection.getFeatures().httpUpload(message.getFileParams().size)) {
                activity.selectPresence(conversation, () -> {
                    message.setCounterpart(conversation.getNextCounterpart());
                    activity.xmppConnectionService.resendFailedMessages(message);
                    new Handler().post(() -> {
                        int size = messageList.size();
                        this.binding.messagesView.setSelection(size - 1);
                    });
                });
                return;
            }
        } else {
            Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
            message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
            activity.onConversationsListItemUpdated();
            refresh();
            return;
        }
    }
    activity.xmppConnectionService.resendFailedMessages(message);
    new Handler().post(() -> {
        int size = messageList.size();
        this.binding.messagesView.setSelection(size - 1);
    });
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Handler(android.os.Handler) Conversation(de.pixart.messenger.entities.Conversation) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) SuppressLint(android.annotation.SuppressLint)

Example 13 with XmppConnection

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

the class ConversationFragment method updateSnackBar.

private void updateSnackBar(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final XmppConnection connection = account.getXmppConnection();
    final Contact contact = conversation.getContact();
    final int mode = conversation.getMode();
    if (account.getStatus() == Account.State.DISABLED) {
        showSnackbar(R.string.this_account_is_disabled, R.string.enable, this.mEnableAccountListener);
    } else if (conversation.isBlocked()) {
        showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
    } else if (contact != null && !contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener, this.mLongPressBlockListener);
    } else if (contact != null && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription, this.mLongPressBlockListener);
    } else if (mode == Conversation.MODE_MULTI && !conversation.getMucOptions().online() && account.getStatus() == Account.State.ONLINE) {
        switch(conversation.getMucOptions().getError()) {
            case NICK_IN_USE:
                showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
                break;
            case NO_RESPONSE:
                showSnackbar(R.string.joining_conference, 0, null);
                break;
            case SERVER_NOT_FOUND:
                if (conversation.receivedMessagesCount() > 0) {
                    showSnackbar(R.string.remote_server_not_found, R.string.try_again, joinMuc);
                } else {
                    showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc);
                }
                break;
            case PASSWORD_REQUIRED:
                showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
                break;
            case BANNED:
                showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
                break;
            case MEMBERS_ONLY:
                showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
                break;
            case KICKED:
                showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
                break;
            case UNKNOWN:
                showSnackbar(R.string.conference_unknown_error, R.string.leave, leaveMuc);
                break;
            case INVALID_NICK:
                showSnackbar(R.string.invalid_muc_nick, R.string.edit, clickToMuc);
            case SHUTDOWN:
                showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc);
                break;
            default:
                hideSnackbar();
                break;
        }
    } else if ((mode == Conversation.MODE_MULTI && !conversation.getMucOptions().participating())) {
        showSnackbar(R.string.no_write_access_in_public_muc, R.string.ok, clickToMuc);
    } else if (account.hasPendingPgpIntent(conversation)) {
        showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.smpRequested()) {
        showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!conversation.isOtrFingerprintVerified())) {
        showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
    } else if (connection != null && connection.getFeatures().blocking() && conversation.countMessages() != 0 && !conversation.isBlocked() && conversation.isWithStranger()) {
        showSnackbar(R.string.received_message_from_stranger, R.string.block, mBlockClickListener);
    } else if (activity.xmppConnectionService.warnUnecryptedChat()) {
        AxolotlService axolotlService = account.getAxolotlService();
        if ((mode == Conversation.MODE_SINGLE) && (conversation.getNextEncryption() == Message.ENCRYPTION_NONE && ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected()) || Config.supportOtr()))) {
            if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) {
                hideSnackbar();
            } else {
                showSnackbar(R.string.conversation_unencrypted_hint, R.string.ok, mHideUnencryptionHint, null);
            }
        } else if ((mode == Conversation.MODE_MULTI && conversation.getMucOptions().membersOnly() && conversation.getMucOptions().nonanonymous()) && (conversation.getNextEncryption() == Message.ENCRYPTION_NONE && ((Config.supportOmemo() && axolotlService != null && conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) || (Config.supportOpenPgp() && account.isPgpDecryptionServiceConnected())))) {
            if (ENCRYPTION_EXCEPTIONS.contains(conversation.getJid().toString()) || conversation.getJid().toString().equals(account.getJid().getDomainpart())) {
                Log.d(Config.LOGTAG, "Don't show unencrypted warning because " + conversation.getJid().toString() + " is on exception list");
                hideSnackbar();
            } else {
                showSnackbar(R.string.conversation_unencrypted_hint, R.string.ok, mHideUnencryptionHint, null);
            }
        } else {
            hideSnackbar();
        }
    } else {
        hideSnackbar();
    }
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) Account(de.pixart.messenger.entities.Account) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Example 14 with XmppConnection

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

the class XmppConnectionService method createConnection.

public XmppConnection createConnection(final Account account) {
    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(de.pixart.messenger.xmpp.XmppConnection) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService)

Example 15 with XmppConnection

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

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.isEnabled() && 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(de.pixart.messenger.xmpp.XmppConnection) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService)

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