use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method discardSubscription.
/**
* Discards subscription request from the entity (deny own presence
* sharing).
*
* @param account
* @param bareAddress
* @throws NetworkException
*/
public void discardSubscription(String account, String bareAddress) throws NetworkException {
Presence packet = new Presence(Presence.Type.unsubscribed);
packet.setTo(bareAddress);
ConnectionManager.getInstance().sendStanza(account, packet);
subscriptionRequestProvider.remove(account, bareAddress);
removeRequestedSubscription(account, bareAddress);
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method getStatusText.
public String getStatusText(String account, String bareAddress) {
final Occupant occupant = getOccupant(account, bareAddress);
if (occupant != null) {
return occupant.getStatusText();
}
final Presence presence = RosterManager.getInstance().getPresence(account, bareAddress);
if (presence == null) {
return null;
} else {
return presence.getStatus();
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method acceptSubscription.
/**
* Accepts subscription request from the entity (share own presence).
*
* @param account
* @param bareAddress
* @throws NetworkException
*/
public void acceptSubscription(String account, String bareAddress) throws NetworkException {
Presence packet = new Presence(Presence.Type.subscribed);
packet.setTo(bareAddress);
ConnectionManager.getInstance().sendStanza(account, packet);
subscriptionRequestProvider.remove(account, bareAddress);
removeRequestedSubscription(account, bareAddress);
}
use of org.jivesoftware.smack.packet.Presence 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.smack.packet.Presence in project xabber-android by redsolution.
the class AvatarManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(packet instanceof Presence) || bareAddress == null) {
return;
}
if (!(connection instanceof AccountItem)) {
return;
}
String account = ((AccountItem) connection).getAccount();
Presence presence = (Presence) packet;
if (presence.getType() == Presence.Type.error) {
return;
}
for (ExtensionElement packetExtension : presence.getExtensions()) {
if (packetExtension instanceof VCardUpdate) {
VCardUpdate vCardUpdate = (VCardUpdate) packetExtension;
if (vCardUpdate.isValid() && vCardUpdate.isPhotoReady()) {
onPhotoReady(account, bareAddress, vCardUpdate);
}
}
}
}
Aggregations