Search in sources :

Example 46 with UserJid

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());
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AbstractContact(com.xabber.android.data.roster.AbstractContact)

Example 47 with UserJid

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;
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid)

Example 48 with UserJid

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);
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RefUser(com.xabber.android.data.extension.references.RefUser) UserJid(com.xabber.android.data.entity.UserJid) Attachment(com.xabber.android.data.database.messagerealm.Attachment) ForwardId(com.xabber.android.data.database.messagerealm.ForwardId)

Example 49 with UserJid

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);
    }
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) ArrayList(java.util.ArrayList) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) UserJid(com.xabber.android.data.entity.UserJid) MucPrivateChatNotification(com.xabber.android.data.message.chat.MucPrivateChatNotification) Captcha(com.xabber.android.data.extension.captcha.Captcha) AccountJid(com.xabber.android.data.entity.AccountJid) NetworkException(com.xabber.android.data.NetworkException)

Example 50 with UserJid

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);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) UserJid(com.xabber.android.data.entity.UserJid)

Aggregations

UserJid (com.xabber.android.data.entity.UserJid)67 AccountJid (com.xabber.android.data.entity.AccountJid)43 AbstractChat (com.xabber.android.data.message.AbstractChat)15 ArrayList (java.util.ArrayList)15 Intent (android.content.Intent)9 Jid (org.jxmpp.jid.Jid)9 Presence (org.jivesoftware.smack.packet.Presence)8 XmppStringprepException (org.jxmpp.stringprep.XmppStringprepException)8 AccountItem (com.xabber.android.data.account.AccountItem)7 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 Message (org.jivesoftware.smack.packet.Message)6 Resourcepart (org.jxmpp.jid.parts.Resourcepart)6 NetworkException (com.xabber.android.data.NetworkException)5 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)5 SmackException (org.jivesoftware.smack.SmackException)5 Uri (android.net.Uri)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 DomainBareJid (org.jxmpp.jid.DomainBareJid)4 TextView (android.widget.TextView)3 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)3