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;
}
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;
}
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;
}
Aggregations