Search in sources :

Example 1 with AttentionExtension

use of org.jivesoftware.smackx.attention.packet.AttentionExtension in project xabber-android by redsolution.

the class AttentionManager method sendAttention.

public void sendAttention(AccountJid account, UserJid user) throws NetworkException {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
    if (!(chat instanceof RegularChat)) {
        throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
    }
    Jid to = chat.getTo();
    if (to.getResourceOrNull() == null || to.getResourceOrNull().equals(Resourcepart.EMPTY)) {
        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);
    }
    if (!CapabilitiesManager.getInstance().isFeatureSupported(to, AttentionExtension.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 AttentionExtension());
    StanzaSender.sendStanza(account, message);
    chat.newAction(null, null, ChatAction.attention_called);
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) AccountJid(com.xabber.android.data.entity.AccountJid) Jid(org.jxmpp.jid.Jid) Message(org.jivesoftware.smack.packet.Message) AbstractChat(com.xabber.android.data.message.AbstractChat) Presence(org.jivesoftware.smack.packet.Presence) NetworkException(com.xabber.android.data.NetworkException) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension) RegularChat(com.xabber.android.data.message.RegularChat)

Example 2 with AttentionExtension

use of org.jivesoftware.smackx.attention.packet.AttentionExtension in project xabber-android by redsolution.

the class AttentionManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    if (!(stanza instanceof Message)) {
        return;
    }
    if (!SettingsManager.chatsAttention()) {
        return;
    }
    final AccountJid account = connection.getAccount();
    UserJid from;
    try {
        from = UserJid.from(stanza.getFrom());
    } catch (UserJid.UserJidCreateException e) {
        e.printStackTrace();
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof AttentionExtension) {
            MessageManager.getInstance().openChat(account, from);
            MessageManager.getInstance().getOrCreateChat(account, from).newAction(null, null, ChatAction.attention_requested);
            attentionRequestProvider.add(new AttentionRequest(account, from.getBareUserJid()), true);
        }
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) AttentionExtension(org.jivesoftware.smackx.attention.packet.AttentionExtension)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)2 UserJid (com.xabber.android.data.entity.UserJid)2 Message (org.jivesoftware.smack.packet.Message)2 AttentionExtension (org.jivesoftware.smackx.attention.packet.AttentionExtension)2 NetworkException (com.xabber.android.data.NetworkException)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 Jid (org.jxmpp.jid.Jid)1