Search in sources :

Example 16 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatActivity method selectChat.

private void selectChat(AccountJid accountJid, UserJid userJid) {
    AbstractChat chat = MessageManager.getInstance().getOrCreateChat(accountJid, userJid);
    selectChatPage(chat, true);
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 17 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatActivity method createSendIntent.

/**
 * Create intent to send message.
 * <p/>
 * Contact list will not be shown on when chat will be closed.
 * @param text    if <code>null</code> then user will be able to send a number
 *                of messages. Else only one message can be send.
 */
public static Intent createSendIntent(Context context, AccountJid account, UserJid user, String text) {
    Intent intent = ChatActivity.createSpecificChatIntent(context, account, user);
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, text);
    AbstractChat chat = MessageManager.getInstance().getChat(account, user);
    intent.putExtra(KEY_SHOW_ARCHIVED, chat != null && chat.isArchived());
    return intent;
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) Intent(android.content.Intent)

Example 18 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatActivity method setUpOptionsMenu.

private void setUpOptionsMenu(Menu menu) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
    if (abstractChat != null) {
        menu.clear();
        MenuInflater inflater = getMenuInflater();
        if (selectedPagePosition == PAGE_POSITION_RECENT_CHATS) {
            inflater.inflate(R.menu.menu_chat_recent_list, menu);
            setUpRecentChatsMenu(menu, abstractChat);
            return;
        }
        if (selectedPagePosition == PAGE_POSITION_CHAT_INFO) {
            inflater.inflate(R.menu.toolbar_contact, menu);
            setUpContactInfoMenu(menu, abstractChat);
            if (abstractChat instanceof RoomChat)
                setUpMUCInfoMenu(menu, abstractChat);
            return;
        }
        if (abstractChat instanceof RoomChat) {
            inflater.inflate(R.menu.menu_chat_muc, menu);
            setUpMUCMenu(menu, abstractChat);
            return;
        }
        if (abstractChat instanceof RegularChat) {
            inflater.inflate(R.menu.menu_chat_regular, menu);
            setUpRegularChatMenu(menu, abstractChat);
            return;
        }
    }
}
Also used : MenuInflater(android.view.MenuInflater) AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) RegularChat(com.xabber.android.data.message.RegularChat)

Example 19 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class ChatActivity method handleOtrIntent.

private void handleOtrIntent(Intent intent) {
    String account = intent.getStringExtra(KEY_ACCOUNT);
    String user = intent.getStringExtra(KEY_USER);
    String question = intent.getStringExtra(KEY_QUESTION);
    if (account != null && user != null) {
        try {
            AccountJid accountJid = AccountJid.from(account);
            UserJid userJid = UserJid.from(user);
            AbstractChat chat = MessageManager.getInstance().getOrCreateChat(accountJid, userJid);
            if (chat != null && chat instanceof RegularChat) {
                if (intent.getBooleanExtra(EXTRA_OTR_PROGRESS, false)) {
                    ((RegularChat) chat).setIntent(QuestionActivity.createCancelIntent(Application.getInstance(), accountJid, userJid));
                } else {
                    ((RegularChat) chat).setIntent(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question));
                }
            }
        } catch (UserJid.UserJidCreateException | XmppStringprepException e) {
            e.printStackTrace();
        }
    }
    getIntent().removeExtra(EXTRA_OTR_REQUEST);
    getIntent().removeExtra(EXTRA_OTR_PROGRESS);
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) AccountJid(com.xabber.android.data.entity.AccountJid) UserJid(com.xabber.android.data.entity.UserJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) RegularChat(com.xabber.android.data.message.RegularChat)

Example 20 with AbstractChat

use of com.xabber.android.data.message.AbstractChat in project xabber-android by redsolution.

the class BookmarksManager method onAuthorized.

public void onAuthorized(AccountJid account) {
    cleanCache(account);
    List<BookmarkedConference> conferences = getConferencesFromBookmarks(account);
    if (!conferences.isEmpty()) {
        for (BookmarkedConference conference : conferences) {
            if (!MUCManager.getInstance().hasRoom(account, conference.getJid())) {
                createMUC(account, conference);
                LogManager.d(this, " Conference " + conference.getJid() + "was added to roster from bookmarks");
            }
        }
    }
    // Check bookmarks on first run new Xabber. Adding all conferences to bookmarks.
    if (!isBookmarkCheckedByXabber(account)) {
        // add conferences from phone to bookmarks
        Collection<AbstractChat> chats = MessageManager.getInstance().getChats(account);
        if (!chats.isEmpty()) {
            for (AbstractChat chat : chats) {
                if (chat instanceof RoomChat) {
                    RoomChat roomChat = (RoomChat) chat;
                    if (!hasConference(conferences, roomChat.getTo())) {
                        addConferenceToBookmarks(account, roomChat.getTo().toString(), roomChat.getTo(), roomChat.getNickname());
                    }
                }
            }
        }
        // add url about check to bookmarks
        addUrlToBookmarks(account, XABBER_URL, XABBER_NAME, false);
    }
    Collection<AbstractChat> chats = MessageManager.getInstance().getChats(account);
    if (!chats.isEmpty()) {
        for (AbstractChat chat : chats) {
            if (chat instanceof RoomChat) {
                if (!hasConference(conferences, ((RoomChat) chat).getTo())) {
                    removeMUC(account, chat.getUser());
                    LogManager.d(this, " Conference " + chat.getTo().toString() + " was deleted from phone");
                }
            }
        }
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) BookmarkedConference(org.jivesoftware.smackx.bookmarks.BookmarkedConference) RoomChat(com.xabber.android.data.extension.muc.RoomChat)

Aggregations

AbstractChat (com.xabber.android.data.message.AbstractChat)55 UserJid (com.xabber.android.data.entity.UserJid)10 RoomChat (com.xabber.android.data.extension.muc.RoomChat)10 NetworkException (com.xabber.android.data.NetworkException)9 RegularChat (com.xabber.android.data.message.RegularChat)9 ArrayList (java.util.ArrayList)8 AccountJid (com.xabber.android.data.entity.AccountJid)7 RoomContact (com.xabber.android.data.extension.muc.RoomContact)6 ChatContact (com.xabber.android.data.message.ChatContact)6 AbstractContact (com.xabber.android.data.roster.AbstractContact)6 RosterContact (com.xabber.android.data.roster.RosterContact)6 NotificationState (com.xabber.android.data.message.NotificationState)5 Message (org.jivesoftware.smack.packet.Message)5 GroupConfiguration (com.xabber.android.ui.adapter.contactlist.GroupConfiguration)4 View (android.view.View)3 MessageManager (com.xabber.android.data.message.MessageManager)3 Map (java.util.Map)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2