use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.
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.isOptionSet(Account.OPTION_DISABLED) && 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);
}
}
}
}
use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.
the class XmppConnectionService method createConnection.
public XmppConnection createConnection(final Account account) {
final SharedPreferences sharedPref = getPreferences();
String resource;
try {
resource = sharedPref.getString("resource", getString(R.string.default_resource)).toLowerCase(Locale.ENGLISH);
if (resource.trim().isEmpty()) {
throw new Exception();
}
} catch (Exception e) {
resource = "conversations";
}
account.setResource(resource);
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;
}
use of eu.siacs.conversations.xmpp.XmppConnection in project Conversations by siacs.
the class XmppConnectionService method sendCreateAccountWithCaptchaPacket.
public void sendCreateAccountWithCaptchaPacket(Account account, String id, Data data) {
final XmppConnection connection = account.getXmppConnection();
if (connection != null) {
IqPacket request = mIqGenerator.generateCreateAccountWithCaptcha(account, id, data);
connection.sendUnmodifiedIqPacket(request, connection.registrationResponseListener);
}
}
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 ShareWithActivity method share.
private void share(final Conversation conversation) {
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) {
OnPresenceSelected callback = new OnPresenceSelected() {
@Override
public void onPresenceSelected() {
attachmentCounter.set(share.uris.size());
if (share.image) {
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()) {
ShareWithActivity.this.xmppConnectionService.attachImageToConversation(conversation, i.next(), attachFileCallback);
}
} else {
replaceToast(getString(R.string.preparing_file));
ShareWithActivity.this.xmppConnectionService.attachFileToConversation(conversation, share.uris.get(0), attachFileCallback);
}
}
};
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 OnPresenceSelected callback = new OnPresenceSelected() {
private void finishAndSend(Message message) {
xmppConnectionService.sendMessage(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(new Runnable() {
@Override
public void run() {
finishAndSend(message);
}
});
}
@Override
public void error(final int errorCode, Message object) {
runOnUiThread(new Runnable() {
@Override
public void run() {
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());
}
finishAndSend(message);
}
};
if (conversation.getNextEncryption() == Message.ENCRYPTION_OTR) {
selectPresence(conversation, callback);
} else {
callback.onPresenceSelected();
}
} else {
switchToConversation(conversation, this.share.text, true);
}
}
}
Aggregations