Search in sources :

Example 26 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class GroupAvatarChangeActor method uploadCompleted.

public void uploadCompleted(final long rid, FileReference fileReference) {
    if (!tasksMap.containsKey(rid)) {
        return;
    }
    final int gid = tasksMap.get(rid);
    long accessHash = getGroup(gid).getAccessHash();
    if (currentTasks.get(gid) != rid) {
        return;
    }
    api(new RequestEditGroupAvatar(new ApiGroupOutPeer(gid, accessHash), rid, new ApiFileLocation(fileReference.getFileId(), fileReference.getAccessHash()), ApiSupportConfiguration.OPTIMIZATIONS)).flatMap(responseEditGroupAvatar -> updates().applyUpdate(responseEditGroupAvatar.getSeq(), responseEditGroupAvatar.getState(), new UpdateGroupAvatarChanged(gid, responseEditGroupAvatar.getAvatar()))).then(v -> avatarChanged(gid, rid)).failure(e -> {
        if (!tasksMap.containsKey(rid)) {
            return;
        }
        final int gid2 = tasksMap.get(rid);
        if (currentTasks.get(gid2) != rid) {
            return;
        }
        currentTasks.remove(gid2);
        tasksMap.remove(rid);
        context().getGroupsModule().getAvatarVM(gid2).getUploadState().change(new AvatarUploadState(null, false));
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ResponseEditGroupAvatar(im.actor.core.api.rpc.ResponseEditGroupAvatar) ModuleContext(im.actor.core.modules.ModuleContext) ResponseSeqDate(im.actor.core.api.rpc.ResponseSeqDate) ExecuteAfter(im.actor.core.modules.sequence.internal.ExecuteAfter) Void(im.actor.runtime.actors.messages.Void) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) RandomUtils(im.actor.core.util.RandomUtils) HashMap(java.util.HashMap) Group(im.actor.core.entity.Group) RpcException(im.actor.core.network.RpcException) RequestRemoveGroupAvatar(im.actor.core.api.rpc.RequestRemoveGroupAvatar) ModuleActor(im.actor.core.modules.ModuleActor) Consumer(im.actor.runtime.function.Consumer) FileReference(im.actor.core.entity.FileReference) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChangedObsolete(im.actor.core.api.updates.UpdateGroupAvatarChangedObsolete) RpcCallback(im.actor.core.network.RpcCallback) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) UploadManager(im.actor.core.modules.file.UploadManager) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) SeqUpdate(im.actor.core.api.base.SeqUpdate) RequestEditGroupAvatar(im.actor.core.api.rpc.RequestEditGroupAvatar) ApiFileLocation(im.actor.core.api.ApiFileLocation) UpdateGroupAvatarChanged(im.actor.core.api.updates.UpdateGroupAvatarChanged) AvatarUploadState(im.actor.core.viewmodel.AvatarUploadState) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer)

Example 27 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class GroupInfoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    chatId = getArguments().getInt(EXTRA_CHAT_ID);
    groupVM = groups().get(chatId);
    View res = inflater.inflate(R.layout.fragment_group, container, false);
    listView = (RecyclerListView) res.findViewById(R.id.groupList);
    notMemberView = res.findViewById(R.id.notMember);
    res.setBackgroundColor(style.getMainBackgroundColor());
    // listView.setBackgroundColor(style.getMainBackgroundColor());
    notMemberView.setBackgroundColor(style.getMainBackgroundColor());
    ((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
    // 
    // Header
    // 
    // Views
    View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
    TextView title = (TextView) header.findViewById(R.id.title);
    TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
    avatarView = (AvatarView) header.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(48), 22);
    TextView aboutTV = (TextView) header.findViewById(R.id.about);
    View shortNameCont = header.findViewById(R.id.shortNameContainer);
    TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
    TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
    TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
    addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
    TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
    TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
    TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
    View descriptionContainer = header.findViewById(R.id.descriptionContainer);
    SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
    // Styling
    // ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
    header.setBackgroundColor(style.getMainBackgroundColor());
    header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    title.setTextColor(style.getProfileTitleColor());
    subtitle.setTextColor(style.getProfileSubtitleColor());
    aboutTV.setTextColor(style.getTextPrimaryColor());
    shortNameView.setTextColor(style.getTextPrimaryColor());
    shortLinkView.setTextColor(style.getTextSecondaryColor());
    // settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    ((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
    ((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
    ((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
    ((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
    members.setTextColor(style.getTextPrimaryColor());
    administrationAction.setTextColor(style.getTextPrimaryColor());
    leaveAction.setTextColor(style.getTextDangerColor());
    if (groupVM.getGroupType() == GroupType.CHANNEL) {
        leaveAction.setText(R.string.group_leave_channel);
    } else {
        leaveAction.setText(R.string.group_leave);
    }
    header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
    // 
    // Header
    // 
    avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
    avatarView.setOnClickListener(view -> {
        if (groupVM.getAvatar().get() != null) {
            startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
        }
    });
    bind(groupVM.getName(), name -> {
        title.setText(name);
    });
    bind(groupVM.getMembersCount(), val -> {
        subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
    });
    // About
    bind(groupVM.getAbout(), (about) -> {
        aboutTV.setText(about);
        aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
    });
    bind(groupVM.getShortName(), shortName -> {
        if (shortName != null) {
            shortNameView.setText("@" + shortName);
            String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
            if (prefix != null) {
                shortLinkView.setText(prefix + shortName);
                shortLinkView.setVisibility(View.VISIBLE);
            } else {
                shortLinkView.setVisibility(View.GONE);
            }
        }
        shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
    });
    final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    shortNameCont.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String link = shortLinkView.getText().toString();
            clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
            Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
        }
    });
    bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
        descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
    });
    // Notifications
    isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
    isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
        messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
    });
    header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
        isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
    });
    // Add Member
    bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
        if (canInvite) {
            addMember.setVisibility(View.VISIBLE);
        } else {
            addMember.setVisibility(View.GONE);
        }
    });
    addMember.setOnClickListener(view -> {
        startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
    });
    // Administration
    if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
        administrationAction.setOnClickListener(view -> {
            startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
        });
    } else {
        administrationAction.setVisibility(View.GONE);
    }
    // Async Members
    // Showing member only when members available and async members is enabled
    bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
        if (canViewMembers) {
            if (isAsync) {
                members.setVisibility(View.VISIBLE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
            } else {
                members.setVisibility(View.GONE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
            }
        } else {
            members.setVisibility(View.GONE);
            header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
        }
    });
    members.setOnClickListener(view -> {
        startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
    });
    // Leave
    bind(groupVM.getIsCanLeave(), canLeave -> {
        if (canLeave) {
            leaveAction.setVisibility(View.VISIBLE);
            leaveAction.setOnClickListener(view1 -> {
                new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
                    execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
                }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
            });
        } else {
            leaveAction.setVisibility(View.GONE);
        }
    });
    listView.addHeaderView(header, null, false);
    // 
    // Members
    // 
    groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
    listView.setAdapter(groupUserAdapter);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        Object item = parent.getItemAtPosition(position);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
                }
            }
        }
    });
    listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
        Object item = adapterView.getItemAtPosition(i);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
                    return true;
                }
            }
        }
        return false;
    });
    // 
    // Scroll handling
    // 
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem >= 1) {
                updateBar(Integer.MAX_VALUE);
            } else {
                View top = listView.getChildAt(0);
                if (top != null) {
                    updateBar(-top.getTop());
                } else {
                    updateBar(Integer.MAX_VALUE);
                }
            }
        }
    });
    // 
    // Placeholder
    // 
    bind(groupVM.isMember(), (isMember) -> {
        notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
        getActivity().invalidateOptionsMenu();
    });
    // Menu
    bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
        getActivity().invalidateOptionsMenu();
    });
    return res;
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) Bundle(android.os.Bundle) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) ColorDrawable(android.graphics.drawable.ColorDrawable) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) ClipboardManager(android.content.ClipboardManager) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Intents(im.actor.sdk.controllers.Intents) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) GroupMember(im.actor.core.entity.GroupMember) UserPhone(im.actor.core.viewmodel.UserPhone) SwitchCompat(android.support.v7.widget.SwitchCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) ActorStyle(im.actor.sdk.ActorStyle) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) TintImageView(im.actor.sdk.view.TintImageView) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActionBar(android.support.v7.app.ActionBar) GroupType(im.actor.core.entity.GroupType) ActorSDK(im.actor.sdk.ActorSDK) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) AbsListView(android.widget.AbsListView) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) Color(android.graphics.Color) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) TintImageView(im.actor.sdk.view.TintImageView) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) TextView(android.widget.TextView) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) AbsListView(android.widget.AbsListView) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 28 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class RouterActor method onMessageRead.

// 
// Read States
// 
private Promise<Void> onMessageRead(Peer peer, long date) {
    ConversationState state = conversationStates.getValue(peer.getUnuqueId());
    boolean isChanged = false;
    Promise<Void> res;
    if (date > state.getOutReadDate()) {
        state = state.changeOutReadDate(date);
        res = getDialogsRouter().onPeerReadChanged(peer, date);
        isChanged = true;
    } else {
        res = Promise.success(null);
    }
    if (date > state.getOutReceiveDate()) {
        state = state.changeOutReceiveDate(date);
        isChanged = true;
    }
    if (isChanged) {
        conversationStates.addOrUpdateItem(state);
    }
    return res;
}
Also used : ConversationState(im.actor.core.entity.ConversationState) Void(im.actor.runtime.actors.messages.Void)

Example 29 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class RouterActor method preStart.

@Override
public void preStart() {
    super.preStart();
    conversationStates = context().getMessagesModule().getConversationStates().getEngine();
    // 
    // Loading Active Dialogs
    // 
    activeDialogStorage = new ActiveDialogStorage();
    byte[] data = context().getStorageModule().getBlobStorage().loadItem(AbsModule.BLOB_DIALOGS_ACTIVE);
    if (data != null) {
        try {
            activeDialogStorage = new ActiveDialogStorage(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if (!activeDialogStorage.isLoaded()) {
        api(new RequestLoadGroupedDialogs(ApiSupportConfiguration.OPTIMIZATIONS)).chain(r -> updates().applyRelatedData(r.getUsers(), r.getGroups())).chain(r -> updates().loadRequiredPeers(r.getUserPeers(), r.getGroupPeers())).then(r -> {
            boolean showArchived = false;
            boolean showInvite = false;
            if (r.showArchived() != null) {
                showArchived = r.showArchived();
            }
            if (r.showInvite() != null) {
                showInvite = r.showInvite();
            }
            onActiveDialogsChanged(r.getDialogs(), showArchived, showInvite);
            context().getConductor().getConductor().onDialogsLoaded();
        });
    } else {
        notifyActiveDialogsVM();
        context().getConductor().getConductor().onDialogsLoaded();
    }
}
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) ActiveDialogStorage(im.actor.core.modules.messaging.router.entity.ActiveDialogStorage) RequestLoadGroupedDialogs(im.actor.core.api.rpc.RequestLoadGroupedDialogs) IOException(java.io.IOException)

Example 30 with Void

use of im.actor.runtime.actors.messages.Void in project actor-platform by actorapp.

the class RouterActor method onNewMessages.

// 
// Incoming Messages
// 
private Promise<Void> onNewMessages(Peer peer, List<Message> messages) {
    assertTrue(messages.size() != 0);
    boolean isConversationVisible = isConversationVisible(peer);
    // 
    // Collecting Information
    // 
    ConversationState state = conversationStates.getValue(peer.getUnuqueId());
    Message topMessage = null;
    int unreadCount = 0;
    long maxInReadDate = 0;
    long maxInDate = 0;
    for (Message m : messages) {
        if (topMessage == null || topMessage.getSortDate() < m.getSortDate()) {
            topMessage = m;
        }
        if (m.getSenderId() != myUid()) {
            if (m.getSortDate() > state.getInReadDate()) {
                unreadCount++;
                maxInReadDate = Math.max(maxInReadDate, m.getSortDate());
            }
            if (m.getSortDate() > state.getInMaxMessageDate()) {
                maxInDate = Math.max(maxInDate, m.getSortDate());
            }
        }
    }
    // 
    // Writing to Conversation
    // 
    conversation(peer).addOrUpdateItems(messages);
    // 
    // Update Chat State
    // 
    updateChatState(peer);
    // 
    // Updating Counter
    // 
    boolean isRead = false;
    if (unreadCount != 0) {
        if (isConversationVisible) {
            // Auto Reading message
            boolean needUpdateState = false;
            if (maxInReadDate > 0) {
                if (state.getInReadDate() < maxInReadDate) {
                    state = state.changeInReadDate(maxInReadDate);
                }
                state = state.changeCounter(0);
                context().getMessagesModule().getPlainReadActor().send(new CursorReaderActor.MarkRead(peer, maxInReadDate));
                context().getNotificationsModule().onOwnRead(peer, maxInReadDate);
                isRead = true;
                needUpdateState = true;
            }
            if (state.getInMaxMessageDate() < maxInDate) {
                state.changeInMaxDate(maxInDate);
                needUpdateState = true;
            }
            if (needUpdateState) {
                conversationStates.addOrUpdateItem(state);
            }
        } else {
            // Updating counter
            state = state.changeCounter(state.getUnreadCount() + unreadCount);
            if (state.getInMaxMessageDate() < maxInDate) {
                state = state.changeInMaxDate(maxInDate);
            }
            conversationStates.addOrUpdateItem(state);
            notifyActiveDialogsVM();
        }
    }
    // 
    if (maxInReadDate > 0 && !isRead) {
        context().getMessagesModule().getPlainReceiverActor().send(new CursorReceiverActor.MarkReceived(peer, maxInReadDate));
    }
    // 
    // Updating Dialog List
    // 
    Promise<Void> res = getDialogsRouter().onMessage(peer, topMessage, state.getUnreadCount());
    // 
    if (!isConversationVisible) {
        for (Message m : messages) {
            if (m.getSenderId() != myUid()) {
                boolean hasCurrentMention = false;
                if (m.getContent() instanceof TextContent) {
                    if (((TextContent) m.getContent()).getMentions().contains(myUid())) {
                        hasCurrentMention = true;
                    }
                }
                int messagesCount = 0;
                int dialogsCount = 0;
                for (Peer activePeer : activeDialogStorage.getAllPeers()) {
                    int activeDialogueUnreadCount = conversationStates.getValue(activePeer.getUnuqueId()).getUnreadCount();
                    if (activeDialogueUnreadCount > 0) {
                        dialogsCount++;
                        messagesCount += activeDialogueUnreadCount;
                    }
                }
                context().getNotificationsModule().onInMessage(peer, m.getSenderId(), m.getSortDate(), ContentDescription.fromContent(m.getContent()), hasCurrentMention, messagesCount, dialogsCount);
            }
        }
    }
    return res;
}
Also used : UpdateMessage(im.actor.core.api.updates.UpdateMessage) Message(im.actor.core.entity.Message) RouterOutgoingMessage(im.actor.core.modules.messaging.router.entity.RouterOutgoingMessage) Peer(im.actor.core.entity.Peer) ConversationState(im.actor.core.entity.ConversationState) CursorReaderActor(im.actor.core.modules.messaging.actions.CursorReaderActor) CursorReceiverActor(im.actor.core.modules.messaging.actions.CursorReceiverActor) Void(im.actor.runtime.actors.messages.Void) TextContent(im.actor.core.entity.content.TextContent)

Aggregations

Void (im.actor.runtime.actors.messages.Void)37 ModuleContext (im.actor.core.modules.ModuleContext)16 ModuleActor (im.actor.core.modules.ModuleActor)15 RpcException (im.actor.core.network.RpcException)15 CommandCallback (im.actor.core.viewmodel.CommandCallback)15 ArrayList (java.util.ArrayList)15 List (java.util.List)13 Log (im.actor.runtime.Log)12 Promise (im.actor.runtime.promise.Promise)11 Peer (im.actor.core.entity.Peer)10 UsedByApp (im.actor.core.js.annotations.UsedByApp)9 JsPromiseExecutor (im.actor.runtime.js.utils.JsPromiseExecutor)9 Message (im.actor.core.entity.Message)8 UserVM (im.actor.core.viewmodel.UserVM)8 Update (im.actor.core.network.parser.Update)7 HashSet (java.util.HashSet)7 Group (im.actor.core.entity.Group)6 User (im.actor.core.entity.User)6 ApiSupportConfiguration (im.actor.core.modules.api.ApiSupportConfiguration)6 AlertDialog (android.app.AlertDialog)5