Search in sources :

Example 1 with ActiveDialogGroup

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();
}
Also used : Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) ConversationState(im.actor.core.entity.ConversationState) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) ApiDialogShort(im.actor.core.api.ApiDialogShort)

Example 2 with ActiveDialogGroup

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;
}
Also used : DialogsInt(im.actor.core.modules.messaging.dialogs.DialogsInt) RouterDifferenceStart(im.actor.core.modules.messaging.router.entity.RouterDifferenceStart) ModuleContext(im.actor.core.modules.ModuleContext) ApiMessageReaction(im.actor.core.api.ApiMessageReaction) UpdateChatGroupsChanged(im.actor.core.api.updates.UpdateChatGroupsChanged) UpdateMessage(im.actor.core.api.updates.UpdateMessage) ActiveDialogStorage(im.actor.core.modules.messaging.router.entity.ActiveDialogStorage) RouterApplyChatHistory(im.actor.core.modules.messaging.router.entity.RouterApplyChatHistory) RouterApplyDialogsHistory(im.actor.core.modules.messaging.router.entity.RouterApplyDialogsHistory) Avatar(im.actor.core.entity.Avatar) JavaUtil(im.actor.core.util.JavaUtil) RouterMessageUpdate(im.actor.core.modules.messaging.router.entity.RouterMessageUpdate) DialogSmall(im.actor.core.viewmodel.DialogSmall) TextContent(im.actor.core.entity.content.TextContent) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) EntityConverter.convert(im.actor.core.entity.EntityConverter.convert) ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) UpdateMessageReadByMe(im.actor.core.api.updates.UpdateMessageReadByMe) RequestLoadGroupedDialogs(im.actor.core.api.rpc.RequestLoadGroupedDialogs) UpdateReactionsUpdate(im.actor.core.api.updates.UpdateReactionsUpdate) Void(im.actor.runtime.actors.messages.Void) DialogHistory(im.actor.core.modules.messaging.history.entity.DialogHistory) RouterDifferenceEnd(im.actor.core.modules.messaging.router.entity.RouterDifferenceEnd) Reaction(im.actor.core.entity.Reaction) AssertUtils.assertTrue(im.actor.core.util.AssertUtils.assertTrue) RouterConversationVisible(im.actor.core.modules.messaging.router.entity.RouterConversationVisible) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) RouterOutgoingSent(im.actor.core.modules.messaging.router.entity.RouterOutgoingSent) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) CursorReceiverActor(im.actor.core.modules.messaging.actions.CursorReceiverActor) UpdateMessageDelete(im.actor.core.api.updates.UpdateMessageDelete) UpdateChatDropCache(im.actor.core.api.updates.UpdateChatDropCache) UpdateMessageContentChanged(im.actor.core.api.updates.UpdateMessageContentChanged) Peer(im.actor.core.entity.Peer) MessageState(im.actor.core.entity.MessageState) RouterChangedContent(im.actor.core.modules.messaging.router.entity.RouterChangedContent) Message(im.actor.core.entity.Message) UpdateMessageReceived(im.actor.core.api.updates.UpdateMessageReceived) RouterAppHidden(im.actor.core.modules.messaging.router.entity.RouterAppHidden) Promise(im.actor.runtime.promise.Promise) RouterResetChat(im.actor.core.modules.messaging.router.entity.RouterResetChat) UpdateChatClear(im.actor.core.api.updates.UpdateChatClear) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ConversationState(im.actor.core.entity.ConversationState) AbsModule(im.actor.core.modules.AbsModule) User(im.actor.core.entity.User) RouterAppVisible(im.actor.core.modules.messaging.router.entity.RouterAppVisible) UpdateMessageSent(im.actor.core.api.updates.UpdateMessageSent) UpdateMessageRead(im.actor.core.api.updates.UpdateMessageRead) ListEngine(im.actor.runtime.storage.ListEngine) PeerType(im.actor.core.entity.PeerType) AbsContent(im.actor.core.entity.content.AbsContent) IOException(java.io.IOException) Group(im.actor.core.entity.Group) RouterConversationHidden(im.actor.core.modules.messaging.router.entity.RouterConversationHidden) RouterOutgoingError(im.actor.core.modules.messaging.router.entity.RouterOutgoingError) CursorReaderActor(im.actor.core.modules.messaging.actions.CursorReaderActor) RouterPeersChanged(im.actor.core.modules.messaging.router.entity.RouterPeersChanged) RouterMessageOnlyActive(im.actor.core.modules.messaging.router.entity.RouterMessageOnlyActive) RouterNewMessages(im.actor.core.modules.messaging.router.entity.RouterNewMessages) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) SenderActor(im.actor.core.modules.messaging.actions.SenderActor) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) RouterDeletedMessages(im.actor.core.modules.messaging.router.entity.RouterDeletedMessages) ContentDescription(im.actor.core.entity.ContentDescription) Log(im.actor.runtime.Log) KeyValueEngine(im.actor.runtime.storage.KeyValueEngine) UpdateChatDelete(im.actor.core.api.updates.UpdateChatDelete) ApiDialogShort(im.actor.core.api.ApiDialogShort) Update(im.actor.core.network.parser.Update) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) Group(im.actor.core.entity.Group) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) User(im.actor.core.entity.User) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) Void(im.actor.runtime.actors.messages.Void)

Example 3 with ActiveDialogGroup

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);
}
Also used : ApiDialogGroup(im.actor.core.api.ApiDialogGroup) Group(im.actor.core.entity.Group) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) User(im.actor.core.entity.User) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) DialogSmall(im.actor.core.viewmodel.DialogSmall) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) Avatar(im.actor.core.entity.Avatar)

Aggregations

ApiDialogGroup (im.actor.core.api.ApiDialogGroup)3 Peer (im.actor.core.entity.Peer)3 ActiveDialogGroup (im.actor.core.modules.messaging.router.entity.ActiveDialogGroup)3 ArrayList (java.util.ArrayList)3 ApiDialogShort (im.actor.core.api.ApiDialogShort)2 Avatar (im.actor.core.entity.Avatar)2 ConversationState (im.actor.core.entity.ConversationState)2 Group (im.actor.core.entity.Group)2 User (im.actor.core.entity.User)2 DialogGroup (im.actor.core.viewmodel.DialogGroup)2 DialogSmall (im.actor.core.viewmodel.DialogSmall)2 ArrayListDialogSmall (im.actor.core.viewmodel.generics.ArrayListDialogSmall)2 ApiMessageReaction (im.actor.core.api.ApiMessageReaction)1 RequestLoadGroupedDialogs (im.actor.core.api.rpc.RequestLoadGroupedDialogs)1 UpdateChatClear (im.actor.core.api.updates.UpdateChatClear)1 UpdateChatDelete (im.actor.core.api.updates.UpdateChatDelete)1 UpdateChatDropCache (im.actor.core.api.updates.UpdateChatDropCache)1 UpdateChatGroupsChanged (im.actor.core.api.updates.UpdateChatGroupsChanged)1 UpdateMessage (im.actor.core.api.updates.UpdateMessage)1 UpdateMessageContentChanged (im.actor.core.api.updates.UpdateMessageContentChanged)1