use of com.xabber.android.data.entity.UserJid 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.entity.UserJid in project xabber-android by redsolution.
the class PresenceManager method onPresenceChanged.
public void onPresenceChanged(AccountJid account, Presence presence) {
UserJid from;
try {
from = UserJid.from(presence.getFrom());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
if (presence.isAvailable()) {
CapabilitiesManager.getInstance().onPresence(account, presence);
}
if (presence.getType() == Presence.Type.unavailable)
LastActivityInteractor.getInstance().setLastActivityTimeNow(account, from.getBareUserJid());
for (OnStatusChangeListener listener : Application.getInstance().getManagers(OnStatusChangeListener.class)) {
listener.onStatusChanged(account, from, StatusMode.createStatusMode(presence), presence.getStatus());
}
RosterContact rosterContact = RosterManager.getInstance().getRosterContact(account, from.getBareJid());
if (rosterContact != null) {
ArrayList<RosterContact> rosterContacts = new ArrayList<>();
rosterContacts.add(rosterContact);
for (OnRosterChangedListener listener : Application.getInstance().getManagers(OnRosterChangedListener.class)) {
listener.onPresenceChanged(rosterContacts);
}
}
RosterManager.onContactChanged(account, from);
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class OccupantListActivity method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
com.xabber.android.data.extension.muc.Occupant occupant = (com.xabber.android.data.extension.muc.Occupant) listAdapter.getItem(position);
LogManager.i(this, occupant.getNickname().toString());
UserJid occupantFullJid = null;
try {
occupantFullJid = UserJid.from(JidCreate.entityFullFrom(room, occupant.getNickname()));
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
final AbstractChat mucPrivateChat;
try {
mucPrivateChat = MessageManager.getInstance().getOrCreatePrivateMucChat(account, occupantFullJid.getJid().asFullJidIfPossible());
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
return;
}
mucPrivateChat.setIsPrivateMucChatAccepted(true);
startActivity(ChatActivity.createSpecificChatIntent(this, account, occupantFullJid));
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class BlockingManager method onAuthorized.
public void onAuthorized(final ConnectionItem connection) {
final AccountJid account = connection.getAccount();
BlockingCommandManager blockingCommandManager = BlockingCommandManager.getInstanceFor(connection.getConnection());
try {
boolean supportedByServer = blockingCommandManager.isSupportedByServer();
if (supportedByServer) {
// cache block list inside
List<UserJid> blockedContacts = new ArrayList<>();
try {
List<Jid> blockedJids = blockingCommandManager.getBlockList();
for (Jid jid : blockedJids) {
blockedContacts.add(UserJid.from(jid));
}
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
LogManager.exception(LOG_TAG, e);
}
// Cache block inside manager
// For contact list building used only this list of blocked contacts
updateCachedBlockedContacts(account, blockedContacts);
}
addBlockedListener(blockingCommandManager, account);
addUnblockedListener(blockingCommandManager, account);
addUnblockedAllListener(blockingCommandManager, account);
// block list already cached successfully
supportForAccounts.put(account, supportedByServer);
BlockingManager.notify(account);
} catch (SmackException.NotConnectedException | XMPPException.XMPPErrorException | SmackException.NoResponseException | InterruptedException e) {
LogManager.exception(this, e);
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class BlockingManager method getBlockedContacts.
public List<UserJid> getBlockedContacts(AccountJid account) {
List<UserJid> blockedContacts = new ArrayList<>();
Boolean supported = isSupported(account);
BlockingCommandManager blockingCommandManager = getBlockingCommandManager(account);
if (blockingCommandManager != null && supported != null && supported) {
try {
List<Jid> blockedJids = blockingCommandManager.getBlockList();
for (Jid jid : blockedJids) {
blockedContacts.add(UserJid.from(jid));
}
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException | SmackException.NotConnectedException | UserJid.UserJidCreateException e) {
LogManager.exception(LOG_TAG, e);
}
}
updateCachedBlockedContacts(account, blockedContacts);
return blockedContacts;
}
Aggregations