Search in sources :

Example 51 with AbstractChat

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

the class ContactList 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(String user, String text) {
    String bareAddress = Jid.getBareAddress(user);
    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();
    for (RosterContact check : RosterManager.getInstance().getContacts()) {
        if (check.isEnabled() && check.getUser().equals(bareAddress)) {
            entities.add(check);
        }
    }
    if (entities.size() == 1) {
        openChat(entities.get(0), text);
        return;
    }
    Collection<String> accounts = AccountManager.getInstance().getAccounts();
    if (accounts.isEmpty()) {
        return;
    }
    if (accounts.size() == 1) {
        openChat(new BaseEntity(accounts.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) ArrayList(java.util.ArrayList) BaseEntity(com.xabber.android.data.entity.BaseEntity)

Example 52 with AbstractChat

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

the class MUCManager method createRoom.

/**
     * Creates or updates existed room.
     *
     */
public void createRoom(String account, String room, String nickname, String password, boolean join) {
    removeInvite(getInvite(account, room));
    AbstractChat chat = MessageManager.getInstance().getChat(account, room);
    RoomChat roomChat;
    if (chat == null || !(chat instanceof RoomChat)) {
        if (chat != null) {
            MessageManager.getInstance().removeChat(chat);
        }
        roomChat = new RoomChat(account, room, nickname, password);
        MessageManager.getInstance().addChat(roomChat);
    } else {
        roomChat = (RoomChat) chat;
        roomChat.setNickname(nickname);
        roomChat.setPassword(password);
    }
    requestToWriteRoom(account, room, nickname, password, join);
    if (join) {
        joinRoom(account, room, true);
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 53 with AbstractChat

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

the class MUCManager method onLoaded.

private void onLoaded(Collection<RoomChat> roomChats, Collection<RoomChat> needJoins) {
    for (RoomChat roomChat : roomChats) {
        AbstractChat abstractChat = MessageManager.getInstance().getChat(roomChat.getAccount(), roomChat.getUser());
        if (abstractChat != null) {
            MessageManager.getInstance().removeChat(abstractChat);
        }
        MessageManager.getInstance().addChat(roomChat);
        if (needJoins.contains(roomChat)) {
            roomChat.setState(RoomState.waiting);
        }
    }
    NotificationManager.getInstance().registerNotificationProvider(inviteProvider);
    NotificationManager.getInstance().registerNotificationProvider(authorizationErrorProvider);
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 54 with AbstractChat

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

the class MessageArchiveManager method onChatReceived.

private void onChatReceived(String account, Chat chat) {
    Boolean modification = modificationRequests.remove(account, chat.getPacketID());
    if (modification == null)
        return;
    ChatStorage chatStorage = chatStorages.get(account, chat.getWith(), chat.getStartString());
    if (chatStorage == null) {
        LogManager.w(this, "Unexpected chat " + chat.getStartString() + " recevied by " + account + " from " + chat.getWith());
        chatStorage = new ChatStorage(chat.getStart());
        chatStorages.put(account, chat.getWith(), chat.getStartString(), chatStorage);
    }
    String bareAddress = Jid.getBareAddress(chat.getWith());
    HeaderSequence sequence;
    if (modification)
        sequence = modificationStorages.get(account);
    else
        sequence = historyStorages.get(account, bareAddress);
    if (sequence == null)
        return;
    AbstractChat abstractChat = MessageManager.getInstance().getOrCreateChat(account, bareAddress);
    for (AbstractMessage abstractMessage : chat.getMessages()) chatStorage.addItem(abstractChat, chat, abstractMessage, TimeManager.getInstance().getServerTimeOffset(account));
    if (chat.getRsm() == null || chat.getRsm().isForwardFinished(chat.getMessages().size())) {
        chatStorage.onItemsReceived(chat.getVersion());
        sequence.pollHeader();
        if (sequence instanceof HistoryStorage)
            if (apply(account, bareAddress, chat.getStartString(), chatStorage, (HistoryStorage) sequence))
                return;
        requestSequence(account, bareAddress, sequence);
    } else {
        requestChat(account, chat, chat.getRsm().getLast(), modification);
    }
}
Also used : AbstractMessage(com.xabber.xmpp.archive.AbstractMessage) AbstractChat(com.xabber.android.data.message.AbstractChat)

Example 55 with AbstractChat

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

the class MessageArchiveManager method apply.

/**
     * Apply received messages.
     *
     * @param account
     * @param bareAddress
     * @param tag
     * @param chatStorage
     * @param historyStorage
     * @return Whether enough messages have been received.
     */
private boolean apply(String account, String bareAddress, String tag, ChatStorage chatStorage, HistoryStorage historyStorage) {
    AbstractChat abstractChat = MessageManager.getInstance().getChat(account, bareAddress);
    int newCount = abstractChat.onMessageDownloaded(tag, chatStorage.getItems(), false);
    int incomingCount = 0;
    for (MessageItem messageItem : chatStorage.getItems()) if (messageItem.isIncoming())
        incomingCount += 1;
    chatStorage.onApplied();
    if (historyStorage.enoughMessages(newCount, incomingCount)) {
        historyStorage.onSuccess();
        return true;
    }
    return false;
}
Also used : MessageItem(com.xabber.android.data.message.MessageItem) AbstractChat(com.xabber.android.data.message.AbstractChat)

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