Search in sources :

Example 76 with Account

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

the class ContactDetailsActivity method onBackendConnected.

public void onBackendConnected() {
    if (accountJid != null && contactJid != null) {
        Account account = xmppConnectionService.findAccountByJid(accountJid);
        if (account == null) {
            return;
        }
        this.mConversation = xmppConnectionService.findConversation(account, contactJid, false);
        if (this.mConversation != null) {
            populateView();
        }
        this.contact = account.getRoster().getContact(contactJid);
        if (mPendingFingerprintVerificationUri != null) {
            processFingerprintVerification(mPendingFingerprintVerificationUri);
            mPendingFingerprintVerificationUri = null;
        }
        populateView();
    }
}
Also used : Account(de.pixart.messenger.entities.Account)

Example 77 with Account

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

the class ConversationActivity method getRedirectionIntent.

private Intent getRedirectionIntent(boolean noAnimation) {
    Account pendingAccount = xmppConnectionService.getPendingAccount();
    Intent intent;
    if (pendingAccount != null) {
        intent = new Intent(this, EditAccountActivity.class);
        intent.putExtra("jid", pendingAccount.getJid().toBareJid().toString());
    } else {
        if (xmppConnectionService.getAccounts().size() == 0) {
            if (Config.X509_VERIFICATION) {
                intent = new Intent(this, ManageAccountActivity.class);
            } else if (Config.MAGIC_CREATE_DOMAIN != null) {
                intent = new Intent(this, WelcomeActivity.class);
                WelcomeActivity.addInviteUri(intent, getIntent());
            } else {
                intent = new Intent(this, EditAccountActivity.class);
            }
        } else {
            intent = new Intent(this, StartConversationActivity.class);
        }
    }
    intent.putExtra("init", true);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    if (noAnimation) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    }
    return intent;
}
Also used : Account(de.pixart.messenger.entities.Account) Intent(android.content.Intent)

Example 78 with Account

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

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

the class AxolotlService method fetchDeviceIds.

public void fetchDeviceIds(final Jid jid, OnDeviceIdsFetched callback) {
    synchronized (this.fetchDeviceIdsMap) {
        List<OnDeviceIdsFetched> callbacks = this.fetchDeviceIdsMap.get(jid);
        if (callbacks != null) {
            if (callback != null) {
                callbacks.add(callback);
            }
            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching device ids for " + jid + " already running. adding callback");
        } else {
            callbacks = new ArrayList<>();
            if (callback != null) {
                callbacks.add(callback);
            }
            this.fetchDeviceIdsMap.put(jid, callbacks);
            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetching device ids for " + jid);
            IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(jid);
            mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    synchronized (fetchDeviceIdsMap) {
                        List<OnDeviceIdsFetched> callbacks = fetchDeviceIdsMap.remove(jid);
                        if (packet.getType() == IqPacket.TYPE.RESULT) {
                            Element item = mXmppConnectionService.getIqParser().getItem(packet);
                            Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
                            registerDevices(jid, deviceIds);
                            if (callbacks != null) {
                                for (OnDeviceIdsFetched callback : callbacks) {
                                    callback.fetched(jid, deviceIds);
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, packet.toString());
                            if (callbacks != null) {
                                for (OnDeviceIdsFetched callback : callbacks) {
                                    callback.fetched(jid, null);
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Set(java.util.Set) HashSet(java.util.HashSet) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) List(java.util.List) ArrayList(java.util.ArrayList) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 80 with Account

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

the class AxolotlService method buildSessionFromPEP.

private void buildSessionFromPEP(final SignalProtocolAddress address) {
    Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Building new session for " + address.toString());
    if (address.equals(getOwnAxolotlAddress())) {
        throw new AssertionError("We should NEVER build a session with ourselves. What happened here?!");
    }
    try {
        IqPacket bundlesPacket = mXmppConnectionService.getIqGenerator().retrieveBundlesForDevice(Jid.fromString(address.getName()), address.getDeviceId());
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Retrieving bundle: " + bundlesPacket);
        mXmppConnectionService.sendIqPacket(account, bundlesPacket, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                    fetchStatusMap.put(address, FetchStatus.TIMEOUT);
                } else if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received preKey IQ packet, processing...");
                    final IqParser parser = mXmppConnectionService.getIqParser();
                    final List<PreKeyBundle> preKeyBundleList = parser.preKeys(packet);
                    final PreKeyBundle bundle = parser.bundle(packet);
                    if (preKeyBundleList.isEmpty() || bundle == null) {
                        Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "preKey IQ packet invalid: " + packet);
                        fetchStatusMap.put(address, FetchStatus.ERROR);
                        finishBuildingSessionsFromPEP(address);
                        return;
                    }
                    Random random = new Random();
                    final PreKeyBundle preKey = preKeyBundleList.get(random.nextInt(preKeyBundleList.size()));
                    if (preKey == null) {
                        // should never happen
                        fetchStatusMap.put(address, FetchStatus.ERROR);
                        finishBuildingSessionsFromPEP(address);
                        return;
                    }
                    final PreKeyBundle preKeyBundle = new PreKeyBundle(0, address.getDeviceId(), preKey.getPreKeyId(), preKey.getPreKey(), bundle.getSignedPreKeyId(), bundle.getSignedPreKey(), bundle.getSignedPreKeySignature(), bundle.getIdentityKey());
                    try {
                        SessionBuilder builder = new SessionBuilder(axolotlStore, address);
                        builder.process(preKeyBundle);
                        XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, bundle.getIdentityKey());
                        sessions.put(address, session);
                        if (Config.X509_VERIFICATION) {
                            verifySessionWithPEP(session);
                        } else {
                            FingerprintStatus status = getFingerprintTrust(CryptoHelper.bytesToHex(bundle.getIdentityKey().getPublicKey().serialize()));
                            FetchStatus fetchStatus;
                            if (status != null && status.isVerified()) {
                                fetchStatus = FetchStatus.SUCCESS_VERIFIED;
                            } else if (status != null && status.isTrusted()) {
                                fetchStatus = FetchStatus.SUCCESS_TRUSTED;
                            } else {
                                fetchStatus = FetchStatus.SUCCESS;
                            }
                            fetchStatusMap.put(address, fetchStatus);
                            finishBuildingSessionsFromPEP(address);
                        }
                    } catch (UntrustedIdentityException | InvalidKeyException e) {
                        Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Error building session for " + address + ": " + e.getClass().getName() + ", " + e.getMessage());
                        fetchStatusMap.put(address, FetchStatus.ERROR);
                        finishBuildingSessionsFromPEP(address);
                    }
                } else {
                    fetchStatusMap.put(address, FetchStatus.ERROR);
                    Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while building session:" + packet.findChild("error"));
                    finishBuildingSessionsFromPEP(address);
                }
            }
        });
    } catch (InvalidJidException e) {
        Log.e(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Got address with invalid jid: " + address.getName());
    }
}
Also used : Account(de.pixart.messenger.entities.Account) IqParser(de.pixart.messenger.parser.IqParser) UntrustedIdentityException(org.whispersystems.libsignal.UntrustedIdentityException) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) SessionBuilder(org.whispersystems.libsignal.SessionBuilder) InvalidKeyException(org.whispersystems.libsignal.InvalidKeyException) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) PreKeyBundle(org.whispersystems.libsignal.state.PreKeyBundle) Random(java.util.Random)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6