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