Search in sources :

Example 41 with Jid

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

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 42 with Jid

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

the class PushManagementService method registerPushTokenOnServer.

public void registerPushTokenOnServer(final Account account) {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": has push support");
    retrieveGcmInstanceToken(new OnGcmInstanceTokenRetrieved() {

        @Override
        public void onGcmInstanceTokenRetrieved(String token) {
            try {
                final String deviceId = Settings.Secure.getString(mXmppConnectionService.getContentResolver(), Settings.Secure.ANDROID_ID);
                IqPacket packet = mXmppConnectionService.getIqGenerator().pushTokenToAppServer(Jid.fromString(APP_SERVER), token, deviceId);
                mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        Element command = packet.findChild("command", "http://jabber.org/protocol/commands");
                        if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
                            Element x = command.findChild("x", Namespace.DATA);
                            if (x != null) {
                                Data data = Data.parse(x);
                                try {
                                    String node = data.getValue("node");
                                    String secret = data.getValue("secret");
                                    Jid jid = Jid.fromString(data.getValue("jid"));
                                    if (node != null && secret != null) {
                                        enablePushOnServer(account, jid, node, secret);
                                    }
                                } catch (InvalidJidException e) {
                                    e.printStackTrace();
                                }
                            }
                        } else {
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": invalid response from app server");
                        }
                    }
                });
            } catch (InvalidJidException ignored) {
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Data(de.pixart.messenger.xmpp.forms.Data) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 43 with Jid

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

the class XmppConnectionService method sendBlockRequest.

public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
    if (blockable != null && blockable.getBlockedJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().add(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
                }
            }
        });
        if (removeBlockedConversations(blockable.getAccount(), jid)) {
            updateConversationUi();
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 44 with Jid

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

the class ShareViaAccountActivity method onBackendConnected.

@Override
void onBackendConnected() {
    final int numAccounts = xmppConnectionService.getAccounts().size();
    if (numAccounts == 1) {
        final String body = getIntent().getStringExtra(EXTRA_BODY);
        final Account account = xmppConnectionService.getAccounts().get(0);
        try {
            final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
            switchToConversation(conversation, body, false);
        } catch (InvalidJidException e) {
        // ignore error
        }
        finish();
    } else {
        refreshUiReal();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation)

Example 45 with Jid

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

the class StartConversationActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (resultCode == RESULT_OK) {
        if (xmppConnectionServiceBound) {
            this.mPostponedActivityResult = null;
            if (requestCode == REQUEST_CREATE_CONFERENCE) {
                Account account = extractAccount(intent);
                final String subject = intent.getStringExtra("subject");
                List<Jid> jids = new ArrayList<>();
                if (intent.getBooleanExtra("multiple", false)) {
                    String[] toAdd = intent.getStringArrayExtra("contacts");
                    for (String item : toAdd) {
                        try {
                            jids.add(Jid.fromString(item));
                        } catch (InvalidJidException e) {
                        // ignored
                        }
                    }
                } else {
                    try {
                        jids.add(Jid.fromString(intent.getStringExtra("contact")));
                    } catch (Exception e) {
                    // ignored
                    }
                }
                if (account != null && jids.size() > 0) {
                    if (xmppConnectionService.createAdhocConference(account, subject, jids, mAdhocConferenceCallback)) {
                        mToast = Toast.makeText(this, R.string.creating_conference, Toast.LENGTH_LONG);
                        mToast.show();
                    }
                }
            }
        } else {
            this.mPostponedActivityResult = new Pair<>(requestCode, intent);
        }
    }
    super.onActivityResult(requestCode, requestCode, intent);
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) ActivityNotFoundException(android.content.ActivityNotFoundException) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

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