use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class MucInviteDialog method setUpContactTitleView.
@Override
protected void setUpContactTitleView(View view) {
roomInvite = MUCManager.getInstance().getInvite(getAccount(), getContact().getJid().asEntityBareJidIfPossible());
final UserJid inviter = roomInvite.getInviter().getBareUserJid();
final AbstractContact bestContact = RosterManager.getInstance().getBestContact(getAccount(), inviter);
((ImageView) view.findViewById(R.id.avatar)).setImageDrawable(bestContact.getAvatar());
((TextView) view.findViewById(R.id.name)).setText(bestContact.getName());
((TextView) view.findViewById(R.id.status_text)).setText(inviter.toString());
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class CrowdfundingChat method createCrowdfundingChat.
public static CrowdfundingChat createCrowdfundingChat(int unreadCount, CrowdfundingMessage message) {
AccountJid accountJid = getDefaultAccount();
UserJid userJid = getDefaultUser();
if (accountJid != null && userJid != null) {
CrowdfundingChat chat = new CrowdfundingChat(accountJid, userJid, false, message, unreadCount);
return chat;
} else
return null;
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class MessageManager method processCarbonsMessage.
public void processCarbonsMessage(AccountJid account, final Message message, CarbonExtension.Direction direction) {
if (direction == CarbonExtension.Direction.sent) {
UserJid companion;
try {
companion = UserJid.from(message.getTo()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
AbstractChat chat = getChat(account, companion);
if (chat == null) {
chat = createChat(account, companion);
}
final String body = message.getBody();
if (body == null) {
return;
}
final AbstractChat finalChat = chat;
String text = body;
String uid = UUID.randomUUID().toString();
RealmList<ForwardId> forwardIds = finalChat.parseForwardedMessage(true, message, uid);
String originalStanza = message.toXML().toString();
String originalFrom = message.getFrom().toString();
// forward comment (to support previous forwarded xep)
String forwardComment = ForwardManager.parseForwardComment(message);
if (forwardComment != null)
text = forwardComment;
// modify body with references
Pair<String, String> bodies = ReferencesManager.modifyBodyWithReferences(message, text);
text = bodies.first;
String markupText = bodies.second;
MessageItem newMessageItem = finalChat.createNewMessageItem(text);
newMessageItem.setStanzaId(AbstractChat.getStanzaId(message));
newMessageItem.setSent(true);
newMessageItem.setForwarded(true);
if (markupText != null)
newMessageItem.setMarkupText(markupText);
// forwarding
if (forwardIds != null)
newMessageItem.setForwardedIds(forwardIds);
newMessageItem.setOriginalStanza(originalStanza);
newMessageItem.setOriginalFrom(originalFrom);
// attachments
RealmList<Attachment> attachments = HttpFileUploadManager.parseFileMessage(message);
if (attachments.size() > 0)
newMessageItem.setAttachments(attachments);
// groupchat
RefUser groupchatUser = ReferencesManager.getGroupchatUserFromReferences(message);
if (groupchatUser != null) {
GroupchatUserManager.getInstance().saveGroupchatUser(groupchatUser);
newMessageItem.setGroupchatUserId(groupchatUser.getId());
}
BackpressureMessageSaver.getInstance().saveMessageItem(newMessageItem);
// mark incoming messages as read
finalChat.markAsReadAll(false);
// start grace period
AccountManager.getInstance().startGracePeriod(account);
return;
}
UserJid companion = null;
try {
companion = UserJid.from(message.getFrom()).getBareUserJid();
} catch (UserJid.UserJidCreateException e) {
return;
}
// check for spam
if (SettingsManager.spamFilterMode() != SettingsManager.SpamFilterMode.disabled && RosterManager.getInstance().getRosterContact(account, companion) == null) {
// just ignore carbons from not-authorized user
return;
}
boolean processed = false;
for (AbstractChat chat : chats.getNested(account.toString()).values()) {
if (chat.onPacket(companion, message, true)) {
processed = true;
break;
}
}
if (getChat(account, companion) != null) {
return;
}
if (processed) {
return;
}
final String body = message.getBody();
if (body == null) {
return;
}
createChat(account, companion).onPacket(companion, message, true);
}
use of com.xabber.android.data.entity.UserJid 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;
List<AbstractChat> chatsCopy = new ArrayList<>();
chatsCopy.addAll(chats.getNested(account.toString()).values());
for (AbstractChat chat : chatsCopy) {
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);
}
}
use of com.xabber.android.data.entity.UserJid in project xabber-android by redsolution.
the class PresenceManager method requestSubscription.
/**
* Requests subscription to the contact.
* Create chat with new contact if need.
* @throws NetworkException
*/
public void requestSubscription(AccountJid account, UserJid user, boolean createChat) 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);
if (createChat)
createChatForNewContact(account, user);
}
Aggregations