Search in sources :

Example 41 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class VCardManager method getVCard.

@SuppressWarnings("WeakerAccess")
void getVCard(final AccountJid account, final Jid srcUser) {
    final AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        onVCardFailed(account, srcUser);
        return;
    }
    final CustomVCardManager vCardManager = CustomVCardManager.getInstanceFor(accountItem.getConnection());
    if (!accountItem.getConnection().isAuthenticated()) {
        onVCardFailed(account, srcUser);
        return;
    }
    Collection<UserJid> blockedContacts = BlockingManager.getInstance().getBlockedContacts(account);
    for (UserJid blockedContact : blockedContacts) {
        if (blockedContact.getBareJid().equals(srcUser.asBareJid())) {
            return;
        }
    }
    final EntityBareJid entityBareJid = srcUser.asEntityBareJidIfPossible();
    if (entityBareJid != null) {
        vCardRequests.add(srcUser);
        try {
            vCardManager.sendVCardRequest(srcUser);
        } catch (SmackException.NotConnectedException e) {
            LogManager.exception(this, e);
            LogManager.w(this, "Error getting vCard: " + e.getMessage());
        } catch (ClassCastException e) {
            LogManager.exception(this, e);
            // http://stackoverflow.com/questions/31498721/error-loading-vcard-information-using-smack-emptyresultiq-cannot-be-cast-to-or
            LogManager.w(this, "ClassCastException: " + e.getMessage());
        // vCard = new VCard();
        } catch (InterruptedException e) {
            LogManager.exception(this, e);
        }
        vCardRequests.remove(srcUser);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 42 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ChatFragment method showResourceChoiceAlert.

public void showResourceChoiceAlert(final AccountJid account, final UserJid user, final boolean restartSession) {
    final List<Presence> allPresences = RosterManager.getInstance().getPresences(account, user.getJid());
    final List<Map<String, String>> items = new ArrayList<>();
    for (Presence presence : allPresences) {
        Jid fromJid = presence.getFrom();
        ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(fromJid);
        String client = "";
        if (clientInfo == null) {
            CapabilitiesManager.getInstance().requestClientInfoByUser(account, fromJid);
        } else if (clientInfo == ClientInfo.INVALID_CLIENT_INFO) {
            client = getString(R.string.unknown);
        } else {
            String name = clientInfo.getName();
            if (name != null) {
                client = name;
            }
            String type = clientInfo.getType();
            if (type != null) {
                if (client.isEmpty()) {
                    client = type;
                } else {
                    client = client + "/" + type;
                }
            }
        }
        Map<String, String> map = new HashMap<>();
        if (!client.isEmpty()) {
            map.put(ResourceAdapter.KEY_CLIENT, client);
        }
        Resourcepart resourceOrNull = fromJid.getResourceOrNull();
        if (resourceOrNull != null) {
            map.put(ResourceAdapter.KEY_RESOURCE, resourceOrNull.toString());
            items.add(map);
        }
    }
    final ResourceAdapter adapter = new ResourceAdapter(getActivity(), items);
    adapter.setCheckedItem(checkedResource);
    if (items.size() > 0) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(R.string.otr_select_resource);
        builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
            }
        });
        builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                checkedResource = adapter.getCheckedItem();
                try {
                    AbstractChat chat = getChat();
                    if (chat instanceof RegularChat) {
                        ((RegularChat) chat).setOTRresource(Resourcepart.from(items.get(checkedResource).get(ResourceAdapter.KEY_RESOURCE)));
                        if (restartSession)
                            restartEncryption(account, user);
                        else
                            startEncryption(account, user);
                    } else {
                        Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                    }
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), R.string.otr_select_toast_error, Toast.LENGTH_SHORT).show();
                }
            }
        });
        builder.setSingleChoiceItems(adapter, checkedResource, null).show();
    } else {
        Toast.makeText(getActivity(), R.string.otr_select_toast_resources_not_found, Toast.LENGTH_SHORT).show();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) AbstractChat(com.xabber.android.data.message.AbstractChat) ArrayList(java.util.ArrayList) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat) Resourcepart(org.jxmpp.jid.parts.Resourcepart) Presence(org.jivesoftware.smack.packet.Presence) ResourceAdapter(com.xabber.android.ui.adapter.ResourceAdapter) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class OccupantListFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    this.account = args.getParcelable(ARGUMENT_ACCOUNT);
    UserJid user = args.getParcelable(ARGUMENT_ROOM);
    if (user != null)
        this.room = user.getJid().asEntityBareJidIfPossible();
}
Also used : Bundle(android.os.Bundle) UserJid(com.xabber.android.data.entity.UserJid)

Example 44 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ChatFragment method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (menuItems != null && menuItems.size() > position) {
        HashMap<String, String> menuItem = menuItems.get(position);
        switch(menuItem.get(CustomMessageMenuAdapter.KEY_ID)) {
            case "action_message_repeat":
                if (clickedMessageItem.haveAttachments()) {
                    HttpFileUploadManager.getInstance().retrySendFileMessage(clickedMessageItem, getActivity());
                } else {
                    sendMessage(clickedMessageItem.getText());
                }
                break;
            case "action_message_copy":
                Spannable spannable = MessageItem.getSpannable(clickedMessageItem);
                ((ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText(spannable, spannable));
                break;
            case "action_message_appeal":
                mentionUser(clickedMessageItem.getResource().toString());
                break;
            case "action_message_quote":
                setInputTextAtCursor("> " + clickedMessageItem.getText() + "\n");
                break;
            case "action_message_remove":
                MessageManager.getInstance().removeMessage(clickedMessageItem.getUniqueId());
                break;
            case "action_message_open_muc_private_chat":
                UserJid occupantFullJid = null;
                try {
                    occupantFullJid = UserJid.from(JidCreate.domainFullFrom(user.getJid().asDomainBareJid(), clickedMessageItem.getResource()));
                    MessageManager.getInstance().openChat(account, occupantFullJid);
                    startActivity(ChatActivity.createSpecificChatIntent(getActivity(), account, occupantFullJid));
                } catch (UserJid.UserJidCreateException e) {
                    LogManager.exception(this, e);
                }
                break;
            case "action_message_show_original_otr":
                chatMessageAdapter.addOrRemoveItemNeedOriginalText(clickedMessageItem.getUniqueId());
                chatMessageAdapter.notifyDataSetChanged();
                break;
            case "action_message_status":
                if (clickedMessageItem.isError())
                    showError(clickedMessageItem.getErrorDescription());
                break;
            default:
                break;
        }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) UserJid(com.xabber.android.data.entity.UserJid) Spannable(android.text.Spannable)

Example 45 with UserJid

use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.

the class ContextMenuHelper method createContactContextMenu.

public static void createContactContextMenu(final Activity activity, ContactListPresenter presenter, AbstractContact abstractContact, ContextMenu menu) {
    final AccountJid account = abstractContact.getAccount();
    final UserJid user = abstractContact.getUser();
    menu.setHeaderTitle(abstractContact.getName());
    MenuInflater inflater = activity.getMenuInflater();
    inflater.inflate(R.menu.item_contact, menu);
    setContactContextMenuActions(activity, presenter, menu, account, user);
    setContactContextMenuItemsVisibilty(abstractContact, menu, account, user);
}
Also used : MenuInflater(android.view.MenuInflater) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3