Search in sources :

Example 51 with Conversation

use of de.pixart.messenger.entities.Conversation 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 52 with Conversation

use of de.pixart.messenger.entities.Conversation 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 53 with Conversation

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

the class ConversationActivity method handlePositiveActivityResult.

private void handlePositiveActivityResult(int requestCode, final Intent data) {
    Log.d(Config.LOGTAG, "positive activity result");
    Conversation conversation = ConversationFragment.getConversationReliable(this);
    if (conversation == null) {
        Log.d(Config.LOGTAG, "conversation not found");
        return;
    }
    switch(requestCode) {
        case REQUEST_DECRYPT_PGP:
            conversation.getAccount().getPgpDecryptionService().continueDecryption(data);
            break;
        case REQUEST_CHOOSE_PGP_ID:
            long id = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, 0);
            if (id != 0) {
                conversation.getAccount().setPgpSignId(id);
                announcePgp(conversation.getAccount(), null, null, onOpenPGPKeyPublished);
            } else {
                choosePgpSignId(conversation.getAccount());
            }
            break;
        case REQUEST_ANNOUNCE_PGP:
            announcePgp(conversation.getAccount(), conversation, data, onOpenPGPKeyPublished);
            break;
    }
}
Also used : Conversation(de.pixart.messenger.entities.Conversation)

Example 54 with Conversation

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

the class ConversationActivity method processViewIntent.

private boolean processViewIntent(Intent intent) {
    Log.d(Config.LOGTAG, "process view intent");
    String uuid = intent.getStringExtra(EXTRA_CONVERSATION);
    Conversation conversation = uuid != null ? xmppConnectionService.findConversationByUuid(uuid) : null;
    if (conversation == null) {
        Log.d(Config.LOGTAG, "unable to view conversation with uuid:" + uuid);
        return false;
    }
    openConversation(conversation, intent.getExtras());
    return true;
}
Also used : Conversation(de.pixart.messenger.entities.Conversation)

Example 55 with Conversation

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

the class ConversationFragment method resendMessage.

public void resendMessage(final Message message) {
    if (message.isFileOrImage()) {
        DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message);
        if (file.exists()) {
            final Conversation conversation = message.getConversation();
            final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection();
            if (!message.hasFileOnRemoteHost() && xmppConnection != null && !xmppConnection.getFeatures().httpUpload(message.getFileParams().size)) {
                activity.selectPresence(conversation, () -> {
                    message.setCounterpart(conversation.getNextCounterpart());
                    activity.xmppConnectionService.resendFailedMessages(message);
                    new Handler().post(() -> {
                        int size = messageList.size();
                        this.binding.messagesView.setSelection(size - 1);
                    });
                });
                return;
            }
        } else {
            Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show();
            message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED));
            activity.onConversationsListItemUpdated();
            refresh();
            return;
        }
    }
    activity.xmppConnectionService.resendFailedMessages(message);
    new Handler().post(() -> {
        int size = messageList.size();
        this.binding.messagesView.setSelection(size - 1);
    });
}
Also used : XmppConnection(de.pixart.messenger.xmpp.XmppConnection) TransferablePlaceholder(de.pixart.messenger.entities.TransferablePlaceholder) Handler(android.os.Handler) Conversation(de.pixart.messenger.entities.Conversation) DownloadableFile(de.pixart.messenger.entities.DownloadableFile) SuppressLint(android.annotation.SuppressLint)

Aggregations

Conversation (de.pixart.messenger.entities.Conversation)69 Jid (de.pixart.messenger.xmpp.jid.Jid)20 Account (de.pixart.messenger.entities.Account)18 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)16 Message (de.pixart.messenger.entities.Message)15 Contact (de.pixart.messenger.entities.Contact)11 MucOptions (de.pixart.messenger.entities.MucOptions)9 Intent (android.content.Intent)7 SuppressLint (android.annotation.SuppressLint)6 Uri (android.net.Uri)6 SpannableString (android.text.SpannableString)6 View (android.view.View)6 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)6 DownloadableFile (de.pixart.messenger.entities.DownloadableFile)6 Element (de.pixart.messenger.xml.Element)6 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)6 IOException (java.io.IOException)6 Fragment (android.app.Fragment)5 SharedPreferences (android.content.SharedPreferences)5 Bitmap (android.graphics.Bitmap)5