use of im.actor.core.modules.messaging.router.entity.ActiveDialogGroup 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();
}
use of im.actor.core.modules.messaging.router.entity.ActiveDialogGroup in project actor-platform by actorapp.
the class RouterActor method onPeersChanged.
//
// Peer Changed
//
private Promise<Void> onPeersChanged(List<User> users, List<Group> groups) {
Promise<Void> res = Promise.success(null);
boolean isActiveNeedUpdate = false;
for (User u : users) {
if (!isActiveNeedUpdate) {
for (ActiveDialogGroup g : activeDialogStorage.getGroups()) {
if (g.getPeers().contains(u.peer())) {
isActiveNeedUpdate = true;
break;
}
}
}
res = res.chain(v -> getDialogsRouter().onUserChanged(u));
}
for (Group group : groups) {
if (!isActiveNeedUpdate) {
for (ActiveDialogGroup g : activeDialogStorage.getGroups()) {
if (g.getPeers().contains(group.peer())) {
isActiveNeedUpdate = true;
break;
}
}
}
res = res.chain(v -> getDialogsRouter().onGroupChanged(group));
}
if (isActiveNeedUpdate) {
notifyActiveDialogsVM();
}
return res;
}
use of im.actor.core.modules.messaging.router.entity.ActiveDialogGroup in project actor-platform by actorapp.
the class RouterActor method notifyActiveDialogsVM.
private void notifyActiveDialogsVM() {
int counter = 0;
ArrayList<DialogGroup> groups = new ArrayList<>();
for (ActiveDialogGroup i : activeDialogStorage.getGroups()) {
ArrayListDialogSmall dialogSmalls = new ArrayListDialogSmall();
for (Peer p : i.getPeers()) {
String title;
Avatar avatar;
if (p.getPeerType() == PeerType.GROUP) {
Group group = getGroup(p.getPeerId());
title = group.getTitle();
avatar = group.getAvatar();
} else if (p.getPeerType() == PeerType.PRIVATE) {
User user = getUser(p.getPeerId());
title = user.getName();
avatar = user.getAvatar();
} else {
continue;
}
int unreadCount = conversationStates.getValue(p.getUnuqueId()).getUnreadCount();
counter += unreadCount;
dialogSmalls.add(new DialogSmall(p, title, avatar, unreadCount));
}
groups.add(new DialogGroup(i.getTitle(), i.getKey(), dialogSmalls));
}
context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().change(groups);
context().getConductor().getGlobalStateVM().onGlobalCounterChanged(counter);
}
Aggregations