use of com.xabber.android.data.message.chat.MucPrivateChatNotification in project xabber-android by redsolution.
the class MessageManager method onPacket.
@Override
public void onPacket(ConnectionItem connection, String bareAddress, Stanza packet) {
if (!(connection instanceof AccountItem)) {
return;
}
String account = ((AccountItem) connection).getAccount();
if (bareAddress == null) {
return;
}
if (packet instanceof Message && MessageArchiveManager.getInstance().isModificationsSucceed(account) && Delay.isOfflineMessage(Jid.getServer(account), packet)) {
// archive have been received.
return;
}
String contact = bareAddress;
if (packet instanceof Message) {
Message message = (Message) packet;
if (MUCManager.getInstance().hasRoom(account, bareAddress) && message.getType() != Message.Type.groupchat) {
contact = packet.getFrom();
}
}
final String user = packet.getFrom();
boolean processed = false;
for (AbstractChat chat : chats.getNested(account).values()) {
if (chat.onPacket(contact, packet)) {
processed = true;
break;
}
}
final AbstractChat chat = getChat(account, user);
if (chat != null && packet instanceof Message) {
if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(chat.getUser())) {
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
}
}
}
return;
}
if (!processed && packet instanceof Message) {
final Message message = (Message) packet;
final String body = message.getBody();
if (body == null) {
return;
}
if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, Jid.getBareAddress(user))) {
createPrivateMucChat(account, user).onPacket(contact, packet);
if (!PrivateMucChatBlockingManager.getInstance().getBlockedContacts(account).contains(user)) {
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
}
return;
}
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof MUCUser) {
return;
}
}
createChat(account, user).onPacket(contact, packet);
}
}
use of com.xabber.android.data.message.chat.MucPrivateChatNotification in project xabber-android by redsolution.
the class MessageManager method onStanza.
@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
if (stanza.getFrom() == null) {
return;
}
AccountJid account = connection.getAccount();
final UserJid user;
try {
user = UserJid.from(stanza.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
boolean processed = false;
for (AbstractChat chat : chats.getNested(account.toString()).values()) {
if (chat.onPacket(user, stanza, false)) {
processed = true;
break;
}
}
final AbstractChat chat = getChat(account, user);
if (chat != null && stanza instanceof Message) {
if (chat.isPrivateMucChat() && !chat.isPrivateMucChatAccepted()) {
if (mucPrivateChatRequestProvider.get(chat.getAccount(), chat.getUser()) == null) {
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
}
}
return;
}
if (!processed && stanza instanceof Message) {
final Message message = (Message) stanza;
final String body = message.getBody();
if (body == null) {
return;
}
// check for spam
if (SettingsManager.spamFilterMode() != SettingsManager.SpamFilterMode.disabled && RosterManager.getInstance().getRosterContact(account, user) == null) {
String thread = ((Message) stanza).getThread();
if (SettingsManager.spamFilterMode() == SettingsManager.SpamFilterMode.authCaptcha) {
// check if this message is captcha-answer
Captcha captcha = CaptchaManager.getInstance().getCaptcha(account, user);
if (captcha != null) {
// attempt limit overhead
if (captcha.getAttemptCount() > CaptchaManager.CAPTCHA_MAX_ATTEMPT_COUNT) {
// remove this captcha
CaptchaManager.getInstance().removeCaptcha(account, user);
// discard subscription
try {
PresenceManager.getInstance().discardSubscription(account, user);
} catch (NetworkException e) {
e.printStackTrace();
}
sendMessageWithoutChat(user.getJid(), thread, account, Application.getInstance().getResources().getString(R.string.spam_filter_captcha_many_attempts));
return;
}
if (body.equals(captcha.getAnswer())) {
// captcha solved successfully
// remove this captcha
CaptchaManager.getInstance().removeCaptcha(account, user);
// show auth
PresenceManager.getInstance().handleSubscriptionRequest(account, user);
sendMessageWithoutChat(user.getJid(), thread, account, Application.getInstance().getResources().getString(R.string.spam_filter_captcha_correct));
return;
} else {
// captcha solved unsuccessfully
// increment attempt count
captcha.setAttemptCount(captcha.getAttemptCount() + 1);
// send warning-message
sendMessageWithoutChat(user.getJid(), thread, account, Application.getInstance().getResources().getString(R.string.spam_filter_captcha_incorrect));
return;
}
} else {
// no captcha exist and user not from roster
sendMessageWithoutChat(user.getJid(), thread, account, Application.getInstance().getResources().getString(R.string.spam_filter_limit_message));
// and skip received message as spam
return;
}
} else {
// if message from not-roster user
// send a warning message to sender
sendMessageWithoutChat(user.getJid(), thread, account, Application.getInstance().getResources().getString(R.string.spam_filter_limit_message));
// and skip received message as spam
return;
}
}
if (message.getType() == Message.Type.chat && MUCManager.getInstance().hasRoom(account, user.getJid().asEntityBareJidIfPossible())) {
try {
createPrivateMucChat(account, user.getJid().asFullJidIfPossible()).onPacket(user, stanza, false);
} catch (UserJid.UserJidCreateException e) {
LogManager.exception(this, e);
}
mucPrivateChatRequestProvider.add(new MucPrivateChatNotification(account, user), true);
return;
}
for (ExtensionElement packetExtension : message.getExtensions()) {
if (packetExtension instanceof MUCUser) {
return;
}
}
createChat(account, user).onPacket(user, stanza, false);
}
}
Aggregations