use of com.xabber.android.data.account.AccountItem 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);
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class PresenceManager method sendVCardUpdatePresence.
public void sendVCardUpdatePresence(AccountJid account, String hash) throws NetworkException {
LogManager.i(this, "sendVCardUpdatePresence: " + account);
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return;
}
final Presence presence = accountItem.getPresence();
final VCardUpdate vCardUpdate = new VCardUpdate();
vCardUpdate.setPhotoHash(hash);
presence.addExtension(vCardUpdate);
StanzaSender.sendStanza(account, presence);
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class PushManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza packet) {
if (packet instanceof IQ && ((IQ) packet).getType() != IQ.Type.error) {
if (waitingIQs.containsKey(packet.getStanzaId())) {
AccountJid account = connection.getAccount();
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
Boolean enable = waitingIQs.get(packet.getStanzaId());
if (accountItem != null && enable != null) {
AccountManager.getInstance().setPushWasEnabled(accountItem, enable);
}
waitingIQs.remove(packet.getStanzaId());
}
}
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class PushManager method updateEnabledPushNodes.
public void updateEnabledPushNodes() {
StringBuilder stringBuilder = new StringBuilder();
for (AccountItem accountItem : AccountManager.getInstance().getAllAccountItems()) {
String node = accountItem.getPushNode();
if (accountItem.isEnabled() && accountItem.isPushEnabled() && accountItem.isPushWasEnabled() && node != null && !node.isEmpty()) {
stringBuilder.append(node);
stringBuilder.append(" ");
}
}
SettingsManager.setEnabledPushNodes(stringBuilder.toString());
}
use of com.xabber.android.data.account.AccountItem in project xabber-android by redsolution.
the class AccountVO method convert.
public static AccountVO convert(AccountConfiguration configuration, AccountClickListener listener) {
String jid;
String name;
String status;
int statusLevel;
int statusId;
Drawable avatar;
int offlineModeLevel;
int accountColorIndicator;
int accountColorIndicatorBack;
String contactCount;
AccountJid account = configuration.getAccount();
accountColorIndicator = ColorManager.getInstance().getAccountPainter().getAccountMainColor(account);
accountColorIndicatorBack = ColorManager.getInstance().getAccountPainter().getAccountIndicatorBackColor(account);
jid = GroupManager.getInstance().getGroupName(account, configuration.getGroup());
name = AccountManager.getInstance().getNickName(account);
contactCount = configuration.getOnline() + "/" + configuration.getTotal();
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
status = accountItem.getStatusText().trim();
statusId = accountItem.getDisplayStatusMode().getStringID();
avatar = AvatarManager.getInstance().getAccountAvatar(account);
statusLevel = accountItem.getDisplayStatusMode().getStatusLevel();
ShowOfflineMode showOfflineMode = configuration.getShowOfflineMode();
if (showOfflineMode == ShowOfflineMode.normal) {
if (SettingsManager.contactsShowOffline()) {
showOfflineMode = ShowOfflineMode.always;
} else {
showOfflineMode = ShowOfflineMode.never;
}
}
offlineModeLevel = showOfflineMode.ordinal();
// custom notification
boolean isCustomNotification = CustomNotifyPrefsManager.getInstance().isPrefsExist(Key.createKey(account));
return new AccountVO(accountColorIndicator, accountColorIndicatorBack, name, jid, status, statusLevel, statusId, avatar, offlineModeLevel, contactCount, configuration.getAccount(), configuration.isExpanded(), configuration.getGroup(), isCustomNotification, listener);
}
Aggregations