Search in sources :

Example 21 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method getKnownConferenceHosts.

public List<String> getKnownConferenceHosts() {
    final ArrayList<String> mucServers = new ArrayList<>();
    for (final Account account : accounts) {
        if (account.getXmppConnection() != null) {
            final String server = account.getXmppConnection().getMucServer();
            if (server != null && !mucServers.contains(server)) {
                mucServers.add(server);
            }
            for (Bookmark bookmark : account.getBookmarks()) {
                final Jid jid = bookmark.getJid();
                final String s = jid == null ? null : jid.getDomainpart();
                if (s != null && !mucServers.contains(s)) {
                    mucServers.add(s);
                }
            }
        }
    }
    return mucServers;
}
Also used : Account(de.pixart.messenger.entities.Account) Bookmark(de.pixart.messenger.entities.Bookmark) Jid(de.pixart.messenger.xmpp.jid.Jid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 22 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method fetchMamPreferences.

public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
    final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
    sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
            if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
                callback.onPreferencesFetched(prefs);
            } else {
                callback.onPreferencesFetchFailed();
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 23 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method loadMoreMessages.

public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) {
    if (XmppConnectionService.this.getMessageArchiveService().queryInProgress(conversation, callback)) {
        return;
    } else if (timestamp == 0) {
        return;
    }
    Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp));
    final Runnable runnable = () -> {
        final Account account = conversation.getAccount();
        List<Message> messages = databaseBackend.getMessages(conversation, 50, timestamp);
        if (messages.size() > 0) {
            conversation.addAll(0, messages);
            checkDeletedFiles(conversation);
            callback.onMoreMessagesLoaded(messages.size(), conversation);
        } else if (conversation.hasMessagesLeftOnServer() && account.isOnlineAndConnected() && conversation.getLastClearHistory().getTimestamp() == 0) {
            final boolean mamAvailable;
            if (conversation.getMode() == Conversation.MODE_SINGLE) {
                mamAvailable = account.getXmppConnection().getFeatures().mam() && !conversation.getContact().isBlocked();
            } else {
                mamAvailable = conversation.getMucOptions().mamSupport();
            }
            if (mamAvailable) {
                MessageArchiveService.Query query = getMessageArchiveService().query(conversation, new MamReference(0), timestamp, false);
                if (query != null) {
                    query.setCallback(callback);
                    callback.informUser(R.string.fetching_history_from_server);
                } else {
                    callback.informUser(R.string.not_fetching_history_retention_period);
                }
            }
        }
    };
    mDatabaseReaderExecutor.execute(runnable);
}
Also used : Account(de.pixart.messenger.entities.Account) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MamReference(de.pixart.messenger.xmpp.mam.MamReference)

Example 24 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method createAccountFromKey.

public void createAccountFromKey(final String alias, final OnAccountCreated callback) {
    new Thread(() -> {
        try {
            final X509Certificate[] chain = KeyChain.getCertificateChain(this, alias);
            final X509Certificate cert = chain != null && chain.length > 0 ? chain[0] : null;
            if (cert == null) {
                callback.informUser(R.string.unable_to_parse_certificate);
                return;
            }
            Pair<Jid, String> info = CryptoHelper.extractJidAndName(cert);
            if (info == null) {
                callback.informUser(R.string.certificate_does_not_contain_jid);
                return;
            }
            if (findAccountByJid(info.first) == null) {
                Account account = new Account(info.first, "");
                account.setPrivateKeyAlias(alias);
                account.setOption(Account.OPTION_DISABLED, true);
                account.setDisplayName(info.second);
                createAccount(account);
                callback.onAccountCreated(account);
                if (Config.X509_VERIFICATION) {
                    try {
                        getMemorizingTrustManager().getNonInteractive(account.getJid().getDomainpart()).checkClientTrusted(chain, "RSA");
                    } catch (CertificateException e) {
                        callback.informUser(R.string.certificate_chain_is_not_trusted);
                    }
                }
            } else {
                callback.informUser(R.string.account_already_exists);
            }
        } catch (Exception e) {
            e.printStackTrace();
            callback.informUser(R.string.unable_to_parse_certificate);
        }
    }).start();
}
Also used : Account(de.pixart.messenger.entities.Account) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) OtrException(net.java.otr4j.OtrException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException) Pair(android.util.Pair)

Example 25 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method pushContactToServer.

public void pushContactToServer(final Contact contact) {
    contact.resetOption(Contact.Options.DIRTY_DELETE);
    contact.setOption(Contact.Options.DIRTY_PUSH);
    final Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        final boolean ask = contact.getOption(Contact.Options.ASKING);
        final boolean sendUpdates = contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST) && contact.getOption(Contact.Options.PREEMPTIVE_GRANT);
        final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        iq.query(Namespace.ROSTER).addChild(contact.asElement());
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
        if (sendUpdates) {
            sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
        }
        if (ask) {
            sendPresencePacket(account, mPresenceGenerator.requestPresenceUpdatesFrom(contact));
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6