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