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");
}
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");
}
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);
}
}
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();
}
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);
}
}
Aggregations