Search in sources :

Example 6 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 7 with XmppConnection

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

the class XmppConnectionService method switchToBackground.

private void switchToBackground() {
    final boolean broadcastLastActivity = broadcastLastActivity();
    for (Account account : getAccounts()) {
        if (account.getStatus() == Account.State.ONLINE) {
            XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                if (broadcastLastActivity) {
                    sendPresence(account, broadcastLastActivity);
                }
                if (connection.getFeatures().csi()) {
                    connection.sendInactive();
                }
            }
        }
    }
    this.mNotificationService.setIsInForeground(false);
    Log.d(Config.LOGTAG, "app switched into background");
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account)

Example 8 with XmppConnection

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

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(eu.siacs.conversations.xmpp.XmppConnection) Conversation(eu.siacs.conversations.entities.Conversation)

Example 9 with XmppConnection

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

the class XmppConnectionService method resetAllAttemptCounts.

private void resetAllAttemptCounts(boolean reallyAll, boolean retryImmediately) {
    Log.d(Config.LOGTAG, "resetting all attempt counts");
    for (Account account : accounts) {
        if (account.hasErrorStatus() || reallyAll) {
            final XmppConnection connection = account.getXmppConnection();
            if (connection != null) {
                connection.resetAttemptCount(retryImmediately);
            }
        }
        if (account.setShowErrorNotification(true)) {
            databaseBackend.updateAccount(account);
        }
    }
    mNotificationService.updateErrorNotification();
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account)

Example 10 with XmppConnection

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

the class SettingsActivity method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String name) {
    final List<String> resendPresence = Arrays.asList("confirm_messages", "xa_on_silent_mode", AWAY_WHEN_SCREEN_IS_OFF, "allow_message_correction", TREAT_VIBRATE_AS_SILENT, MANUALLY_CHANGE_PRESENCE, "last_activity");
    if (name.equals("resource")) {
        String resource = preferences.getString("resource", "mobile").toLowerCase(Locale.US);
        if (xmppConnectionServiceBound) {
            for (Account account : xmppConnectionService.getAccounts()) {
                if (account.setResource(resource)) {
                    if (!account.isOptionSet(Account.OPTION_DISABLED)) {
                        XmppConnection connection = account.getXmppConnection();
                        if (connection != null) {
                            connection.resetStreamId();
                        }
                        xmppConnectionService.reconnectAccountInBackground(account);
                    }
                }
            }
        }
    } else if (name.equals(KEEP_FOREGROUND_SERVICE)) {
        boolean foreground_service = preferences.getBoolean(KEEP_FOREGROUND_SERVICE, false);
        if (!foreground_service) {
            xmppConnectionService.clearStartTimeCounter();
        }
        xmppConnectionService.toggleForegroundService();
    } else if (resendPresence.contains(name)) {
        if (xmppConnectionServiceBound) {
            if (name.equals(AWAY_WHEN_SCREEN_IS_OFF) || name.equals(MANUALLY_CHANGE_PRESENCE)) {
                xmppConnectionService.toggleScreenEventReceiver();
            }
            if (name.equals(MANUALLY_CHANGE_PRESENCE) && !noAccountUsesPgp()) {
                Toast.makeText(this, R.string.republish_pgp_keys, Toast.LENGTH_LONG).show();
            }
            xmppConnectionService.refreshAllPresences();
        }
    } else if (name.equals("dont_trust_system_cas")) {
        xmppConnectionService.updateMemorizingTrustmanager();
        reconnectAccounts();
    } else if (name.equals("use_tor")) {
        reconnectAccounts();
    } else if (name.equals(AUTOMATIC_MESSAGE_DELETION)) {
        xmppConnectionService.expireOldMessages(true);
    }
}
Also used : XmppConnection(eu.siacs.conversations.xmpp.XmppConnection) Account(eu.siacs.conversations.entities.Account)

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