use of org.jivesoftware.smackx.chatstates.ChatState in project Smack by igniterealtime.
the class ChatStateExtensionProvider method parse.
@Override
public ChatStateExtension parse(XmlPullParser parser, int initialDepth) throws Exception {
String chatStateString = parser.getName();
ChatState state = ChatState.valueOf(chatStateString);
return new ChatStateExtension(state);
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class EligibleForChatMarkerFilter method accept.
/**
* From XEP-0333, Protocol Format: The Chat Marker MUST have an 'id' which is the 'id' of the
* message being marked.<br>
* In order to make Chat Markers works together with XEP-0085 as it said in
* 8.5 Interaction with Chat States, only messages with <tt>active</tt> chat
* state are accepted.
*
* @param message to be analyzed.
* @return true if the message contains a stanza Id.
* @see <a href="http://xmpp.org/extensions/xep-0333.html">XEP-0333: Chat Markers</a>
*/
@Override
public boolean accept(Stanza message) {
if (!message.hasStanzaIdSet()) {
return false;
}
if (super.accept(message)) {
ExtensionElement extension = message.getExtension(ChatStateManager.NAMESPACE);
String chatStateElementName = extension.getElementName();
ChatState state;
try {
state = ChatState.valueOf(chatStateElementName);
return (state == ChatState.active);
} catch (Exception ex) {
return false;
}
}
return true;
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class ChatStateManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
final Resourcepart resource = stanza.getFrom().getResourceOrNull();
if (resource == null) {
return;
}
final AccountJid account = ((AccountItem) connection).getAccount();
final UserJid bareUserJid;
try {
bareUserJid = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
if (stanza instanceof Presence) {
Presence presence = (Presence) stanza;
if (presence.getType() != Type.unavailable) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
supports.remove(account.toString(), bareUserJid.toString(), resource);
} else if (stanza instanceof Message) {
boolean support = false;
for (ExtensionElement extension : stanza.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareUserJid.getBareJid(), resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account.toString(), bareUserJid.toString(), resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account.toString(), bareUserJid.toString(), resource)) {
return;
}
chatStates.remove(account.toString(), bareUserJid.toString(), resource);
removeCallback(account, bareUserJid.getBareJid(), resource);
RosterManager.onChatStateChanged(account, bareUserJid);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account.toString(), bareUserJid.toString(), resource, runnable);
}
RosterManager.onChatStateChanged(account, bareUserJid);
support = true;
break;
}
Message message = (Message) stanza;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat) {
return;
}
if (support) {
supports.put(account.toString(), bareUserJid.toString(), resource, true);
} else if (supports.get(account.toString(), bareUserJid.toString(), resource) == null) {
// Disable only if there no information about support.
supports.put(account.toString(), bareUserJid.toString(), resource, false);
}
}
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class ChatStateManager method getChatState.
/**
* Returns best information chat state for specified bare address.
*
* @return <code>null</code> if there is no available information.
*/
public ChatState getChatState(AccountJid account, UserJid bareAddress) {
Map<Resourcepart, ChatState> map = chatStates.get(account.toString(), bareAddress.toString());
if (map == null) {
return null;
}
ChatState chatState = null;
for (ChatState check : map.values()) {
if (chatState == null || check.compareTo(chatState) < 0) {
chatState = check;
}
}
return chatState;
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class ChatStateManager method getChatState.
/**
* Returns best information chat state for specified bare address.
*
* @param account
* @param bareAddress
* @return <code>null</code> if there is no available information.
*/
public ChatState getChatState(String account, String bareAddress) {
Map<String, ChatState> map = chatStates.get(account, bareAddress);
if (map == null)
return null;
ChatState chatState = null;
for (ChatState check : map.values()) if (chatState == null || check.compareTo(chatState) < 0)
chatState = check;
return chatState;
}
Aggregations