Search in sources :

Example 31 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class MessageParser method getTrueCounterpart.

private static Jid getTrueCounterpart(Element mucUserElement, Jid fallback) {
    final Element item = mucUserElement == null ? null : mucUserElement.findChild("item");
    Jid result = item == null ? null : item.getAttributeAsJid("jid");
    return result != null ? result : fallback;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element)

Example 32 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class ChooseContactActivity method showEnterJidDialog.

protected void showEnterJidDialog() {
    EnterJidDialog dialog = new EnterJidDialog(this, mKnownHosts, mActivatedAccounts, getString(R.string.enter_contact), getString(R.string.select), null, getIntent().getStringExtra(EXTRA_ACCOUNT), true);
    dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {

        @Override
        public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
            final Intent request = getIntent();
            final Intent data = new Intent();
            data.putExtra("contact", contactJid.toString());
            data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
            data.putExtra("conversation", request.getStringExtra("conversation"));
            data.putExtra("multiple", false);
            data.putExtra("subject", request.getStringExtra("subject"));
            setResult(RESULT_OK, data);
            finish();
            return true;
        }
    });
    dialog.show();
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Intent(android.content.Intent)

Example 33 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class XmppConnectionService method changeAffiliationsInConference.

public void changeAffiliationsInConference(final Conversation conference, MucOptions.Affiliation before, MucOptions.Affiliation after) {
    List<Jid> jids = new ArrayList<>();
    for (MucOptions.User user : conference.getMucOptions().getUsers()) {
        if (user.getAffiliation() == before && user.getRealJid() != null) {
            jids.add(user.getRealJid());
        }
    }
    IqPacket request = this.mIqGenerator.changeAffiliation(conference, jids, after.toString());
    sendIqPacket(conference.getAccount(), request, mDefaultIqHandler);
}
Also used : MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.jid.Jid) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 34 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class XmppConnectionService method fetchConferenceMembers.

private void fetchConferenceMembers(final Conversation conversation) {
    final Account account = conversation.getAccount();
    final String[] affiliations = { "member", "admin", "owner" };
    OnIqPacketReceived callback = new OnIqPacketReceived() {

        private int i = 0;

        private boolean success = true;

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.query("http://jabber.org/protocol/muc#admin");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                for (Element child : query.getChildren()) {
                    if ("item".equals(child.getName())) {
                        MucOptions.User user = AbstractParser.parseItem(conversation, child);
                        if (!user.realJidMatchesAccount()) {
                            conversation.getMucOptions().updateUser(user);
                        }
                    }
                }
            } else {
                success = false;
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not request affiliation " + affiliations[i] + " in " + conversation.getJid().toBareJid());
            }
            ++i;
            if (i >= affiliations.length) {
                List<Jid> members = conversation.getMucOptions().getMembers();
                if (success) {
                    List<Jid> cryptoTargets = conversation.getAcceptedCryptoTargets();
                    boolean changed = false;
                    for (ListIterator<Jid> iterator = cryptoTargets.listIterator(); iterator.hasNext(); ) {
                        Jid jid = iterator.next();
                        if (!members.contains(jid)) {
                            iterator.remove();
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": removed " + jid + " from crypto targets of " + conversation.getName());
                            changed = true;
                        }
                    }
                    if (changed) {
                        conversation.setAcceptedCryptoTargets(cryptoTargets);
                        updateConversation(conversation);
                    }
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved members for " + conversation.getJid().toBareJid() + ": " + conversation.getMucOptions().getMembers());
                getAvatarService().clear(conversation);
                updateMucRosterUi();
                updateConversationUi();
            }
        }
    };
    for (String affiliation : affiliations) {
        sendIqPacket(account, mIqGenerator.queryAffiliation(conversation, affiliation), callback);
    }
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching members for " + conversation.getName());
}
Also used : Account(eu.siacs.conversations.entities.Account) MucOptions(eu.siacs.conversations.entities.MucOptions) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 35 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_conversation, container, false);
    view.setOnClickListener(null);
    String[] allImagesMimeType = { "image/*" };
    mEditMessage = (EditMessage) view.findViewById(R.id.textinput);
    mEditMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (activity != null) {
                activity.hideConversationsOverview();
            }
        }
    });
    mEditMessage.setOnEditorActionListener(mEditorActionListener);
    mEditMessage.setRichContentListener(allImagesMimeType, mEditorContentListener);
    mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
    mSendButton.setOnClickListener(this.mSendButtonListener);
    snackbar = (RelativeLayout) view.findViewById(R.id.snackbar);
    snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message);
    snackbarAction = (TextView) view.findViewById(R.id.snackbar_action);
    messagesView = (ListView) view.findViewById(R.id.messages_view);
    messagesView.setOnScrollListener(mOnScrollListener);
    messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    messageListAdapter = new MessageAdapter((ConversationActivity) getActivity(), this.messageList);
    messageListAdapter.setOnContactPictureClicked(new OnContactPictureClicked() {

        @Override
        public void onContactPictureClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (!message.getConversation().getMucOptions().isUserInRoom(user)) {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                        highlightInConference(user.getResourcepart());
                    }
                } else {
                    if (!message.getContact().isSelf()) {
                        String fingerprint;
                        if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                            fingerprint = "pgp";
                        } else {
                            fingerprint = message.getFingerprint();
                        }
                        activity.switchToContactDetails(message.getContact(), fingerprint);
                    }
                }
            } else {
                Account account = message.getConversation().getAccount();
                Intent intent;
                if (activity.manuallyChangePresence()) {
                    intent = new Intent(activity, SetPresenceActivity.class);
                    intent.putExtra(SetPresenceActivity.EXTRA_ACCOUNT, account.getJid().toBareJid().toString());
                } else {
                    intent = new Intent(activity, EditAccountActivity.class);
                    intent.putExtra("jid", account.getJid().toBareJid().toString());
                    String fingerprint;
                    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
                        fingerprint = "pgp";
                    } else {
                        fingerprint = message.getFingerprint();
                    }
                    intent.putExtra("fingerprint", fingerprint);
                }
                startActivity(intent);
            }
        }
    });
    messageListAdapter.setOnContactPictureLongClicked(new OnContactPictureLongClicked() {

        @Override
        public void onContactPictureLongClicked(Message message) {
            if (message.getStatus() <= Message.STATUS_RECEIVED) {
                if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                    Jid user = message.getCounterpart();
                    if (user != null && !user.isBareJid()) {
                        if (message.getConversation().getMucOptions().isUserInRoom(user)) {
                            privateMessageWith(user);
                        } else {
                            Toast.makeText(activity, activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            } else {
                activity.showQrCode();
            }
        }
    });
    messageListAdapter.setOnQuoteListener(new MessageAdapter.OnQuoteListener() {

        @Override
        public void onQuote(String text) {
            if (mEditMessage.isEnabled()) {
                text = text.replaceAll("(\n *){2,}", "\n").replaceAll("(^|\n)", "$1> ").replaceAll("\n$", "");
                Editable editable = mEditMessage.getEditableText();
                int position = mEditMessage.getSelectionEnd();
                if (position == -1)
                    position = editable.length();
                if (position > 0 && editable.charAt(position - 1) != '\n') {
                    editable.insert(position++, "\n");
                }
                editable.insert(position, text);
                position += text.length();
                editable.insert(position++, "\n");
                if (position < editable.length() && editable.charAt(position) != '\n') {
                    editable.insert(position, "\n");
                }
                mEditMessage.setSelection(position);
                mEditMessage.requestFocus();
                InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (inputMethodManager != null) {
                    inputMethodManager.showSoftInput(mEditMessage, InputMethodManager.SHOW_IMPLICIT);
                }
            }
        }
    });
    messagesView.setAdapter(messageListAdapter);
    registerForContextMenu(messagesView);
    return view;
}
Also used : MessageAdapter(eu.siacs.conversations.ui.adapter.MessageAdapter) Account(eu.siacs.conversations.entities.Account) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) OnContactPictureLongClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureLongClicked) OnContactPictureClicked(eu.siacs.conversations.ui.adapter.MessageAdapter.OnContactPictureClicked) OnClickListener(android.view.View.OnClickListener) Editable(android.text.Editable)

Aggregations

Jid (eu.siacs.conversations.xmpp.jid.Jid)59 Account (eu.siacs.conversations.entities.Account)22 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)19 Element (eu.siacs.conversations.xml.Element)17 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)14 Conversation (eu.siacs.conversations.entities.Conversation)13 Contact (eu.siacs.conversations.entities.Contact)9 MucOptions (eu.siacs.conversations.entities.MucOptions)9 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)9 Message (eu.siacs.conversations.entities.Message)7 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 HashMap (java.util.HashMap)4 PendingIntent (android.app.PendingIntent)3