use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class NotificationManager method onMessageNotification.
public void onMessageNotification(MessageItem messageItem) {
MessageNotification messageNotification = getMessageNotification(messageItem.getAccount(), messageItem.getUser());
if (messageNotification == null) {
messageNotification = new MessageNotification(messageItem.getAccount(), messageItem.getUser(), null, null, 0);
} else {
messageNotifications.remove(messageNotification);
}
messageNotification.addMessage(messageItem.getText());
messageNotifications.add(messageNotification);
final AccountJid account = messageNotification.getAccount();
final UserJid user = messageNotification.getUser();
final String text = messageNotification.getText();
final Date timestamp = messageNotification.getTimestamp();
final int count = messageNotification.getCount();
Application.getInstance().runInBackgroundUserRequest(new Runnable() {
@Override
public void run() {
NotificationTable.getInstance().write(account.toString(), user.toString(), text, timestamp, count);
}
});
updateMessageNotification(messageItem);
}
use of com.xabber.android.data.entity.AccountJid 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.AccountJid in project xabber-android by redsolution.
the class RosterManager method onContactsDeleted.
void onContactsDeleted(AccountJid account, Collection<Jid> addresses) {
Collection<RosterContact> removedContacts = new ArrayList<>(addresses.size());
for (Jid jid : addresses) {
RosterContact contact = rosterContacts.remove(account.toString(), jid.asBareJid().toString());
if (contact != null) {
removedContacts.add(contact);
}
}
onContactsChanged(removedContacts);
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class RosterManager method onContactsAdded.
void onContactsAdded(AccountJid account, Collection<Jid> addresses) {
final Roster roster = RosterManager.getInstance().getRoster(account);
Collection<RosterContact> newContacts = new ArrayList<>(addresses.size());
for (Jid jid : addresses) {
RosterEntry entry = roster.getEntry(jid.asBareJid());
try {
RosterContact contact = convertRosterEntryToRosterContact(account, roster, entry);
rosterContacts.put(account.toString(), contact.getUser().getBareJid().toString(), contact);
newContacts.add(contact);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(LOG_TAG, e);
}
}
onContactsChanged(newContacts);
}
use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.
the class XabberAccountManager method updateLocalAccount.
public void updateLocalAccount(XMPPAccountSettings account) {
// if account synced
if (isAccountSynchronize(account.getJid()) || SettingsManager.isSyncAllAccounts()) {
AccountJid accountJid = getExistingAccount(account.getJid());
// create new xmpp-account
if (accountJid == null && !account.isDeleted()) {
try {
AccountJid jid = AccountManager.getInstance().addAccount(account.getJid(), "", account.getToken(), false, true, true, false, false, true);
AccountManager.getInstance().setColor(jid, ColorManager.getInstance().convertColorNameToIndex(account.getColor()));
AccountManager.getInstance().setOrder(jid, account.getOrder());
AccountManager.getInstance().setTimestamp(jid, account.getTimestamp());
AccountManager.getInstance().onAccountChanged(jid);
} catch (NetworkException e) {
Application.getInstance().onError(e);
}
// update existing xmpp-account
// now we are updated only color of account
} else if (accountJid != null && !account.isDeleted()) {
AccountManager.getInstance().setOrder(accountJid, account.getOrder());
AccountManager.getInstance().setTimestamp(accountJid, account.getTimestamp());
AccountManager.getInstance().setColor(accountJid, ColorManager.getInstance().convertColorNameToIndex(account.getColor()));
AccountManager.getInstance().onAccountChanged(accountJid);
// delete existing account
} else if (accountJid != null && account.isDeleted()) {
AccountManager.getInstance().removeAccountWithoutSync(accountJid);
}
}
}
Aggregations