use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class StartConversationActivity method getSelectedAccount.
public static Account getSelectedAccount(Context context, Spinner spinner) {
if (spinner == null || !spinner.isEnabled()) {
return null;
}
if (context instanceof XmppActivity) {
Jid jid;
try {
if (Config.DOMAIN_LOCK != null) {
jid = Jid.ofEscaped((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
jid = Jid.ofEscaped((String) spinner.getSelectedItem());
}
} catch (final IllegalArgumentException e) {
return null;
}
final XmppConnectionService service = ((XmppActivity) context).xmppConnectionService;
if (service == null) {
return null;
}
return service.findAccountByJid(jid);
} else {
return null;
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class StartConversationActivity method openConversationsForBookmark.
protected void openConversationsForBookmark(Bookmark bookmark) {
final Jid jid = bookmark.getFullJid();
if (jid == null) {
Toast.makeText(this, R.string.invalid_jid, Toast.LENGTH_SHORT).show();
return;
}
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), jid, true, true, true);
bookmark.setConversation(conversation);
if (!bookmark.autojoin() && getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))) {
bookmark.setAutojoin(true);
xmppConnectionService.createBookmark(bookmark.getAccount(), bookmark);
}
SoftKeyboardUtils.hideSoftKeyboard(this);
switchToConversation(conversation);
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class SettingsActivity method deleteOmemoIdentities.
private boolean deleteOmemoIdentities() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.pref_delete_omemo_identities);
final List<CharSequence> accounts = new ArrayList<>();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.isEnabled()) {
accounts.add(account.getJid().asBareJid().toString());
}
}
final boolean[] checkedItems = new boolean[accounts.size()];
builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, isChecked) -> {
checkedItems[which] = isChecked;
final AlertDialog alertDialog = (AlertDialog) dialog;
for (boolean item : checkedItems) {
if (item) {
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
return;
}
}
alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
});
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.delete_selected_keys, (dialog, which) -> {
for (int i = 0; i < checkedItems.length; ++i) {
if (checkedItems[i]) {
try {
Jid jid = Jid.of(accounts.get(i).toString());
Account account = xmppConnectionService.findAccountByJid(jid);
if (account != null) {
account.getAxolotlService().regenerateKeys(true);
}
} catch (IllegalArgumentException e) {
//
}
}
}
});
AlertDialog dialog = builder.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class TrustKeysActivity method populateView.
private void populateView() {
setTitle(getString(R.string.trust_omemo_fingerprints));
binding.ownKeysDetails.removeAllViews();
binding.foreignKeys.removeAllViews();
boolean hasOwnKeys = false;
boolean hasForeignKeys = false;
for (final String fingerprint : ownKeysToTrust.keySet()) {
hasOwnKeys = true;
addFingerprintRowWithListeners(binding.ownKeysDetails, mAccount, fingerprint, false, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)), false, false, (buttonView, isChecked) -> {
ownKeysToTrust.put(fingerprint, isChecked);
// own fingerprints have no impact on locked status.
});
}
synchronized (this.foreignKeysToTrust) {
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
hasForeignKeys = true;
KeysCardBinding keysCardBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.keys_card, binding.foreignKeys, false);
final Jid jid = entry.getKey();
keysCardBinding.foreignKeysTitle.setText(IrregularUnicodeDetector.style(this, jid));
keysCardBinding.foreignKeysTitle.setOnClickListener(v -> switchToContactDetails(mAccount.getRoster().getContact(jid)));
final Map<String, Boolean> fingerprints = entry.getValue();
for (final String fingerprint : fingerprints.keySet()) {
addFingerprintRowWithListeners(keysCardBinding.foreignKeysDetails, mAccount, fingerprint, false, FingerprintStatus.createActive(fingerprints.get(fingerprint)), false, false, (buttonView, isChecked) -> {
fingerprints.put(fingerprint, isChecked);
lockOrUnlockAsNeeded();
});
}
if (fingerprints.size() == 0) {
keysCardBinding.noKeysToAccept.setVisibility(View.VISIBLE);
if (hasNoOtherTrustedKeys(jid)) {
if (!mAccount.getRoster().getContact(jid).mutualPresenceSubscription()) {
keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_presence);
} else {
keysCardBinding.noKeysToAccept.setText(R.string.error_no_keys_to_trust_server_error);
}
} else {
keysCardBinding.noKeysToAccept.setText(getString(R.string.no_keys_just_confirm, mAccount.getRoster().getContact(jid).getDisplayName()));
}
} else {
keysCardBinding.noKeysToAccept.setVisibility(View.GONE);
}
binding.foreignKeys.addView(keysCardBinding.foreignKeysCard);
}
}
if ((hasOwnKeys || foreignActuallyHasKeys()) && isCameraFeatureAvailable() && mUseCameraHintShown.compareAndSet(false, true)) {
showCameraToast();
}
binding.ownKeysTitle.setText(mAccount.getJid().asBareJid().toEscapedString());
binding.ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE);
binding.foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE);
if (hasPendingKeyFetches()) {
setFetching();
lock();
} else {
if (!hasForeignKeys && hasNoOtherTrustedKeys()) {
binding.keyErrorMessageCard.setVisibility(View.VISIBLE);
boolean lastReportWasError = lastFetchReport == AxolotlService.FetchStatus.ERROR;
boolean errorFetchingBundle = mAccount.getAxolotlService().fetchMapHasErrors(contactJids);
boolean errorFetchingDeviceList = mAccount.getAxolotlService().hasErrorFetchingDeviceList(contactJids);
boolean anyWithoutMutualPresenceSubscription = anyWithoutMutualPresenceSubscription(contactJids);
if (errorFetchingDeviceList) {
binding.keyErrorMessage.setVisibility(View.VISIBLE);
binding.keyErrorMessage.setText(R.string.error_trustkey_device_list);
} else if (errorFetchingBundle || lastReportWasError) {
binding.keyErrorMessage.setVisibility(View.VISIBLE);
binding.keyErrorMessage.setText(R.string.error_trustkey_bundle);
} else {
binding.keyErrorMessage.setVisibility(View.GONE);
}
this.binding.keyErrorHintMutual.setVisibility(anyWithoutMutualPresenceSubscription ? View.VISIBLE : View.GONE);
Contact contact = mAccount.getRoster().getContact(contactJids.get(0));
binding.keyErrorGeneral.setText(getString(R.string.error_trustkey_general, getString(R.string.app_name), contact.getDisplayName()));
binding.ownKeysDetails.removeAllViews();
if (OmemoSetting.isAlways()) {
binding.disableButton.setVisibility(View.GONE);
} else {
binding.disableButton.setVisibility(View.VISIBLE);
binding.disableButton.setOnClickListener(this::disableEncryptionDialog);
}
binding.ownKeysCard.setVisibility(View.GONE);
binding.foreignKeys.removeAllViews();
binding.foreignKeys.setVisibility(View.GONE);
}
lockOrUnlockAsNeeded();
setDone();
}
}
use of eu.siacs.conversations.xmpp.Jid in project Conversations by siacs.
the class TrustKeysActivity method commitTrusts.
private void commitTrusts() {
for (final String fingerprint : ownKeysToTrust.keySet()) {
mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(ownKeysToTrust.get(fingerprint)));
}
List<Jid> acceptedTargets = mConversation == null ? new ArrayList<>() : mConversation.getAcceptedCryptoTargets();
synchronized (this.foreignKeysToTrust) {
for (Map.Entry<Jid, Map<String, Boolean>> entry : foreignKeysToTrust.entrySet()) {
Jid jid = entry.getKey();
Map<String, Boolean> value = entry.getValue();
if (!acceptedTargets.contains(jid)) {
acceptedTargets.add(jid);
}
for (final String fingerprint : value.keySet()) {
mAccount.getAxolotlService().setFingerprintTrust(fingerprint, FingerprintStatus.createActive(value.get(fingerprint)));
}
}
}
if (mConversation != null && mConversation.getMode() == Conversation.MODE_MULTI) {
mConversation.setAcceptedCryptoTargets(acceptedTargets);
xmppConnectionService.updateConversation(mConversation);
}
}
Aggregations