Search in sources :

Example 1 with MentionFilterResult

use of im.actor.core.entity.MentionFilterResult in project actor-platform by actorapp.

the class JsFacade method findMentions.

@UsedByApp
public JsArray<JsMentionFilterResult> findMentions(int gid, String query) {
    List<MentionFilterResult> res = messenger.findMentions(gid, query);
    JsArray<JsMentionFilterResult> mentions = JsArray.createArray().cast();
    for (MentionFilterResult m : res) {
        mentions.push(JsMentionFilterResult.create(m));
    }
    return mentions;
}
Also used : MentionFilterResult(im.actor.core.entity.MentionFilterResult) UsedByApp(im.actor.core.js.annotations.UsedByApp)

Example 2 with MentionFilterResult

use of im.actor.core.entity.MentionFilterResult in project actor-platform by actorapp.

the class MentionsModule method findMentions.

public List<MentionFilterResult> findMentions(int gid, String query) {
    query = query.trim().toLowerCase();
    ArrayList<MentionFilterResult> results = new ArrayList<MentionFilterResult>();
    final Group group = groups().getValue(gid);
    GroupMember[] members = group.getMembers().toArray(new GroupMember[group.getMembers().size()]);
    Arrays.sort(members, (a, b) -> {
        User ua = users().getValue(a.getUid());
        User ub = users().getValue(b.getUid());
        return ua.getName().compareToIgnoreCase(ub.getName());
    });
    for (GroupMember member : members) {
        if (member.getUid() == myUid()) {
            continue;
        }
        User user = users().getValue(member.getUid());
        boolean isNick = user.getNick() != null;
        String mention;
        String secondName;
        if (isNick) {
            mention = user.getNick();
            secondName = user.getName();
        } else {
            if (user.getLocalName() != null) {
                mention = user.getServerName();
                secondName = user.getLocalName();
            } else {
                mention = user.getName();
                secondName = null;
            }
        }
        if (query.length() == 0) {
            results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), isNick ? "@" + mention : mention, new ArrayList<>(), secondName, new ArrayList<>(), isNick));
        } else {
            List<StringMatch> mentionMatches = StringMatcher.findMatches(mention, query);
            if (secondName != null) {
                List<StringMatch> secondNameMatches = StringMatcher.findMatches(secondName, query);
                if (mentionMatches.size() > 0 || secondNameMatches.size() > 0) {
                    if (isNick) {
                        List<StringMatch> nickMatches = new ArrayList<>();
                        for (StringMatch m : mentionMatches) {
                            nickMatches.add(new StringMatch(m.getStart() + 1, m.getLength()));
                        }
                        mentionMatches = nickMatches;
                    }
                    results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), isNick ? "@" + mention : mention, mentionMatches, secondName, secondNameMatches, isNick));
                }
            } else {
                if (mentionMatches.size() > 0) {
                    results.add(new MentionFilterResult(user.getUid(), user.getAvatar(), mention, mentionMatches, null, null, false));
                }
            }
        }
    }
    if (results.size() > SEARCH_LIMIT) {
        results.clear();
    }
    return results;
}
Also used : Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) User(im.actor.core.entity.User) ArrayList(java.util.ArrayList) MentionFilterResult(im.actor.core.entity.MentionFilterResult) StringMatch(im.actor.core.util.StringMatch)

Example 3 with MentionFilterResult

use of im.actor.core.entity.MentionFilterResult in project actor-platform by actorapp.

the class AutocompleteFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    autocompleteList = new BottomSheetListView(getContext());
    autocompleteList.setVisibility(View.INVISIBLE);
    autocompleteList.setUnderlyingView(underlyingView);
    autocompleteList.setDivider(null);
    autocompleteList.setDividerHeight(0);
    autocompleteList.setBackgroundColor(Color.TRANSPARENT);
    if (autocompleteAdapter != null) {
        autocompleteList.setAdapter(autocompleteAdapter);
    }
    autocompleteList.setOnItemClickListener((adapterView, view, i, l) -> {
        Object item = autocompleteAdapter.getItem(i);
        if (item instanceof MentionFilterResult) {
            String mention = ((MentionFilterResult) item).getMentionString();
            Fragment parent = getParentFragment();
            if (parent instanceof AutocompleteCallback) {
                ((AutocompleteCallback) parent).onMentionPicked(mention);
            }
        } else if (item instanceof BotCommand) {
            String command = ((BotCommand) item).getSlashCommand();
            Fragment parent = getParentFragment();
            if (parent instanceof AutocompleteCallback) {
                ((AutocompleteCallback) parent).onCommandPicked(command);
            }
        }
    });
    // Initial zero height
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.BOTTOM;
    autocompleteList.setLayoutParams(params);
    return autocompleteList;
}
Also used : BotCommand(im.actor.core.entity.BotCommand) FrameLayout(android.widget.FrameLayout) MentionFilterResult(im.actor.core.entity.MentionFilterResult) BottomSheetListView(im.actor.sdk.view.adapters.BottomSheetListView) BaseFragment(im.actor.sdk.controllers.BaseFragment) Fragment(android.support.v4.app.Fragment) Nullable(android.support.annotation.Nullable)

Aggregations

MentionFilterResult (im.actor.core.entity.MentionFilterResult)3 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1 FrameLayout (android.widget.FrameLayout)1 BotCommand (im.actor.core.entity.BotCommand)1 Group (im.actor.core.entity.Group)1 GroupMember (im.actor.core.entity.GroupMember)1 User (im.actor.core.entity.User)1 UsedByApp (im.actor.core.js.annotations.UsedByApp)1 StringMatch (im.actor.core.util.StringMatch)1 BaseFragment (im.actor.sdk.controllers.BaseFragment)1 BottomSheetListView (im.actor.sdk.view.adapters.BottomSheetListView)1 ArrayList (java.util.ArrayList)1