Search in sources :

Example 56 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ContactListActivity method openChat.

/**
 * Open chat with specified contact.
 * <p/>
 * Show dialog to choose account if necessary.
 *
 * @param user
 * @param text can be <code>null</code>.
 */
private void openChat(UserJid user, String text) {
    UserJid bareAddress = user.getBareUserJid();
    ArrayList<BaseEntity> entities = new ArrayList<>();
    for (AbstractChat check : MessageManager.getInstance().getChats()) {
        if (check.isActive() && check.getUser().equals(bareAddress)) {
            entities.add(check);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    entities.clear();
    Collection<AccountJid> enabledAccounts = AccountManager.getInstance().getEnabledAccounts();
    RosterManager rosterManager = RosterManager.getInstance();
    for (AccountJid accountJid : enabledAccounts) {
        RosterContact rosterContact = rosterManager.getRosterContact(accountJid, user);
        if (rosterContact != null && rosterContact.isEnabled()) {
            entities.add(rosterContact);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    if (enabledAccounts.isEmpty()) {
        return;
    }
    if (enabledAccounts.size() == 1) {
        openChat(rosterManager.getBestContact(enabledAccounts.iterator().next(), bareAddress), text);
        return;
    }
    AccountChooseDialogFragment.newInstance(bareAddress, text).show(getFragmentManager(), "OPEN_WITH_ACCOUNT");
}
Also used : RosterContact(com.xabber.android.data.roster.RosterContact) AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) BaseEntity(com.xabber.android.data.entity.BaseEntity) ArrayList(java.util.ArrayList) UserJid(com.xabber.android.data.entity.UserJid) RosterManager(com.xabber.android.data.roster.RosterManager)

Example 57 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ContactListActivity method showContactSubscriptionDialog.

private void showContactSubscriptionDialog() {
    Intent intent = getIntent();
    AccountJid account = getRoomInviteAccount(intent);
    UserJid user = getRoomInviteUser(intent);
    if (account != null && user != null) {
        ContactSubscriptionDialog.newInstance(account, user).show(getFragmentManager(), ContactSubscriptionDialog.class.getName());
    }
}
Also used : AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent) ContactSubscriptionDialog(com.xabber.android.ui.dialog.ContactSubscriptionDialog)

Example 58 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class ContactListActivity method showMucInviteDialog.

private void showMucInviteDialog() {
    Intent intent = getIntent();
    AccountJid account = getRoomInviteAccount(intent);
    UserJid user = getRoomInviteUser(intent);
    if (account != null && user != null) {
        MucInviteDialog.newInstance(account, user).show(getFragmentManager(), MucInviteDialog.class.getName());
    }
}
Also used : MucInviteDialog(com.xabber.android.ui.dialog.MucInviteDialog) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) Intent(android.content.Intent)

Example 59 with AccountJid

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

Example 60 with AccountJid

use of com.xabber.android.data.entity.AccountJid in project xabber-android by redsolution.

the class MessageManager method setVisibleChat.

/**
 * Sets currently visible chat.
 */
public void setVisibleChat(BaseEntity visibleChat) {
    AbstractChat chat = getChat(visibleChat.getAccount(), visibleChat.getUser());
    if (chat == null) {
        chat = createChat(visibleChat.getAccount(), visibleChat.getUser());
    } else {
        final AccountJid account = chat.getAccount();
        final UserJid user = chat.getUser();
        MessageDatabaseManager.getInstance().getRealmUiThread().executeTransactionAsync(new Realm.Transaction() {

            @Override
            public void execute(Realm realm) {
                RealmResults<MessageItem> unreadMessages = realm.where(MessageItem.class).equalTo(MessageItem.Fields.ACCOUNT, account.toString()).equalTo(MessageItem.Fields.USER, user.toString()).equalTo(MessageItem.Fields.READ, false).findAll();
                List<MessageItem> unreadMessagesList = new ArrayList<>(unreadMessages);
                for (MessageItem messageItem : unreadMessagesList) {
                    messageItem.setRead(true);
                }
            }
        });
    }
    this.visibleChat = chat;
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) List(java.util.List) ArrayList(java.util.ArrayList) Realm(io.realm.Realm) RealmResults(io.realm.RealmResults)

Aggregations

AccountJid (com.xabber.android.data.entity.AccountJid)74 UserJid (com.xabber.android.data.entity.UserJid)38 AccountItem (com.xabber.android.data.account.AccountItem)21 Jid (org.jxmpp.jid.Jid)13 Intent (android.content.Intent)11 ArrayList (java.util.ArrayList)11 View (android.view.View)10 NetworkException (com.xabber.android.data.NetworkException)9 AbstractChat (com.xabber.android.data.message.AbstractChat)7 Message (org.jivesoftware.smack.packet.Message)7 Presence (org.jivesoftware.smack.packet.Presence)7 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)6 TextView (android.widget.TextView)5 StatusMode (com.xabber.android.data.account.StatusMode)5 Resourcepart (org.jxmpp.jid.parts.Resourcepart)5 ImageView (android.widget.ImageView)4 AccountManager (com.xabber.android.data.account.AccountManager)4 RosterContact (com.xabber.android.data.roster.RosterContact)4 ContactVO (com.xabber.android.presentation.ui.contactlist.viewobjects.ContactVO)4 BarPainter (com.xabber.android.ui.color.BarPainter)4