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);
}
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);
}
}
}
Aggregations