use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class ChatStateManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, final String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem))
return;
final String resource = Jid.getResource(packet.getFrom());
if (resource == null)
return;
final String account = ((AccountItem) connection).getAccount();
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
if (presence.getType() != Type.unavailable)
return;
chatStates.remove(account, bareAddress, resource);
removeCallback(account, bareAddress, resource);
supports.remove(account, bareAddress, resource);
} else if (packet instanceof Message) {
boolean support = false;
for (ExtensionElement extension : packet.getExtensions()) if (extension instanceof ChatStateExtension) {
removeCallback(account, bareAddress, resource);
ChatState chatState = ((ChatStateExtension) extension).getChatState();
chatStates.put(account, bareAddress, resource, chatState);
if (chatState != ChatState.active) {
Runnable runnable = new Runnable() {
@Override
public void run() {
if (this != stateCleaners.get(account, bareAddress, resource))
return;
chatStates.remove(account, bareAddress, resource);
removeCallback(account, bareAddress, resource);
RosterManager.getInstance().onContactChanged(account, bareAddress);
}
};
handler.postDelayed(runnable, REMOVE_STATE_DELAY);
stateCleaners.put(account, bareAddress, resource, runnable);
}
RosterManager.getInstance().onContactChanged(account, bareAddress);
support = true;
break;
}
Message message = (Message) packet;
if (message.getType() != Message.Type.chat && message.getType() != Message.Type.groupchat)
return;
if (support)
supports.put(account, bareAddress, resource, true);
else if (supports.get(account, bareAddress, resource) == null)
// Disable only if there no information about support.
supports.put(account, bareAddress, resource, false);
}
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class ContactTitleInflater method setStatus.
private static void setStatus(Context context, View titleView, AbstractContact abstractContact) {
final ImageView statusModeView = (ImageView) titleView.findViewById(R.id.ivStatus);
int statusLevel = abstractContact.getStatusMode().getStatusLevel();
statusModeView.setVisibility(View.GONE);
if (isContactOffline(statusLevel)) {
statusModeView.setVisibility(View.GONE);
} else {
statusModeView.setVisibility(View.VISIBLE);
statusModeView.setImageLevel(statusLevel);
}
final TextView statusTextView = (TextView) titleView.findViewById(R.id.status_text);
ChatState chatState = ChatStateManager.getInstance().getChatState(abstractContact.getAccount(), abstractContact.getUser());
CharSequence statusText;
if (chatState == ChatState.composing) {
statusText = context.getString(R.string.chat_state_composing);
} else if (chatState == ChatState.paused) {
statusText = context.getString(R.string.chat_state_paused);
} else {
statusText = abstractContact.getStatusText().trim();
if (statusText.toString().isEmpty()) {
statusText = context.getString(abstractContact.getStatusMode().getStringID());
}
}
statusTextView.setText(statusText);
}
use of org.jivesoftware.smackx.chatstates.ChatState in project xabber-android by redsolution.
the class NewContactTitleInflater method setStatus.
private static void setStatus(Context context, View titleView, AbstractContact abstractContact) {
final ImageView statusModeView = (ImageView) titleView.findViewById(R.id.ivStatus);
final ImageView groupchatStatusView = (ImageView) titleView.findViewById(R.id.ivStatusGroupchat);
boolean isGroupchat = false;
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(abstractContact.getAccount(), abstractContact.getUser());
if (chat != null)
isGroupchat = chat.isGroupchat();
int statusLevel = abstractContact.getStatusMode().getStatusLevel();
statusModeView.setVisibility(View.GONE);
if (isContactOffline(statusLevel)) {
statusModeView.setVisibility(View.GONE);
groupchatStatusView.setVisibility(View.GONE);
} else {
if (isGroupchat) {
statusModeView.setVisibility(View.GONE);
groupchatStatusView.setVisibility(View.VISIBLE);
} else {
statusModeView.setVisibility(View.VISIBLE);
statusModeView.setImageLevel(statusLevel);
groupchatStatusView.setVisibility(View.GONE);
}
}
final TextView statusTextView = (TextView) titleView.findViewById(R.id.status_text);
ChatState chatState = ChatStateManager.getInstance().getChatState(abstractContact.getAccount(), abstractContact.getUser());
CharSequence statusText;
if (chatState == ChatState.composing) {
statusText = context.getString(R.string.chat_state_composing);
} else if (chatState == ChatState.paused) {
statusText = context.getString(R.string.chat_state_paused);
} else {
if (StatusMode.unavailable == abstractContact.getStatusMode())
statusText = getLastActivity(abstractContact);
else
statusText = abstractContact.getStatusText().trim();
if (statusText.toString().isEmpty())
statusText = context.getString(abstractContact.getStatusMode().getStringID());
}
statusTextView.setText(statusText);
}
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, XmlEnvironment xmlEnvironment) {
String chatStateString = parser.getName();
ChatState state = ChatState.valueOf(chatStateString);
return new ChatStateExtension(state);
}
use of org.jivesoftware.smackx.chatstates.ChatState in project Smack by igniterealtime.
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 <code>active</code> 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)) {
XmlElement 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;
}
Aggregations