Search in sources :

Example 31 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method filterContacts.

protected void filterContacts(String needle) {
    this.contacts.clear();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (Contact contact : account.getRoster().getContacts()) {
                Presence.Status s = contact.getShownStatus();
                if (contact.showInRoster() && contact.match(this, needle) && (!this.mHideOfflineContacts || (needle != null && !needle.trim().isEmpty()) || s.compareTo(Presence.Status.OFFLINE) < 0)) {
                    this.contacts.add(contact);
                }
            }
        }
    }
    Collections.sort(this.contacts);
    mContactsAdapter.notifyDataSetChanged();
}
Also used : Account(de.pixart.messenger.entities.Account) Presence(de.pixart.messenger.entities.Presence) Contact(de.pixart.messenger.entities.Contact)

Example 32 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method handleJid.

private boolean handleJid(Invite invite) {
    List<Contact> contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account);
    if (invite.isAction(XmppUri.ACTION_JOIN)) {
        Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid());
        if (muc != null) {
            switchToConversation(muc, invite.getBody(), false);
            return true;
        } else {
            showJoinConferenceDialog(invite.getJid().toBareJid().toString());
            return false;
        }
    } else if (contacts.size() == 0) {
        showCreateContactDialog(invite.getJid().toString(), invite);
        return false;
    } else if (contacts.size() == 1) {
        Contact contact = contacts.get(0);
        if (!invite.isSafeSource() && invite.hasFingerprints()) {
            displayVerificationWarningDialog(contact, invite);
        } else {
            if (invite.hasFingerprints()) {
                if (xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints())) {
                    Toast.makeText(this, R.string.verified_fingerprints, Toast.LENGTH_SHORT).show();
                }
            }
            if (invite.account != null) {
                xmppConnectionService.getShortcutService().report(contact);
            }
            switchToConversation(contact, invite.getBody());
        }
        return true;
    } else {
        if (mMenuSearchView != null) {
            mMenuSearchView.expandActionView();
            mSearchEditText.setText("");
            mSearchEditText.append(invite.getJid().toString());
            filter(invite.getJid().toString());
        } else {
            mInitialJid = invite.getJid().toString();
        }
        return true;
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation) Contact(de.pixart.messenger.entities.Contact)

Example 33 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

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();
        final Jid jid = user.getFullJid();
        this.mSelectedUser = user;
        String name;
        final Contact contact = user.getContact();
        if (contact != null && contact.showInRoster()) {
            name = contact.getDisplayName();
        } else if (user.getRealJid() != null) {
            name = user.getRealJid().toBareJid().toString();
        } else {
            name = user.getName();
        }
        menu.setHeaderTitle(name);
        MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
        MenuItem highlightInMuc = menu.findItem(R.id.highlight_in_muc);
        if (user.getRealJid() != null) {
            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 (user.getRole() == MucOptions.Role.NONE) {
                invite.setVisible(true);
            }
            if (jid != null && !jid.isBareJid()) {
                if (mConversation.getMucOptions().isUserInRoom(jid)) {
                    sendPrivateMessage.setVisible(true);
                } else {
                    sendPrivateMessage.setVisible(false);
                }
            }
            if (self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) {
                if (mAdvancedMode) {
                    if (user.getAffiliation() != MucOptions.Affiliation.ADMIN) {
                        giveAdminPrivileges.setVisible(true);
                    } else {
                        removeAdminPrivileges.setVisible(true);
                    }
                } else {
                    removeFromRoom.setVisible(true);
                }
                if (user.getAffiliation() == MucOptions.Affiliation.NONE) {
                    giveMembership.setVisible(true);
                } else {
                    removeMembership.setVisible(true);
                }
                banFromConference.setVisible(true);
            }
        } else {
            if (jid != null && !jid.isBareJid()) {
                if (mConversation.getMucOptions().isUserInRoom(jid)) {
                    sendPrivateMessage.setVisible(true);
                } else {
                    sendPrivateMessage.setVisible(false);
                }
            }
            highlightInMuc.setVisible(self.getRole().ranks(MucOptions.Role.PARTICIPANT));
        }
    }
    super.onCreateContextMenu(menu, v, menuInfo);
}
Also used : User(de.pixart.messenger.entities.MucOptions.User) Jid(de.pixart.messenger.xmpp.jid.Jid) MenuItem(android.view.MenuItem) Contact(de.pixart.messenger.entities.Contact)

Example 34 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method sendPgpMessage.

protected void sendPgpMessage(final Message message) {
    final XmppConnectionService xmppService = activity.xmppConnectionService;
    final Contact contact = message.getConversation().getContact();
    if (!activity.hasPgp()) {
        activity.showInstallPgpDialog();
        return;
    }
    if (conversation.getAccount().getPgpSignature() == null) {
        activity.announcePgp(conversation.getAccount(), conversation, null, activity.onOpenPGPKeyPublished);
        return;
    }
    if (!mSendingPgpMessage.compareAndSet(false, true)) {
        Log.d(Config.LOGTAG, "sending pgp message already in progress");
    }
    if (conversation.getMode() == Conversation.MODE_SINGLE) {
        if (contact.getPgpKeyId() != 0) {
            xmppService.getPgpEngine().hasKey(contact, new UiCallback<Contact>() {

                @Override
                public void userInputRequried(PendingIntent pi, Contact contact) {
                    startPendingIntent(pi, REQUEST_ENCRYPT_MESSAGE);
                }

                @Override
                public void success(Contact contact) {
                    encryptTextMessage(message);
                }

                @Override
                public void error(int error, Contact contact) {
                    activity.runOnUiThread(() -> Toast.makeText(activity, R.string.unable_to_connect_to_keychain, Toast.LENGTH_SHORT).show());
                    mSendingPgpMessage.set(false);
                }
            });
        } else {
            showNoPGPKeyDialog(false, (dialog, which) -> {
                conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                xmppService.updateConversation(conversation);
                message.setEncryption(Message.ENCRYPTION_NONE);
                xmppService.sendMessage(message);
                messageSent();
            });
        }
    } else {
        if (conversation.getMucOptions().pgpKeysInUse()) {
            if (!conversation.getMucOptions().everybodyHasKeys()) {
                Toast warning = Toast.makeText(getActivity(), R.string.missing_public_keys, Toast.LENGTH_LONG);
                warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                warning.show();
            }
            encryptTextMessage(message);
        } else {
            showNoPGPKeyDialog(true, (dialog, which) -> {
                conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                message.setEncryption(Message.ENCRYPTION_NONE);
                xmppService.updateConversation(conversation);
                xmppService.sendMessage(message);
                messageSent();
            });
        }
    }
}
Also used : XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) Toast(android.widget.Toast) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Example 35 with Contact

use of de.pixart.messenger.entities.Contact in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method attachFile.

public void attachFile(final int attachmentChoice) {
    if (attachmentChoice == ATTACHMENT_CHOICE_TAKE_FROM_CAMERA) {
        if (!hasStorageAndCameraPermission(attachmentChoice)) {
            return;
        }
    } else if (attachmentChoice != ATTACHMENT_CHOICE_LOCATION) {
        if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(attachmentChoice)) {
            return;
        }
    }
    if (attachmentChoice == ATTACHMENT_CHOICE_RECORD_VOICE) {
        if (!activity.hasMicPermission(attachmentChoice)) {
            return;
        }
    }
    if (attachmentChoice == ATTACHMENT_CHOICE_LOCATION) {
        if (!activity.hasLocationPermission(attachmentChoice)) {
            return;
        }
    }
    try {
        activity.getPreferences().edit().putString(RECENTLY_USED_QUICK_ACTION, SendButtonAction.of(attachmentChoice).toString()).apply();
    } catch (IllegalArgumentException e) {
    // just do not save
    }
    final int encryption = conversation.getNextEncryption();
    final int mode = conversation.getMode();
    if (encryption == Message.ENCRYPTION_PGP) {
        if (activity.hasPgp()) {
            if (mode == Conversation.MODE_SINGLE && conversation.getContact().getPgpKeyId() != 0) {
                activity.xmppConnectionService.getPgpEngine().hasKey(conversation.getContact(), new UiCallback<Contact>() {

                    @Override
                    public void userInputRequried(PendingIntent pi, Contact contact) {
                        startPendingIntent(pi, attachmentChoice);
                    }

                    @Override
                    public void success(Contact contact) {
                        selectPresenceToAttachFile(attachmentChoice);
                    }

                    @Override
                    public void error(int error, Contact contact) {
                        activity.replaceToast(getString(error));
                    }
                });
            } else if (mode == Conversation.MODE_MULTI && conversation.getMucOptions().pgpKeysInUse()) {
                if (!conversation.getMucOptions().everybodyHasKeys()) {
                    getActivity().runOnUiThread(() -> {
                        Toast warning = Toast.makeText(activity, R.string.missing_public_keys, Toast.LENGTH_LONG);
                        warning.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                        warning.show();
                    });
                }
                selectPresenceToAttachFile(attachmentChoice);
            } else {
                final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
                if (fragment != null) {
                    fragment.showNoPGPKeyDialog(false, (dialog, which) -> {
                        conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                        activity.xmppConnectionService.updateConversation(conversation);
                        selectPresenceToAttachFile(attachmentChoice);
                    });
                }
            }
        } else {
            activity.showInstallPgpDialog();
        }
    } else {
        if (encryption != Message.ENCRYPTION_AXOLOTL || !trustKeysIfNeeded(REQUEST_TRUST_KEYS_MENU, attachmentChoice)) {
            selectPresenceToAttachFile(attachmentChoice);
        }
    }
}
Also used : Arrays(java.util.Arrays) HttpDownloadConnection(de.pixart.messenger.http.HttpDownloadConnection) Bundle(android.os.Bundle) MessageUtils(de.pixart.messenger.utils.MessageUtils) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Uri(android.net.Uri) ImageView(android.widget.ImageView) EXTRA_ACCOUNT(de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT) Account(de.pixart.messenger.entities.Account) Manifest(android.Manifest) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) PopupMenu(android.widget.PopupMenu) ActivityResult(de.pixart.messenger.ui.util.ActivityResult) Log(android.util.Log) Set(java.util.Set) SendButtonTool(de.pixart.messenger.ui.util.SendButtonTool) Contact(de.pixart.messenger.entities.Contact) Transferable(de.pixart.messenger.entities.Transferable) EditMessage(de.pixart.messenger.ui.widget.EditMessage) TextWatcher(android.text.TextWatcher) UIHelper(de.pixart.messenger.utils.UIHelper) ContextMenuInfo(android.view.ContextMenu.ContextMenuInfo) SimpleDateFormat(java.text.SimpleDateFormat) BitmapFactory(android.graphics.BitmapFactory) SystemClock(android.os.SystemClock) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) SessionStatus(net.java.otr4j.session.SessionStatus) ArrayList(java.util.ArrayList) Conversation(de.pixart.messenger.entities.Conversation) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ENCRYPTION_EXCEPTIONS(de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS) Fragment(android.app.Fragment) InputContentInfoCompat(android.support.v13.view.inputmethod.InputContentInfoCompat) FingerprintStatus(de.pixart.messenger.crypto.axolotl.FingerprintStatus) IOException(java.io.IOException) ScrollState(de.pixart.messenger.ui.util.ScrollState) File(java.io.File) IdRes(android.support.annotation.IdRes) Gravity(android.view.Gravity) AlertDialog(android.support.v7.app.AlertDialog) SharedPreferences(android.content.SharedPreferences) DataBindingUtil(android.databinding.DataBindingUtil) SendButtonAction(de.pixart.messenger.ui.util.SendButtonAction) ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) LinearLayout(android.widget.LinearLayout) PackageManager(android.content.pm.PackageManager) PendingIntent(android.app.PendingIntent) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Jid(de.pixart.messenger.xmpp.jid.Jid) CheckBox(android.widget.CheckBox) Locale(java.util.Locale) View(android.view.View) AdapterView(android.widget.AdapterView) SendIntentException(android.content.IntentSender.SendIntentException) PreferenceManager(android.preference.PreferenceManager) Presence(de.pixart.messenger.entities.Presence) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) MessageAdapter(de.pixart.messenger.ui.adapter.MessageAdapter) ExifInterface(android.support.media.ExifInterface) FragmentConversationBinding(de.pixart.messenger.databinding.FragmentConversationBinding) UUID(java.util.UUID) ViewGroup(android.view.ViewGroup) OnScrollListener(android.widget.AbsListView.OnScrollListener) ConversationMenuConfigurator(de.pixart.messenger.ui.util.ConversationMenuConfigurator) List(java.util.List) ActivityNotFoundException(android.content.ActivityNotFoundException) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) FileUtils(de.pixart.messenger.utils.FileUtils) ListView(android.widget.ListView) AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) XmppConnection(de.pixart.messenger.xmpp.XmppConnection) EditorInfo(android.view.inputmethod.EditorInfo) Blockable(de.pixart.messenger.entities.Blockable) Context(android.content.Context) ContextMenu(android.view.ContextMenu) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) MessageArchiveService(de.pixart.messenger.services.MessageArchiveService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Intent(android.content.Intent) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) FileBackend(de.pixart.messenger.persistance.FileBackend) OnSwipeTouchListener(de.pixart.messenger.ui.interfaces.OnSwipeTouchListener) MotionEvent(android.view.MotionEvent) R(de.pixart.messenger.R) AttachmentTool(de.pixart.messenger.ui.util.AttachmentTool) Build(android.os.Build) Config(de.pixart.messenger.Config) NickValidityChecker(de.pixart.messenger.utils.NickValidityChecker) DialogInterface(android.content.DialogInterface) Message(de.pixart.messenger.entities.Message) MucOptions(de.pixart.messenger.entities.MucOptions) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) StylingHelper(de.pixart.messenger.utils.StylingHelper) InputConnectionCompat(android.support.v13.view.inputmethod.InputConnectionCompat) PendingItem(de.pixart.messenger.ui.util.PendingItem) Bitmap(android.graphics.Bitmap) Activity(android.app.Activity) Collections(java.util.Collections) PresenceSelector(de.pixart.messenger.ui.util.PresenceSelector) OnClickListener(android.view.View.OnClickListener) REQUEST_INVITE_TO_CONVERSATION(de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION) Toast(android.widget.Toast) PendingIntent(android.app.PendingIntent) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Aggregations

Contact (de.pixart.messenger.entities.Contact)39 Jid (de.pixart.messenger.xmpp.jid.Jid)16 Account (de.pixart.messenger.entities.Account)12 Conversation (de.pixart.messenger.entities.Conversation)11 Element (de.pixart.messenger.xml.Element)9 SuppressLint (android.annotation.SuppressLint)7 MucOptions (de.pixart.messenger.entities.MucOptions)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)5 ArrayList (java.util.ArrayList)5 PendingIntent (android.app.PendingIntent)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 MenuItem (android.view.MenuItem)4 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 DialogInterface (android.content.DialogInterface)3 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 Message (de.pixart.messenger.entities.Message)3 Presence (de.pixart.messenger.entities.Presence)3