Search in sources :

Example 51 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method loadPhoneContacts.

public void loadPhoneContacts() {
    mContactMergerExecutor.execute(new Runnable() {

        @Override
        public void run() {
            PhoneHelper.loadPhoneContacts(XmppConnectionService.this, new OnPhoneContactsLoadedListener() {

                @Override
                public void onPhoneContactsLoaded(List<Bundle> phoneContacts) {
                    Log.d(Config.LOGTAG, "start merging phone contacts with roster");
                    for (Account account : accounts) {
                        List<Contact> withSystemAccounts = account.getRoster().getWithSystemAccounts();
                        for (Bundle phoneContact : phoneContacts) {
                            Jid jid;
                            try {
                                jid = Jid.fromString(phoneContact.getString("jid"));
                            } catch (final InvalidJidException e) {
                                continue;
                            }
                            final Contact contact = account.getRoster().getContact(jid);
                            String systemAccount = phoneContact.getInt("phoneid") + "#" + phoneContact.getString("lookup");
                            contact.setSystemAccount(systemAccount);
                            boolean needsCacheClean = contact.setPhotoUri(phoneContact.getString("photouri"));
                            needsCacheClean |= contact.setSystemName(phoneContact.getString("displayname"));
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                            withSystemAccounts.remove(contact);
                        }
                        for (Contact contact : withSystemAccounts) {
                            contact.setSystemAccount(null);
                            boolean needsCacheClean = contact.setPhotoUri(null);
                            needsCacheClean |= contact.setSystemName(null);
                            if (needsCacheClean) {
                                getAvatarService().clear(contact);
                            }
                        }
                    }
                    Log.d(Config.LOGTAG, "finished merging phone contacts");
                    updateAccountUi();
                }
            });
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Bundle(android.os.Bundle) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OnPhoneContactsLoadedListener(eu.siacs.conversations.utils.OnPhoneContactsLoadedListener) Contact(eu.siacs.conversations.entities.Contact)

Example 52 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class ConversationFragment method updateSnackBar.

private void updateSnackBar(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final int mode = conversation.getMode();
    final Contact contact = mode == Conversation.MODE_SINGLE ? conversation.getContact() : null;
    if (account.getStatus() == Account.State.DISABLED) {
        showSnackbar(R.string.this_account_is_disabled, R.string.enable, this.mEnableAccountListener);
    } else if (conversation.isBlocked()) {
        showSnackbar(R.string.contact_blocked, R.string.unblock, this.mUnblockClickListener);
    } else if (contact != null && !contact.showInRoster() && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_added_you, R.string.add_back, this.mAddBackClickListener);
    } else if (contact != null && contact.getOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST)) {
        showSnackbar(R.string.contact_asks_for_presence_subscription, R.string.allow, this.mAllowPresenceSubscription);
    } else if (mode == Conversation.MODE_MULTI && !conversation.getMucOptions().online() && account.getStatus() == Account.State.ONLINE) {
        switch(conversation.getMucOptions().getError()) {
            case NICK_IN_USE:
                showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
                break;
            case NO_RESPONSE:
                showSnackbar(R.string.joining_conference, 0, null);
                break;
            case SERVER_NOT_FOUND:
                showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc);
                break;
            case PASSWORD_REQUIRED:
                showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
                break;
            case BANNED:
                showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
                break;
            case MEMBERS_ONLY:
                showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
                break;
            case KICKED:
                showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
                break;
            case UNKNOWN:
                showSnackbar(R.string.conference_unknown_error, R.string.join, joinMuc);
                break;
            case SHUTDOWN:
                showSnackbar(R.string.conference_shutdown, R.string.join, joinMuc);
                break;
            default:
                break;
        }
    } else if (account.hasPendingPgpIntent(conversation)) {
        showSnackbar(R.string.openpgp_messages_found, R.string.decrypt, clickToDecryptListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.smpRequested()) {
        showSnackbar(R.string.smp_requested, R.string.verify, this.mAnswerSmpClickListener);
    } else if (mode == Conversation.MODE_SINGLE && conversation.hasValidOtrSession() && (conversation.getOtrSession().getSessionStatus() == SessionStatus.ENCRYPTED) && (!conversation.isOtrFingerprintVerified())) {
        showSnackbar(R.string.unknown_otr_fingerprint, R.string.verify, clickToVerify);
    } else if (conversation.countMessages() != 0 && !conversation.isBlocked() && conversation.isWithStranger()) {
        showSnackbar(R.string.received_message_from_stranger, R.string.block, mBlockClickListener);
    } else {
        hideSnackbar();
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Contact(eu.siacs.conversations.entities.Contact)

Example 53 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class ChooseContactActivity method onBackendConnected.

@Override
void onBackendConnected() {
    filterContacts();
    this.mActivatedAccounts.clear();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            if (Config.DOMAIN_LOCK != null) {
                this.mActivatedAccounts.add(account.getJid().getLocalpart());
            } else {
                this.mActivatedAccounts.add(account.getJid().toBareJid().toString());
            }
        }
    }
    this.mKnownHosts = xmppConnectionService.getKnownHosts();
}
Also used : Account(eu.siacs.conversations.entities.Account)

Example 54 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class OmemoActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Object account = v.getTag(R.id.TAG_ACCOUNT);
    Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
    Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
    ;
    if (account != null && fingerprint != null && account instanceof Account && fingerprintStatus != null && fingerprint instanceof String && fingerprintStatus instanceof FingerprintStatus) {
        getMenuInflater().inflate(R.menu.omemo_key_context, menu);
        MenuItem distrust = menu.findItem(R.id.distrust_key);
        MenuItem verifyScan = menu.findItem(R.id.verify_scan);
        if (this instanceof TrustKeysActivity) {
            distrust.setVisible(false);
            verifyScan.setVisible(false);
        } else {
            FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
            if (!status.isActive() || status.isVerified()) {
                verifyScan.setVisible(false);
            }
            distrust.setVisible(status.isVerified());
        }
        this.mSelectedAccount = (Account) account;
        this.mSelectedFingerprint = (String) fingerprint;
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) FingerprintStatus(eu.siacs.conversations.crypto.axolotl.FingerprintStatus) MenuItem(android.view.MenuItem)

Example 55 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class MagicCreateActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    if (getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.magic_create);
    mFullJidDisplay = (TextView) findViewById(R.id.full_jid);
    mUsername = (EditText) findViewById(R.id.username);
    mRandom = new SecureRandom();
    Button next = (Button) findViewById(R.id.create_account);
    next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String username = mUsername.getText().toString();
            if (username.contains("@") || username.length() < 3) {
                mUsername.setError(getString(R.string.invalid_username));
                mUsername.requestFocus();
            } else {
                mUsername.setError(null);
                try {
                    Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
                    Account account = xmppConnectionService.findAccountByJid(jid);
                    if (account == null) {
                        account = new Account(jid, createPassword());
                        account.setOption(Account.OPTION_REGISTER, true);
                        account.setOption(Account.OPTION_DISABLED, true);
                        account.setOption(Account.OPTION_MAGIC_CREATE, true);
                        xmppConnectionService.createAccount(account);
                    }
                    Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class);
                    intent.putExtra("jid", account.getJid().toBareJid().toString());
                    intent.putExtra("init", true);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
                    startActivity(intent);
                } catch (InvalidJidException e) {
                    mUsername.setError(getString(R.string.invalid_username));
                    mUsername.requestFocus();
                }
            }
        }
    });
    mUsername.addTextChangedListener(this);
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) Button(android.widget.Button) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) SecureRandom(java.security.SecureRandom) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5