Search in sources :

Example 16 with RoomChat

use of com.xabber.android.data.extension.muc.RoomChat in project xabber-android by redsolution.

the class ChatFragment method showJoinButtonIfNeed.

public void showJoinButtonIfNeed() {
    AbstractChat chat = getChat();
    if (chat != null && chat instanceof RoomChat) {
        RoomState chatState = ((RoomChat) chat).getState();
        if (chatState == RoomState.unavailable) {
            if (joinLayout == null)
                inflateJoinLayout();
            joinLayout.setVisibility(View.VISIBLE);
            inputView.setVisibility(View.GONE);
        } else {
            if (joinLayout != null)
                joinLayout.setVisibility(View.GONE);
            inputView.setVisibility(View.VISIBLE);
        }
    }
}
Also used : AbstractChat(com.xabber.android.data.message.AbstractChat) RoomChat(com.xabber.android.data.extension.muc.RoomChat) RoomState(com.xabber.android.data.extension.muc.RoomState)

Example 17 with RoomChat

use of com.xabber.android.data.extension.muc.RoomChat in project xabber-android by redsolution.

the class MessageManager method exportChat.

/**
 * Export chat to file with specified name.
 *
 * @param account
 * @param user
 * @param fileName
 * @throws NetworkException
 */
public File exportChat(AccountJid account, UserJid user, String fileName) throws NetworkException {
    final File file = new File(Environment.getExternalStorageDirectory(), fileName);
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        final String titleName = RosterManager.getInstance().getName(account, user) + " (" + user + ")";
        out.write("<html><head><title>");
        out.write(StringUtils.escapeHtml(titleName));
        out.write("</title></head><body>");
        final AbstractChat abstractChat = getChat(account, user);
        if (abstractChat != null) {
            final boolean isMUC = abstractChat instanceof RoomChat;
            final String accountName = AccountManager.getInstance().getNickName(account);
            final String userName = RosterManager.getInstance().getName(account, user);
            Realm realm = MessageDatabaseManager.getInstance().getNewBackgroundRealm();
            RealmResults<MessageItem> messageItems = MessageDatabaseManager.getChatMessages(realm, account, user);
            for (MessageItem messageItem : messageItems) {
                if (messageItem.getAction() != null) {
                    continue;
                }
                final String name;
                if (isMUC) {
                    name = messageItem.getResource().toString();
                } else {
                    if (messageItem.isIncoming()) {
                        name = userName;
                    } else {
                        name = accountName;
                    }
                }
                out.write("<b>");
                out.write(StringUtils.escapeHtml(name));
                out.write("</b>&nbsp;(");
                out.write(StringUtils.getDateTimeText(new Date(messageItem.getTimestamp())));
                out.write(")<br />\n<p>");
                out.write(StringUtils.escapeHtml(messageItem.getText()));
                out.write("</p><hr />\n");
            }
            realm.close();
        }
        out.write("</body></html>");
        out.close();
    } catch (IOException e) {
        throw new NetworkException(R.string.FILE_NOT_FOUND);
    }
    return file;
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) FileWriter(java.io.FileWriter) IOException(java.io.IOException) RoomChat(com.xabber.android.data.extension.muc.RoomChat) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) File(java.io.File) Realm(io.realm.Realm) NetworkException(com.xabber.android.data.NetworkException)

Example 18 with RoomChat

use of com.xabber.android.data.extension.muc.RoomChat in project xabber-android by redsolution.

the class RosterManager method getDisplayAuthorName.

public static String getDisplayAuthorName(MessageItem messageItem) {
    UserJid jid = null;
    try {
        jid = UserJid.from(messageItem.getOriginalFrom());
    } catch (UserJid.UserJidCreateException e) {
        e.printStackTrace();
    }
    String author = null;
    if (jid != null) {
        EntityBareJid room = messageItem.getUser().getBareJid().asEntityBareJidIfPossible();
        RoomChat roomChat = null;
        if (room != null)
            roomChat = MUCManager.getInstance().getRoomChat(messageItem.getAccount(), room);
        if (roomChat != null) {
            if (!messageItem.isIncoming())
                author = MUCManager.getInstance().getNickname(messageItem.getAccount(), room).toString();
            else
                author = jid.getJid().getResourceOrEmpty().toString();
        } else {
            if (!messageItem.getAccount().getFullJid().asBareJid().equals(jid.getBareJid()))
                author = RosterManager.getInstance().getNameOrBareJid(messageItem.getAccount(), jid);
            else
                author = AccountManager.getInstance().getNickName(messageItem.getAccount());
        }
    }
    return author;
}
Also used : UserJid(com.xabber.android.data.entity.UserJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) RoomChat(com.xabber.android.data.extension.muc.RoomChat)

Example 19 with RoomChat

use of com.xabber.android.data.extension.muc.RoomChat in project xabber-android by redsolution.

the class ChatActivity method setUpMUCMenu.

private void setUpMUCMenu(Menu menu, AbstractChat abstractChat) {
    RoomState chatState = ((RoomChat) abstractChat).getState();
    if (chatState == RoomState.error) {
        menu.findItem(R.id.action_authorization_settings).setVisible(true);
    }
    setUpRegularChatMenu(menu, abstractChat);
}
Also used : RoomChat(com.xabber.android.data.extension.muc.RoomChat) RoomState(com.xabber.android.data.extension.muc.RoomState)

Aggregations

RoomChat (com.xabber.android.data.extension.muc.RoomChat)19 AbstractChat (com.xabber.android.data.message.AbstractChat)12 RoomContact (com.xabber.android.data.extension.muc.RoomContact)7 ChatContact (com.xabber.android.data.message.ChatContact)7 RosterContact (com.xabber.android.data.roster.RosterContact)6 ArrayList (java.util.ArrayList)6 UserJid (com.xabber.android.data.entity.UserJid)5 AbstractContact (com.xabber.android.data.roster.AbstractContact)5 AccountJid (com.xabber.android.data.entity.AccountJid)4 RoomState (com.xabber.android.data.extension.muc.RoomState)4 CommonState (com.xabber.android.data.account.CommonState)3 File (java.io.File)3 Collection (java.util.Collection)3 Date (java.util.Date)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 NetworkException (com.xabber.android.data.NetworkException)2 MessageItem (com.xabber.android.data.database.messagerealm.MessageItem)2 RegularChat (com.xabber.android.data.message.RegularChat)2 AccountWithButtonsVO (com.xabber.android.presentation.ui.contactlist.viewobjects.AccountWithButtonsVO)2