Search in sources :

Example 46 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final TextView yourAccount = dialogView.findViewById(R.id.your_account);
    final Spinner spinner = dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid);
    DelayedHintHelper.setHint(R.string.conference_address_example, jid);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    if (xmppConnectionService.multipleAccounts()) {
        yourAccount.setVisibility(View.VISIBLE);
        spinner.setVisibility(View.VISIBLE);
    } else {
        yourAccount.setVisibility(View.GONE);
        spinner.setVisibility(View.GONE);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (!xmppConnectionServiceBound) {
            return;
        }
        final Account account = getSelectedAccount(spinner);
        if (account == null) {
            return;
        }
        final Jid conferenceJid;
        try {
            conferenceJid = Jid.fromString(jid.getText().toString());
        } catch (final InvalidJidException e) {
            jid.setError(getString(R.string.invalid_jid));
            return;
        }
        if (bookmarkCheckBox.isChecked()) {
            if (account.hasBookmarkFor(conferenceJid)) {
                jid.setError(getString(R.string.bookmark_already_exists));
            } else {
                final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin)));
                String nick = conferenceJid.getResourcepart();
                if (nick != null && !nick.isEmpty()) {
                    bookmark.setNick(nick);
                }
                account.getBookmarks().add(bookmark);
                xmppConnectionService.pushBookmarks(account);
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
                bookmark.setConversation(conversation);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        } else {
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
            dialog.dismiss();
            mCurrentDialog = null;
            switchToConversation(conversation);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) KnownHostsAdapter(de.pixart.messenger.ui.adapter.KnownHostsAdapter) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(de.pixart.messenger.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 47 with Jid

use of de.pixart.messenger.xmpp.jid.Jid 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 48 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method processExtras.

private void processExtras(Bundle extras) {
    final String downloadUuid = extras.getString(ConversationActivity.EXTRA_DOWNLOAD_UUID);
    final String text = extras.getString(ConversationActivity.EXTRA_TEXT);
    final String nick = extras.getString(ConversationActivity.EXTRA_NICK);
    final boolean pm = extras.getBoolean(ConversationActivity.EXTRA_IS_PRIVATE_MESSAGE, false);
    if (nick != null) {
        if (pm) {
            Jid jid = conversation.getJid();
            try {
                Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
                privateMessageWith(next);
            } catch (final InvalidJidException ignored) {
            // do nothing
            }
        } else {
            highlightInConference(nick);
        }
    } else {
        appendText(text);
    }
    final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid);
    if (message != null) {
        startDownloadable(message);
    }
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

Example 49 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_conversation, container, false);
    // TODO why the fuck did we do this?
    binding.getRoot().setOnClickListener(null);
    binding.textinput.addTextChangedListener(new StylingHelper.MessageEditorStyler(binding.textinput));
    binding.textinput.setOnEditorActionListener(mEditorActionListener);
    binding.textinput.setRichContentListener(new String[] { "image/*" }, mEditorContentListener);
    binding.textSendButton.setOnClickListener(this.mSendButtonListener);
    binding.textSendButton.setOnLongClickListener(this.mSendButtonLongListener);
    binding.messagesView.setOnScrollListener(mOnScrollListener);
    binding.messagesView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL);
    messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList);
    messageListAdapter.setOnContactPictureClicked(message -> {
        final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
        if (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, getActivity().getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                    }
                    highlightInConference(user.getResourcepart());
                }
                return;
            } 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);
                    return;
                }
            }
        }
        Account account = message.getConversation().getAccount();
        Intent 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(message -> {
        if (message.getStatus() <= Message.STATUS_RECEIVED) {
            if (message.getConversation().getMode() == Conversation.MODE_MULTI) {
                final MucOptions mucOptions = conversation.getMucOptions();
                if (!mucOptions.allowPm()) {
                    Toast.makeText(getActivity(), R.string.private_messages_are_disabled, Toast.LENGTH_SHORT).show();
                    return;
                }
                Jid user = message.getCounterpart();
                if (user != null && !user.isBareJid()) {
                    if (mucOptions.isUserInRoom(user)) {
                        privateMessageWith(user);
                    } else {
                        Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResourcepart()), Toast.LENGTH_SHORT).show();
                    }
                }
            }
        } else {
            activity.showQrCode(conversation.getAccount().getShareableUri());
        }
    });
    messageListAdapter.setOnQuoteListener(this::quoteText);
    binding.messagesView.setAdapter(messageListAdapter);
    registerForContextMenu(binding.messagesView);
    return binding.getRoot();
}
Also used : MessageAdapter(de.pixart.messenger.ui.adapter.MessageAdapter) Account(de.pixart.messenger.entities.Account) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) StylingHelper(de.pixart.messenger.utils.StylingHelper)

Example 50 with Jid

use of de.pixart.messenger.xmpp.jid.Jid in project Pix-Art-Messenger by kriztan.

the class IqGenerator method changeAffiliation.

public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(conference.getJid().toBareJid());
    packet.setFrom(conference.getAccount().getJid());
    Element query = packet.query("http://jabber.org/protocol/muc#admin");
    for (Jid jid : jids) {
        Element item = query.addChild("item");
        item.setAttribute("jid", jid.toString());
        item.setAttribute("affiliation", affiliation);
    }
    return packet;
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Jid (de.pixart.messenger.xmpp.jid.Jid)75 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)26 Account (de.pixart.messenger.entities.Account)24 Element (de.pixart.messenger.xml.Element)19 Conversation (de.pixart.messenger.entities.Conversation)18 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)15 Contact (de.pixart.messenger.entities.Contact)14 MucOptions (de.pixart.messenger.entities.MucOptions)11 ArrayList (java.util.ArrayList)11 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)8 Message (de.pixart.messenger.entities.Message)7 Intent (android.content.Intent)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)6 Bookmark (de.pixart.messenger.entities.Bookmark)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)4 Map (java.util.Map)4 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)3 HashMap (java.util.HashMap)3