Search in sources :

Example 11 with Contact

use of eu.siacs.conversations.entities.Contact 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 12 with Contact

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

the class ChooseContactActivity method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    filterContacts = new HashSet<>();
    String[] contacts = getIntent().getStringArrayExtra("filter_contacts");
    if (contacts != null) {
        Collections.addAll(filterContacts, contacts);
    }
    if (getIntent().getBooleanExtra("multiple", false)) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {

            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                MenuInflater inflater = getMenuInflater();
                inflater.inflate(R.menu.select_multiple, menu);
                selected = new HashSet<Contact>();
                return true;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch(item.getItemId()) {
                    case R.id.selection_submit:
                        final Intent request = getIntent();
                        final Intent data = new Intent();
                        data.putExtra("conversation", request.getStringExtra("conversation"));
                        String[] selection = getSelectedContactJids();
                        data.putExtra("contacts", selection);
                        data.putExtra("multiple", true);
                        data.putExtra(EXTRA_ACCOUNT, request.getStringExtra(EXTRA_ACCOUNT));
                        data.putExtra("subject", request.getStringExtra("subject"));
                        setResult(RESULT_OK, data);
                        finish();
                        return true;
                }
                return false;
            }

            @Override
            public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
                Contact item = (Contact) getListItems().get(position);
                if (checked) {
                    selected.add(item);
                } else {
                    selected.remove(item);
                }
                int numSelected = selected.size();
                MenuItem selectButton = mode.getMenu().findItem(R.id.selection_submit);
                String buttonText = getResources().getQuantityString(R.plurals.select_contact, numSelected, numSelected);
                selectButton.setTitle(buttonText);
            }
        });
    }
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
            final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
            final Intent request = getIntent();
            final Intent data = new Intent();
            final ListItem mListItem = getListItems().get(position);
            data.putExtra("contact", mListItem.getJid().toString());
            String account = request.getStringExtra(EXTRA_ACCOUNT);
            if (account == null && mListItem instanceof Contact) {
                account = ((Contact) mListItem).getAccount().getJid().toBareJid().toString();
            }
            data.putExtra(EXTRA_ACCOUNT, account);
            data.putExtra("conversation", request.getStringExtra("conversation"));
            data.putExtra("multiple", false);
            data.putExtra("subject", request.getStringExtra("subject"));
            setResult(RESULT_OK, data);
            finish();
        }
    });
}
Also used : MenuInflater(android.view.MenuInflater) InputMethodManager(android.view.inputmethod.InputMethodManager) MenuItem(android.view.MenuItem) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Contact(eu.siacs.conversations.entities.Contact) ActionMode(android.view.ActionMode) AdapterView(android.widget.AdapterView) Menu(android.view.Menu) ListItem(eu.siacs.conversations.entities.ListItem) MultiChoiceModeListener(android.widget.AbsListView.MultiChoiceModeListener) HashSet(java.util.HashSet)

Example 13 with Contact

use of eu.siacs.conversations.entities.Contact 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 14 with Contact

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

the class ConferenceDetailsActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    Object tag = v.getTag();
    if (tag instanceof User) {
        getMenuInflater().inflate(R.menu.muc_details_context, menu);
        final User user = (User) tag;
        final User self = mConversation.getMucOptions().getSelf();
        this.mSelectedUser = user;
        String name;
        final Contact contact = user.getContact();
        if (contact != null) {
            name = contact.getDisplayName();
        } else if (user.getRealJid() != null) {
            name = user.getRealJid().toBareJid().toString();
        } else {
            name = user.getName();
        }
        menu.setHeaderTitle(name);
        if (user.getRealJid() != null) {
            MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
            MenuItem startConversation = menu.findItem(R.id.start_conversation);
            MenuItem giveMembership = menu.findItem(R.id.give_membership);
            MenuItem removeMembership = menu.findItem(R.id.remove_membership);
            MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
            MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
            MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
            MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
            MenuItem invite = menu.findItem(R.id.invite);
            startConversation.setVisible(true);
            if (contact != null) {
                showContactDetails.setVisible(!contact.isSelf());
            }
            if (user.getRole() == MucOptions.Role.NONE) {
                invite.setVisible(true);
            }
            if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) {
                if (mAdvancedMode) {
                    if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
                        giveMembership.setVisible(true);
                    } else {
                        removeMembership.setVisible(true);
                    }
                    banFromConference.setVisible(true);
                } else {
                    removeFromRoom.setVisible(true);
                }
                if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
                    giveAdminPrivileges.setVisible(true);
                } else {
                    removeAdminPrivileges.setVisible(true);
                }
            }
        } else {
            MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
            sendPrivateMessage.setVisible(user.getRole().ranks(MucOptions.Role.PARTICIPANT));
        }
    }
    super.onCreateContextMenu(menu, v, menuInfo);
}
Also used : User(eu.siacs.conversations.entities.MucOptions.User) MenuItem(android.view.MenuItem) Contact(eu.siacs.conversations.entities.Contact)

Example 15 with Contact

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

the class MessageParser method extractInvite.

private Invite extractInvite(Account account, Element message) {
    Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
    if (x != null) {
        Element invite = x.findChild("invite");
        if (invite != null) {
            Element pw = x.findChild("password");
            Jid from = invite.getAttributeAsJid("from");
            Contact contact = from == null ? null : account.getRoster().getContact(from);
            return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent() : null, contact);
        }
    } else {
        x = message.findChild("x", "jabber:x:conference");
        if (x != null) {
            Jid from = message.getAttributeAsJid("from");
            Contact contact = from == null ? null : account.getRoster().getContact(from);
            return new Invite(x.getAttributeAsJid("jid"), x.getAttribute("password"), contact);
        }
    }
    return null;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) Contact(eu.siacs.conversations.entities.Contact)

Aggregations

Contact (eu.siacs.conversations.entities.Contact)32 Account (eu.siacs.conversations.entities.Account)9 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 Conversation (eu.siacs.conversations.entities.Conversation)8 Element (eu.siacs.conversations.xml.Element)7 SuppressLint (android.annotation.SuppressLint)5 DialogInterface (android.content.DialogInterface)5 OnClickListener (android.content.DialogInterface.OnClickListener)4 AlertDialog (android.app.AlertDialog)3 Message (eu.siacs.conversations.entities.Message)3 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)3 Builder (android.app.AlertDialog.Builder)2 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Point (android.graphics.Point)2 Uri (android.net.Uri)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 Toast (android.widget.Toast)2 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)2