use of im.actor.core.entity.GroupMember in project actor-platform by actorapp.
the class SenderActor method doSendText.
// Sending text
public void doSendText(@NotNull Peer peer, @NotNull String text, @Nullable ArrayList<Integer> mentions, /*Ignored*/
@Nullable String markDownText, boolean autoDetect) {
text = text.trim();
long rid = RandomUtils.nextRid();
long date = createPendingDate();
long sortDate = date + 365 * 24 * 60 * 60 * 1000L;
if (autoDetect) {
mentions = new ArrayList<>();
if (peer.getPeerType() == PeerType.GROUP) {
Group group = getGroup(peer.getPeerId());
String lowText = text.toLowerCase();
if (group.getMembers() != null) {
for (GroupMember member : group.getMembers()) {
User user = getUser(member.getUid());
if (user.getNick() != null) {
String nick = "@" + user.getNick().toLowerCase();
// TODO: Better filtering
if (lowText.contains(nick + ":") || lowText.contains(nick + " ") || lowText.contains(" " + nick) || lowText.endsWith(nick) || lowText.equals(nick)) {
mentions.add(user.getUid());
}
}
}
}
}
}
TextContent content = TextContent.create(text, null, mentions);
Message message = new Message(rid, sortDate, date, myUid(), MessageState.PENDING, content);
context().getMessagesModule().getRouter().onOutgoingMessage(peer, message);
pendingMessages.getPendingMessages().add(new PendingMessage(peer, rid, content));
savePending();
performSendContent(peer, rid, content);
}
use of im.actor.core.entity.GroupMember in project actor-platform by actorapp.
the class AddMemberFragment method onItemClicked.
@Override
public void onItemClicked(Contact contact) {
final UserVM userModel = users().get(contact.getUid());
for (GroupMember uid : groupVM.getMembers().get()) {
if (uid.getUid() == userModel.getId()) {
Toast.makeText(getActivity(), R.string.toast_already_member, Toast.LENGTH_SHORT).show();
return;
}
}
new AlertDialog.Builder(getActivity()).setMessage(getString(R.string.alert_group_add_text).replace("{0}", userModel.getName().get())).setPositiveButton(R.string.alert_group_add_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog2, int which) {
execute(messenger().inviteMember(groupVM.getId(), userModel.getId()), R.string.progress_common, new CommandCallback<Void>() {
@Override
public void onResult(Void res) {
getActivity().finish();
}
@Override
public void onError(Exception e) {
Toast.makeText(getActivity(), R.string.toast_unable_add, Toast.LENGTH_SHORT).show();
}
});
}
}).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
}
use of im.actor.core.entity.GroupMember in project actor-platform by actorapp.
the class MembersFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View res = inflater.inflate(R.layout.fragment_members, container, false);
int groupId = getArguments().getInt("groupId");
adapter = new MembersAdapter(getContext(), groupId);
GroupVM groupVM = groups().get(groupId);
RecyclerListView list = (RecyclerListView) res.findViewById(R.id.items);
Boolean canInvite = groupVM.getIsCanInviteMembers().get();
Boolean canInviteViaLink = groupVM.getIsCanInviteViaLink().get();
if (canInvite || canInviteViaLink) {
LinearLayout header = new LinearLayout(getActivity());
list.addHeaderView(header);
if (canInvite) {
TextView addMmemberTV = new TextView(getContext());
addMmemberTV.setBackgroundResource(R.drawable.selector);
addMmemberTV.setTextSize(16);
addMmemberTV.setPadding(Screen.dp(72), 0, 0, 0);
addMmemberTV.setGravity(Gravity.CENTER_VERTICAL);
addMmemberTV.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
addMmemberTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
addMmemberTV.setOnClickListener(view -> {
startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupId));
});
header.addView(addMmemberTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
}
if (canInvite && canInviteViaLink) {
header.addView(new DividerView(getActivity()), ViewGroup.LayoutParams.MATCH_PARENT, 1);
}
if (canInviteViaLink) {
TextView shareLinkTV = new TextView(getContext());
shareLinkTV.setBackgroundResource(R.drawable.selector);
shareLinkTV.setTextSize(16);
shareLinkTV.setPadding(Screen.dp(72), 0, 0, 0);
shareLinkTV.setGravity(Gravity.CENTER_VERTICAL);
shareLinkTV.setTextColor(ActorSDK.sharedActor().style.getTextPrimaryColor());
shareLinkTV.setText(R.string.invite_link_action_share);
shareLinkTV.setOnClickListener(view -> Intents.inviteLink(groupId, getActivity()));
header.addView(shareLinkTV, ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(58));
}
}
footer = new LinearLayout(getActivity());
footer.setVisibility(View.INVISIBLE);
list.addFooterView(footer);
CircularProgressBar botProgressView = new CircularProgressBar(getActivity());
int padding = Screen.dp(16);
botProgressView.setPadding(padding, padding, padding, padding);
botProgressView.setIndeterminate(true);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(72));
params.gravity = Gravity.CENTER;
FrameLayout cont = new FrameLayout(getActivity());
cont.addView(botProgressView, params);
footer.addView(cont, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
list.setAdapter(adapter);
list.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()));
}
}
}
});
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long 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) {
adapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
return true;
}
}
}
return false;
}
});
progressView = (CircularProgressBar) res.findViewById(R.id.loadingProgress);
progressView.setIndeterminate(true);
return res;
}
use of im.actor.core.entity.GroupMember in project actor-platform by actorapp.
the class JsGroup method fromGroupVM.
public static JsGroup fromGroupVM(GroupVM groupVM, JsMessenger messenger) {
int online = groupVM.getPresence().get();
String presence = messenger.getFormatter().formatGroupMembers(groupVM.getMembersCount().get());
if (online > 0) {
presence += ", " + messenger.getFormatter().formatGroupOnline(online);
}
String fileUrl = null;
String bigFileUrl = null;
Avatar avatar = groupVM.getAvatar().get();
if (avatar != null) {
if (avatar.getSmallImage() != null) {
fileUrl = messenger.getFileUrl(avatar.getSmallImage().getFileReference());
}
if (avatar.getLargeImage() != null) {
bigFileUrl = messenger.getFileUrl(avatar.getLargeImage().getFileReference());
}
}
ArrayList<JsGroupMember> convertedMembers = new ArrayList<JsGroupMember>();
HashSet<GroupMember> groupMembers = groupVM.getMembers().get();
GroupMember[] members = groupMembers.toArray(new GroupMember[groupMembers.size()]);
for (GroupMember g : members) {
JsPeerInfo peerInfo = messenger.buildPeerInfo(Peer.user(g.getUid()));
// Log.d("JsGroup", "PeerInfo: " + peerInfo);
convertedMembers.add(JsGroupMember.create(peerInfo, g.isAdministrator(), g.getInviterUid() == messenger.myUid()));
}
Collections.sort(convertedMembers, new Comparator<JsGroupMember>() {
@Override
public int compare(JsGroupMember o1, JsGroupMember o2) {
return o1.getPeerInfo().getTitle().compareToIgnoreCase(o2.getPeerInfo().getTitle());
}
});
JsArray<JsGroupMember> jsMembers = JsArray.createArray().cast();
for (JsGroupMember member : convertedMembers) {
jsMembers.push(member);
}
return create(groupVM.getId(), groupVM.getName().get(), groupVM.getAbout().get(), fileUrl, bigFileUrl, Placeholders.getPlaceholder(groupVM.getId()), presence, jsMembers);
}
use of im.actor.core.entity.GroupMember 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;
}
Aggregations