Search in sources :

Example 11 with AccountItem

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

the class AttentionManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    if (!(packet instanceof Message))
        return;
    if (!SettingsManager.chatsAttention())
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (bareAddress == null)
        return;
    for (ExtensionElement packetExtension : packet.getExtensions()) {
        if (packetExtension instanceof Attention) {
            MessageManager.getInstance().openChat(account, bareAddress);
            MessageManager.getInstance().getOrCreateChat(account, bareAddress).newAction(null, null, ChatAction.attention_requested);
            attentionRequestProvider.add(new AttentionRequest(account, bareAddress), true);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) Attention(com.xabber.xmpp.attention.Attention) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement)

Example 12 with AccountItem

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

the class PingManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    if (!(connection instanceof AccountItem))
        return;
    final String account = ((AccountItem) connection).getAccount();
    if (!(packet instanceof Ping))
        return;
    final Ping ping = (Ping) packet;
    if (ping.getType() != IQ.Type.get)
        return;
    try {
        ConnectionManager.getInstance().sendStanza(account, IQ.createResultIQ(ping));
    } catch (NetworkException e) {
        LogManager.exception(this, e);
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Ping(org.jivesoftware.smackx.ping.packet.Ping) NetworkException(com.xabber.android.data.NetworkException)

Example 13 with AccountItem

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

the class SSNManager method onPacket.

@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
    String from = packet.getFrom();
    if (from == null)
        return;
    if (!(connection instanceof AccountItem) || !(packet instanceof Message))
        return;
    String account = ((AccountItem) connection).getAccount();
    Message message = (Message) packet;
    String session = message.getThread();
    if (session == null)
        return;
    for (ExtensionElement packetExtension : packet.getExtensions()) if (packetExtension instanceof Feature) {
        Feature feature = (Feature) packetExtension;
        if (!feature.isValid())
            continue;
        DataFormType type = feature.getDataFormType();
        if (type == DataFormType.form)
            onFormReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.submit)
            onSubmitReceived(account, from, bareAddress, session, feature);
        else if (type == DataFormType.result)
            onResultReceived(account, from, bareAddress, session, feature);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataFormType(com.xabber.xmpp.form.DataFormType) Feature(com.xabber.xmpp.ssn.Feature)

Example 14 with AccountItem

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

the class ClientStateManager method sendClientState.

protected static void sendClientState(PlainStreamElement element) {
    AccountManager accountManager = AccountManager.getInstance();
    for (String accountName : accountManager.getAccounts()) {
        AccountItem account = accountManager.getAccount(accountName);
        if (account == null) {
            continue;
        }
        ConnectionThread connectionThread = account.getConnectionThread();
        if (connectionThread == null) {
            continue;
        }
        AbstractXMPPConnection xmppConnection = connectionThread.getXMPPConnection();
        if (xmppConnection == null) {
            continue;
        }
        if (xmppConnection.hasFeature("csi", ClientStateIndication.NAMESPACE))
            try {
                xmppConnection.send(element);
            } catch (SmackException.NotConnectedException e) {
            // not connected
            }
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) ConnectionThread(com.xabber.android.data.connection.ConnectionThread) AccountManager(com.xabber.android.data.account.AccountManager) AbstractXMPPConnection(org.jivesoftware.smack.AbstractXMPPConnection)

Example 15 with AccountItem

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

the class TimeManager method onServerInfoReceived.

@Override
public void onServerInfoReceived(ConnectionItem connection) {
    if (!(connection instanceof AccountItem)) {
        onAvailable(connection);
        return;
    }
    String account = ((AccountItem) connection).getAccount();
    if (ServerInfoManager.getInstance().isProtocolSupported(account, FEATURE) && offsets.get(account) == null) {
        sents.put(account, new Date());
        Time packet = new Time();
        packet.setTo(Jid.getServer(account));
        packet.setType(Type.get);
        try {
            ConnectionManager.getInstance().sendRequest(account, packet, this);
        } catch (NetworkException e) {
        }
        return;
    }
    onAvailable(connection);
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) Time(com.xabber.xmpp.time.Time) NetworkException(com.xabber.android.data.NetworkException) Date(java.util.Date)

Aggregations

AccountItem (com.xabber.android.data.account.AccountItem)96 AccountJid (com.xabber.android.data.entity.AccountJid)24 UserJid (com.xabber.android.data.entity.UserJid)14 View (android.view.View)12 NetworkException (com.xabber.android.data.NetworkException)11 ArrayList (java.util.ArrayList)11 SmackException (org.jivesoftware.smack.SmackException)11 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)11 Message (org.jivesoftware.smack.packet.Message)11 Presence (org.jivesoftware.smack.packet.Presence)10 TextView (android.widget.TextView)9 XMPPException (org.jivesoftware.smack.XMPPException)9 Jid (org.jxmpp.jid.Jid)9 ImageView (android.widget.ImageView)8 StatusMode (com.xabber.android.data.account.StatusMode)6 ConnectionState (com.xabber.android.data.connection.ConnectionState)5 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)5 Realm (io.realm.Realm)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 AccountManager (com.xabber.android.data.account.AccountManager)4