Search in sources :

Example 1 with UserVM

use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.

the class JsFacade method findUsers.

@UsedByApp
public JsPromise findUsers(final String query) {
    return JsPromise.create(new JsPromiseExecutor() {

        @Override
        public void execute() {
            messenger.findUsers(query).start(new CommandCallback<UserVM[]>() {

                @Override
                public void onResult(UserVM[] users) {
                    Log.d(TAG, "findUsers:result");
                    JsArray<JsUser> jsUsers = JsArray.createArray().cast();
                    for (UserVM user : users) {
                        jsUsers.push(messenger.getJsUser(user.getId()).get());
                    }
                    resolve(jsUsers);
                }

                @Override
                public void onError(Exception e) {
                    Log.d(TAG, "findUsers:error");
                    reject(e.getMessage());
                }
            });
        }
    });
}
Also used : JsPromiseExecutor(im.actor.runtime.js.utils.JsPromiseExecutor) UserVM(im.actor.core.viewmodel.UserVM) CommandCallback(im.actor.core.viewmodel.CommandCallback) RpcException(im.actor.core.network.RpcException) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Example 2 with UserVM

use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.

the class GlobalSearchSource method loadGlobalResults.

private void loadGlobalResults(String query, ArrayList<SearchResult> localResults, Consumer<List<SearchResult>> callback) {
    context().getSearchModule().findPeers(query).then(r -> {
        ArrayList<SearchResult> results = new ArrayList<>();
        outer: for (PeerSearchEntity peerSearch : r) {
            for (SearchResult l : localResults) {
                if (peerSearch.getPeer().equals(l.getPeer())) {
                    continue outer;
                }
            }
            if (peerSearch.getPeer().getPeerType() == PeerType.GROUP) {
                Group group = context().getGroupsModule().getGroups().getValue(peerSearch.getPeer().getPeerId());
                results.add(new SearchResult(peerSearch.getPeer(), group.getAvatar(), group.getTitle(), peerSearch.getOptMatchString()));
            } else if (peerSearch.getPeer().getPeerType() == PeerType.PRIVATE) {
                UserVM user = context().getUsersModule().getUsers().get(peerSearch.getPeer().getPeerId());
                results.add(new SearchResult(peerSearch.getPeer(), user.getAvatar().get(), user.getName().get(), peerSearch.getOptMatchString()));
            }
        }
        if (results.size() > 0) {
            ArrayList<SearchResult> combined = new ArrayList<>();
            combined.addAll(localResults);
            combined.addAll(results);
            callback.apply(combined);
        }
    });
}
Also used : Group(im.actor.core.entity.Group) PeerSearchEntity(im.actor.core.entity.PeerSearchEntity) UserVM(im.actor.core.viewmodel.UserVM) ArrayList(java.util.ArrayList) SearchResult(im.actor.core.entity.SearchResult)

Example 3 with UserVM

use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.

the class PresenceActor method onUserGoesOffline.

private void onUserGoesOffline(int uid, int date, long updateDate) {
    // Log.d(TAG, "onUserGoesOffline  #" + uid + " at " + date + " at " + updateDate);
    if (lastUidState.containsKey(uid) && lastUidState.get(uid) >= updateDate) {
        // Log.d(TAG, "onUserGoesOffline:ignored - too old");
        return;
    }
    lastUidState.put(uid, updateDate);
    // Log.d(TAG, "onUserGoesOffline:updated");
    UserVM vm = getUserVM(uid);
    if (vm != null) {
        vm.getPresence().change(new UserPresence(UserPresence.State.OFFLINE, date));
    }
    // Cancel timeout
    if (uidCancellables.containsKey(uid)) {
        uidCancellables.remove(uid).cancel();
    }
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) UserPresence(im.actor.core.viewmodel.UserPresence)

Example 4 with UserVM

use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.

the class ChatFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    findInputBar().setText(messenger().loadDraft(peer), true);
    if (peer.getPeerType() == PeerType.PRIVATE) {
        UserVM userVM = users().get(peer.getPeerId());
        if (userVM.isBot()) {
            ConversationVM conversationVM = messenger().getConversationVM(peer);
            bind(conversationVM.getIsEmpty(), conversationVM.getIsLoaded(), (isEmpty, valueModel, isLoaded, valueModel2) -> {
                if (isEmpty) {
                    inputOverlayText.setText(R.string.chat_empty_bot);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
                if (isEmpty && isLoaded) {
                    showView(emptyContainer, false);
                } else {
                    hideView(emptyContainer, false);
                }
            });
            bind(userVM.getAbout(), (val, valueModel) -> {
                if (val == null) {
                    findEmptyPlaceholder().setText(getString(R.string.chat_empty_bot_about));
                } else {
                    findEmptyPlaceholder().setText(val);
                }
            });
        } else {
            bind(userVM.getIsBlocked(), (val, valueModel) -> {
                if (val) {
                    inputOverlayText.setText(R.string.blocked_unblock);
                    inputOverlayText.setTextColor(style.getListActionColor());
                    inputOverlayText.setClickable(true);
                    showView(inputOverlayContainer, false);
                    goneView(inputContainer, false);
                } else {
                    goneView(inputOverlayContainer, false);
                    showView(inputContainer, false);
                }
            });
        }
    } else if (peer.getPeerType() == PeerType.GROUP) {
        GroupVM groupVM = groups().get(peer.getPeerId());
        bind(groupVM.isMember(), groupVM.getIsCanWriteMessage(), (isMember, valueModel, canWriteMessage, valueModel2) -> {
            if (canWriteMessage) {
                goneView(inputOverlayContainer, false);
                showView(inputContainer, false);
            } else if (isMember) {
                if (messenger().isNotificationsEnabled(peer)) {
                    inputOverlayText.setText(getString(R.string.chat_mute));
                } else {
                    inputOverlayText.setText(getString(R.string.chat_unmute));
                }
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsCanJoin().get()) {
                inputOverlayText.setText(getString(R.string.join));
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(true);
                inputOverlayText.setEnabled(true);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else if (groupVM.getIsDeleted().get()) {
                inputOverlayText.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_deleted : R.string.group_deleted);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            } else {
                inputOverlayText.setText(R.string.chat_not_member);
                inputOverlayText.setTextColor(style.getListActionColor());
                inputOverlayText.setClickable(false);
                inputOverlayText.setEnabled(false);
                showView(inputOverlayContainer, false);
                goneView(inputContainer, false);
            }
        });
    }
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) ConversationVM(im.actor.core.viewmodel.ConversationVM) InputBarFragment(im.actor.sdk.controllers.conversation.inputbar.InputBarFragment) Bundle(android.os.Bundle) ValueDoubleChangedListener(im.actor.runtime.mvvm.ValueDoubleChangedListener) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) ValueListener(im.actor.runtime.mvvm.ValueListener) GroupVM(im.actor.core.viewmodel.GroupVM) QuoteCallback(im.actor.sdk.controllers.conversation.quote.QuoteCallback) AutocompleteFragment(im.actor.sdk.controllers.conversation.mentions.AutocompleteFragment) AttachFragment(im.actor.sdk.controllers.conversation.attach.AttachFragment) Toast(android.widget.Toast) AbsAttachFragment(im.actor.sdk.controllers.conversation.attach.AbsAttachFragment) View(android.view.View) AutocompleteCallback(im.actor.sdk.controllers.conversation.mentions.AutocompleteCallback) GroupType(im.actor.core.entity.GroupType) PeerType(im.actor.core.entity.PeerType) Sticker(im.actor.core.entity.Sticker) ActorSDK(im.actor.sdk.ActorSDK) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) MessagesDefaultFragment(im.actor.sdk.controllers.conversation.messages.MessagesDefaultFragment) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) InputBarCallback(im.actor.sdk.controllers.conversation.inputbar.InputBarCallback) MessagesFragmentCallback(im.actor.sdk.controllers.conversation.messages.MessagesFragmentCallback) ViewGroup(android.view.ViewGroup) RpcException(im.actor.core.network.RpcException) EmptyChatPlaceholder(im.actor.sdk.controllers.conversation.placeholder.EmptyChatPlaceholder) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) TextView(android.widget.TextView) QuoteFragment(im.actor.sdk.controllers.conversation.quote.QuoteFragment) Configuration(android.content.res.Configuration) Peer(im.actor.core.entity.Peer) Nullable(android.support.annotation.Nullable) Activity(android.app.Activity) ValueChangedListener(im.actor.runtime.mvvm.ValueChangedListener) Value(im.actor.runtime.mvvm.Value) ChatToolbarFragment(im.actor.sdk.controllers.conversation.toolbar.ChatToolbarFragment) UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) ConversationVM(im.actor.core.viewmodel.ConversationVM)

Example 5 with UserVM

use of im.actor.core.viewmodel.UserVM in project actor-platform by actorapp.

the class ChatToolbarFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (peer.getPeerType() == PeerType.PRIVATE) {
        // Loading user
        UserVM user = users().get(peer.getPeerId());
        // Binding User Avatar to Toolbar
        bind(barAvatar, user.getId(), user.getAvatar(), user.getName());
        // Binding User name to Toolbar
        bind(barTitle, user.getName());
        bind(user.getIsVerified(), (val, valueModel) -> {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, val ? new TintDrawable(getResources().getDrawable(R.drawable.ic_verified_user_black_18dp), ActorSDK.sharedActor().style.getVerifiedColor()) : null, null);
        });
        // Binding User presence to Toolbar
        bind(barSubtitle, user);
        // Binding User typing to Toolbar
        bindPrivateTyping(barTyping, barTypingContainer, barSubtitle, messenger().getTyping(user.getId()));
        // Refresh menu on contact state change
        bind(user.isContact(), (val, valueModel) -> {
            getActivity().invalidateOptionsMenu();
        });
    } else if (peer.getPeerType() == PeerType.GROUP) {
        // Loading group
        GroupVM group = groups().get(peer.getPeerId());
        // Binding Group avatar to Toolbar
        bind(barAvatar, group.getId(), group.getAvatar(), group.getName());
        // Binding Group title to Toolbar
        bind(barTitle, group.getName());
        if (group.getGroupType() == GroupType.CHANNEL) {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(new TintDrawable(getResources().getDrawable(R.drawable.ic_megaphone_18dp_black), Color.WHITE), null, null, null);
        } else {
            barTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
        // Subtitle is always visible for Groups
        barSubtitleContainer.setVisibility(View.VISIBLE);
        // Binding group members
        bind(barSubtitle, barSubtitleContainer, group);
        // Binding group typing
        if (group.getGroupType() == GroupType.GROUP) {
            bindGroupTyping(barTyping, barTypingContainer, barSubtitle, messenger().getGroupTyping(group.getId()));
        }
    }
    // Global Counter
    bind(messenger().getGlobalState().getGlobalCounter(), (val, valueModel) -> {
        if (val != null && val > 0) {
            counter.setText(Integer.toString(val));
            showView(counter);
        } else {
            hideView(counter);
        }
    });
}
Also used : UserVM(im.actor.core.viewmodel.UserVM) GroupVM(im.actor.core.viewmodel.GroupVM) TintDrawable(im.actor.sdk.view.TintDrawable)

Aggregations

UserVM (im.actor.core.viewmodel.UserVM)30 View (android.view.View)12 TextView (android.widget.TextView)12 GroupVM (im.actor.core.viewmodel.GroupVM)11 CommandCallback (im.actor.core.viewmodel.CommandCallback)9 ArrayList (java.util.ArrayList)8 Intent (android.content.Intent)7 Peer (im.actor.core.entity.Peer)7 AlertDialog (android.app.AlertDialog)6 ViewGroup (android.view.ViewGroup)6 Void (im.actor.runtime.actors.messages.Void)6 ActorSDK (im.actor.sdk.ActorSDK)6 R (im.actor.sdk.R)6 ActorSDKMessenger.messenger (im.actor.sdk.util.ActorSDKMessenger.messenger)6 ActorSDKMessenger.users (im.actor.sdk.util.ActorSDKMessenger.users)6 AvatarView (im.actor.sdk.view.avatar.AvatarView)6 Context (android.content.Context)5 Bundle (android.os.Bundle)5 MenuItem (android.view.MenuItem)5 GroupMember (im.actor.core.entity.GroupMember)5