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);
}
}
}
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> (");
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;
}
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;
}
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);
}
Aggregations