Search in sources :

Example 1 with Attention

use of com.xabber.xmpp.attention.Attention in project xabber-android by redsolution.

the class AttentionManager method sendAttention.

public void sendAttention(String account, String user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    String to = chat.getTo();
    if (Jid.getResource(to) == null || "".equals(Jid.getResource(to))) {
        final Presence presence = RosterManager.getInstance().getPresence(account, user);
        if (presence == null) {
            to = null;
        } else {
            to = presence.getFrom();
        }
    }
    if (to == null) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    }
    ClientInfo clientInfo = CapabilitiesManager.getInstance().getClientInfo(account, to);
    if (clientInfo == null)
        throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
    if (!clientInfo.getFeatures().contains(Attention.NAMESPACE))
        throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
    Message message = new Message();
    message.setTo(to);
    message.setType(Message.Type.headline);
    message.addExtension(new Attention());
    ConnectionManager.getInstance().sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called);
}
Also used : Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Attention(com.xabber.xmpp.attention.Attention) Presence(org.jivesoftware.smack.packet.Presence) ClientInfo(com.xabber.android.data.extension.capability.ClientInfo) NetworkException(com.xabber.android.data.NetworkException) RegularChat(com.xabber.android.data.message.RegularChat)

Example 2 with Attention

use of com.xabber.xmpp.attention.Attention 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)

Aggregations

Attention (com.xabber.xmpp.attention.Attention)2 Message (org.jivesoftware.smack.packet.Message)2 NetworkException (com.xabber.android.data.NetworkException)1 AccountItem (com.xabber.android.data.account.AccountItem)1 ClientInfo (com.xabber.android.data.extension.capability.ClientInfo)1 AbstractChat (com.xabber.android.data.message.AbstractChat)1 RegularChat (com.xabber.android.data.message.RegularChat)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 Presence (org.jivesoftware.smack.packet.Presence)1