Search in sources :

Example 1 with GroupMember

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);
}
Also used : Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) User(im.actor.core.entity.User) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage) ApiTextMessage(im.actor.core.api.ApiTextMessage) Message(im.actor.core.entity.Message) ApiDocumentMessage(im.actor.core.api.ApiDocumentMessage) RequestSendMessage(im.actor.core.api.rpc.RequestSendMessage) ApiMessage(im.actor.core.api.ApiMessage) ApiJsonMessage(im.actor.core.api.ApiJsonMessage) TextContent(im.actor.core.entity.content.TextContent) PendingMessage(im.actor.core.modules.messaging.actions.entity.PendingMessage)

Example 2 with GroupMember

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);
}
Also used : AlertDialog(android.app.AlertDialog) GroupMember(im.actor.core.entity.GroupMember) UserVM(im.actor.core.viewmodel.UserVM) DialogInterface(android.content.DialogInterface) Void(im.actor.runtime.actors.messages.Void)

Example 3 with GroupMember

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;
}
Also used : MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) GroupVM(im.actor.core.viewmodel.GroupVM) DividerView(im.actor.sdk.view.DividerView) CircularProgressBar(fr.castorflex.android.circularprogressbar.CircularProgressBar) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) AdapterView(android.widget.AdapterView) DividerView(im.actor.sdk.view.DividerView) TextView(android.widget.TextView) UserVM(im.actor.core.viewmodel.UserVM) FrameLayout(android.widget.FrameLayout) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout) Nullable(android.support.annotation.Nullable)

Example 4 with GroupMember

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);
}
Also used : GroupMember(im.actor.core.entity.GroupMember) ArrayList(java.util.ArrayList) Avatar(im.actor.core.entity.Avatar)

Example 5 with GroupMember

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;
}
Also used : Group(im.actor.core.entity.Group) GroupMember(im.actor.core.entity.GroupMember) User(im.actor.core.entity.User) MentionFilterResult(im.actor.core.entity.MentionFilterResult) ArrayList(java.util.ArrayList) StringMatch(im.actor.core.util.StringMatch)

Aggregations

GroupMember (im.actor.core.entity.GroupMember)9 ArrayList (java.util.ArrayList)5 Group (im.actor.core.entity.Group)4 User (im.actor.core.entity.User)4 UserVM (im.actor.core.viewmodel.UserVM)4 Void (im.actor.runtime.actors.messages.Void)4 Peer (im.actor.core.entity.Peer)3 GroupVM (im.actor.core.viewmodel.GroupVM)3 AlertDialog (android.app.AlertDialog)2 Intent (android.content.Intent)2 ApiOutPeer (im.actor.core.api.ApiOutPeer)2 ApiPeerType (im.actor.core.api.ApiPeerType)2 PeerType (im.actor.core.entity.PeerType)2 PeerChatOpened (im.actor.core.events.PeerChatOpened)2 AbsModule (im.actor.core.modules.AbsModule)2 ModuleContext (im.actor.core.modules.ModuleContext)2 CommandCallback (im.actor.core.viewmodel.CommandCallback)2 Storage (im.actor.runtime.Storage)2 ActorRef (im.actor.runtime.actors.ActorRef)2 ActorSystem.system (im.actor.runtime.actors.ActorSystem.system)2