use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class AbstractContact method getClientSoftware.
public ClientSoftware getClientSoftware() {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null || !presence.isAvailable()) {
return ClientSoftware.unknown;
}
ClientInfo clientInfo = CapabilitiesManager.getInstance().getCachedClientInfo(presence.getFrom());
if (clientInfo == null) {
return ClientSoftware.unknown;
} else {
return clientInfo.getClientSoftware();
}
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method requestSubscription.
/**
* Requests subscription to the contact.
*
* @throws NetworkException
*/
public void requestSubscription(AccountJid account, UserJid user) throws NetworkException {
Presence packet = new Presence(Presence.Type.subscribe);
packet.setTo(user.getJid());
StanzaSender.sendStanza(account, packet);
Set<UserJid> set = requestedSubscriptions.get(account);
if (set == null) {
set = new HashSet<>();
requestedSubscriptions.put(account, set);
}
set.add(user);
}
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).
*/
public void acceptSubscription(AccountJid account, UserJid user) throws NetworkException {
Presence packet = new Presence(Presence.Type.subscribed);
packet.setTo(user.getJid());
StanzaSender.sendStanza(account, packet);
subscriptionRequestProvider.remove(account, user);
removeRequestedSubscription(account, user);
}
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).
*/
public void discardSubscription(AccountJid account, UserJid user) throws NetworkException {
Presence packet = new Presence(Presence.Type.unsubscribed);
packet.setTo(user.getJid());
StanzaSender.sendStanza(account, packet);
subscriptionRequestProvider.remove(account, user);
removeRequestedSubscription(account, user);
}
use of org.jivesoftware.smack.packet.Presence in project xabber-android by redsolution.
the class PresenceManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (!(connection instanceof AccountItem)) {
return;
}
if (!(stanza instanceof Presence)) {
return;
}
Presence presence = (Presence) stanza;
UserJid from;
try {
from = UserJid.from(stanza.getFrom());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
if (presence.getType() == Presence.Type.subscribe) {
AccountJid account = connection.getAccount();
// reject all subscribe-requests
if (SettingsManager.spamFilterMode() == SettingsManager.SpamFilterMode.noAuth) {
// send a warning message to sender
MessageManager.getInstance().sendMessageWithoutChat(from.getJid(), StringUtils.randomString(12), account, Application.getInstance().getResources().getString(R.string.spam_filter_ban_subscription));
// and discard subscription
try {
discardSubscription(account, UserJid.from(from.toString()));
} catch (NetworkException | UserJid.UserJidCreateException e) {
e.printStackTrace();
}
return;
}
// require captcha for subscription
if (SettingsManager.spamFilterMode() == SettingsManager.SpamFilterMode.authCaptcha) {
Captcha captcha = CaptchaManager.getInstance().getCaptcha(account, from);
// if captcha for this user already exist, check expires time and discard if need
if (captcha != null) {
if (captcha.getExpiresDate() < System.currentTimeMillis()) {
// discard subscription
try {
discardSubscription(account, UserJid.from(from.toString()));
} catch (NetworkException | UserJid.UserJidCreateException e) {
e.printStackTrace();
}
return;
}
// skip subscription, waiting for captcha in messageManager
return;
} else {
// generate captcha
String captchaQuestion = CaptchaManager.getInstance().generateAndSaveCaptcha(account, from);
// send captcha message to sender
MessageManager.getInstance().sendMessageWithoutChat(from.getJid(), StringUtils.randomString(12), account, Application.getInstance().getResources().getString(R.string.spam_filter_limit_subscription) + " " + captchaQuestion);
// and skip subscription, waiting for captcha in messageManager
return;
}
}
// subscription request
handleSubscriptionRequest(account, from);
}
}
Aggregations