Search in sources :

Example 31 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class XMPPAuthManager method addContactToRoster.

private void addContactToRoster(String apiJid, String clientJid) {
    UserJid user;
    AccountJid account;
    try {
        user = UserJid.from(apiJid);
        account = AccountJid.from(clientJid);
        RosterManager.getInstance().createContact(account, user, "xabber", Collections.EMPTY_LIST);
        PresenceManager.getInstance().requestSubscription(account, user, false);
    } catch (UserJid.UserJidCreateException | XmppStringprepException | InterruptedException | SmackException | NetworkException | XMPPException.XMPPErrorException e) {
        LogManager.exception(this, e);
        return;
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) SmackException(org.jivesoftware.smack.SmackException) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) NetworkException(com.xabber.android.data.NetworkException)

Example 32 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class ReceiptManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
    if (!(connection instanceof AccountItem)) {
        return;
    }
    final AccountJid account = ((AccountItem) connection).getAccount();
    final Jid from = packet.getFrom();
    if (from == null) {
        return;
    }
    if (!(packet instanceof Message)) {
        return;
    }
    final Message message = (Message) packet;
    if (message.getType() == Message.Type.error) {
        Application.getInstance().runInBackgroundUserRequest(new Runnable() {

            @Override
            public void run() {
                markAsError(account, message);
            }
        });
    } else {
        // TODO setDefaultAutoReceiptMode should be used
        for (ExtensionElement packetExtension : message.getExtensions()) {
            if (packetExtension instanceof DeliveryReceiptRequest) {
                String id = AbstractChat.getStanzaId(message);
                if (id == null) {
                    continue;
                }
                Message receipt = new Message(from);
                receipt.addExtension(new DeliveryReceipt(id));
                // the key problem is Thread - smack does not keep it in auto reply
                receipt.setThread(message.getThread());
                receipt.setType(Message.Type.chat);
                try {
                    StanzaSender.sendStanza(account, receipt);
                } catch (NetworkException e) {
                    LogManager.exception(this, e);
                }
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) DeliveryReceiptRequest(org.jivesoftware.smackx.receipts.DeliveryReceiptRequest) AccountJid(com.xabber.android.data.entity.AccountJid) DeliveryReceipt(org.jivesoftware.smackx.receipts.DeliveryReceipt) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) NetworkException(com.xabber.android.data.NetworkException)

Example 33 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class QuestionViewer method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (isFinishing()) {
        return;
    }
    Intent intent = getIntent();
    account = QuestionViewer.getAccount(intent);
    user = QuestionViewer.getUser(intent);
    if (AccountManager.getInstance().getAccount(account) == null || user == null) {
        Application.getInstance().onError(R.string.ENTRY_IS_NOT_FOUND);
        finish();
        return;
    }
    if (intent.getBooleanExtra(EXTRA_FIELD_CANCEL, false)) {
        try {
            OTRManager.getInstance().abortSmp(account, user);
        } catch (NetworkException e) {
            Application.getInstance().onError(e);
        }
        finish();
        return;
    }
    showQuestion = intent.getBooleanExtra(EXTRA_FIELD_SHOW_QUESTION, true);
    answerRequest = intent.getBooleanExtra(EXTRA_FIELD_ANSWER_REQUEST, false);
    if (showQuestion) {
        setContentView(R.layout.question_viewer);
        questionView = (EditText) findViewById(R.id.question);
        questionView.setEnabled(!answerRequest);
        if (answerRequest) {
            questionView.setText(intent.getStringExtra(Intent.EXTRA_TEXT));
        } else {
            findViewById(R.id.cancel).setVisibility(View.GONE);
        }
    } else {
        setContentView(R.layout.secret_viewer);
    }
    findViewById(R.id.cancel).setOnClickListener(this);
    findViewById(R.id.send).setOnClickListener(this);
    contactTitleActionBarInflater = new ContactTitleActionBarInflater(this, (Toolbar) findViewById(R.id.toolbar_default));
    contactTitleActionBarInflater.setUpActionBarView();
}
Also used : ContactTitleActionBarInflater(com.xabber.android.ui.helper.ContactTitleActionBarInflater) Intent(android.content.Intent) NetworkException(com.xabber.android.data.NetworkException) Toolbar(android.support.v7.widget.Toolbar)

Example 34 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class SSNManager method sendFeature.

private void sendFeature(String account, String user, String session, Feature feature) {
    Message message = new Message(user, Message.Type.normal);
    message.setThread(session);
    message.addExtension(feature);
    try {
        ConnectionManager.getInstance().sendStanza(account, message);
    } catch (NetworkException e) {
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) NetworkException(com.xabber.android.data.NetworkException)

Example 35 with NetworkException

use of com.xabber.android.data.NetworkException in project xabber-android by redsolution.

the class TimeManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    String account = ((AccountItem) connection).getAccount();
    if (!(packet instanceof Time))
        return;
    Time time = (Time) packet;
    if (time.getType() == Type.get) {
        Time result = new Time();
        result.setType(Type.result);
        result.setPacketID(time.getPacketID());
        result.setFrom(time.getTo());
        result.setTo(time.getFrom());
        Calendar calendar = Calendar.getInstance();
        result.setTzo((calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000);
        result.setUtc(calendar.getTime());
        try {
            ConnectionManager.getInstance().sendStanza(account, result);
        } catch (NetworkException e) {
        }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Calendar(java.util.Calendar) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException)

Aggregations

NetworkException (com.xabber.android.data.NetworkException)64 Message (org.jivesoftware.smack.packet.Message)13 AccountJid (com.xabber.android.data.entity.AccountJid)11 OtrException (net.java.otr4j.OtrException)11 AccountItem (com.xabber.android.data.account.AccountItem)10 AbstractChat (com.xabber.android.data.message.AbstractChat)10 OnResponseListener (com.xabber.android.data.connection.OnResponseListener)6 Date (java.util.Date)6 IQ (org.jivesoftware.smack.packet.IQ)6 UserJid (com.xabber.android.data.entity.UserJid)5 ArrayList (java.util.ArrayList)4 Presence (org.jivesoftware.smack.packet.Presence)4 Intent (android.content.Intent)3 Set (com.xabber.xmpp.rsm.Set)3 File (java.io.File)3 SmackException (org.jivesoftware.smack.SmackException)3 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 Captcha (com.xabber.android.data.extension.captcha.Captcha)2 RoomChat (com.xabber.android.data.extension.muc.RoomChat)2