use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatDelete.
private Promise<Void> onChatDelete(Peer peer) {
conversation(peer).clear();
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (!state.isLoaded()) {
state = state.changeIsLoaded(true);
conversationStates.addOrUpdateItem(state);
}
updateChatState(peer);
return getDialogsRouter().onChatDelete(peer).chain(aVoid -> onChatDropCache(peer));
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatHistoryLoaded.
private Promise<Void> onChatHistoryLoaded(Peer peer, List<Message> messages, Long maxReadDate, Long maxReceiveDate, boolean isEnded) {
Log.d(TAG, "History Loaded");
long maxMessageDate = 0;
// Processing all new messages
ArrayList<Message> updated = new ArrayList<>();
for (Message historyMessage : messages) {
// Ignore already present messages
if (conversation(peer).getValue(historyMessage.getEngineId()) != null) {
continue;
}
updated.add(historyMessage);
if (historyMessage.getSenderId() != myUid()) {
maxMessageDate = Math.max(maxMessageDate, historyMessage.getSortDate());
}
}
// Writing messages
conversation(peer).addOrUpdateItems(updated);
// Updating conversation state
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
if (state.getInMaxMessageDate() < maxMessageDate) {
state = state.changeInMaxDate(maxMessageDate);
isChanged = true;
}
if (maxReadDate != null && maxReadDate != 0 && state.getOutReadDate() < maxMessageDate) {
state = state.changeOutReadDate(maxReadDate);
isChanged = true;
}
if (maxReceiveDate != null && maxReceiveDate != 0 && state.getOutReceiveDate() < maxReceiveDate) {
state = state.changeOutReceiveDate(maxReceiveDate);
isChanged = true;
}
if (state.isLoaded() != isEnded) {
state = state.changeIsLoaded(isEnded);
isChanged = true;
}
boolean isEmpty = conversation(peer).isEmpty();
if (state.isEmpty() != isEmpty) {
state = state.changeIsEmpty(isEmpty);
isChanged = true;
}
if (isChanged) {
conversationStates.addOrUpdateItem(state);
}
// Reading messages if needed
markAsReadIfNeeded(peer);
return Promise.success(null);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onChatClear.
private Promise<Void> onChatClear(Peer peer) {
conversation(peer).clear();
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
if (!state.isLoaded()) {
state = state.changeIsLoaded(true);
conversationStates.addOrUpdateItem(state);
}
updateChatState(peer);
return getDialogsRouter().onChatClear(peer);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onMessageDeleted.
//
// Message Deletions
//
private Promise<Void> onMessageDeleted(Peer peer, List<Long> rids) {
// Delete Messages
conversation(peer).removeItems(JavaUtil.unbox(rids));
updateChatState(peer);
Message head = conversation(peer).getHeadValue();
if (head != null) {
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
state = state.changeInReadDate(head.getSortDate()).changeOutSendDate(head.getSortDate());
conversationStates.addOrUpdateItem(state);
if (head.getMessageState() == MessageState.PENDING) {
head = null;
}
}
return getDialogsRouter().onMessageDeleted(peer, head);
}
use of im.actor.core.entity.ConversationState in project actor-platform by actorapp.
the class RouterActor method onActiveDialogsChanged.
//
// Active Dialogs
//
private void onActiveDialogsChanged(List<ApiDialogGroup> dialogs, boolean showArchived, boolean showInvite) {
//
// Updating Counters
//
ArrayList<ConversationState> convStates = new ArrayList<>();
for (ApiDialogGroup g : dialogs) {
for (ApiDialogShort s : g.getDialogs()) {
Peer peer = convert(s.getPeer());
ConversationState state = conversationStates.getValue(peer.getUnuqueId());
boolean isChanged = false;
if (state.getUnreadCount() != s.getCounter() && !isConversationVisible(peer)) {
state = state.changeCounter(s.getCounter());
isChanged = true;
}
if (state.getInMaxMessageDate() < s.getDate()) {
state = state.changeInMaxDate(s.getDate());
isChanged = true;
}
if (isChanged) {
convStates.add(state);
}
}
}
conversationStates.addOrUpdateItems(convStates);
//
// Updating storage
//
activeDialogStorage.setHaveArchived(showArchived);
activeDialogStorage.setShowInvite(showInvite);
activeDialogStorage.setLoaded(true);
activeDialogStorage.getGroups().clear();
for (ApiDialogGroup g : dialogs) {
ArrayList<Peer> peers = new ArrayList<>();
for (ApiDialogShort s : g.getDialogs()) {
Peer peer = convert(s.getPeer());
peers.add(peer);
}
activeDialogStorage.getGroups().add(new ActiveDialogGroup(g.getKey(), g.getTitle(), peers));
}
context().getStorageModule().getBlobStorage().addOrUpdateItem(AbsModule.BLOB_DIALOGS_ACTIVE, activeDialogStorage.toByteArray());
//
// Notify VM
//
notifyActiveDialogsVM();
//
// Unstash all messages after initial loading
//
unstashAll();
}
Aggregations