Search in sources :

Example 1 with Group

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

the class GroupRouter method editDescGroup.

private Promise<Void> editDescGroup(int groupId, Function<Group, Group> func) {
    return forGroup(groupId, group -> {
        Group g = func.apply(group);
        groups().addOrUpdateItem(g);
        return onGroupDescChanged(g);
    });
}
Also used : RouterLoadFullGroup(im.actor.core.modules.groups.router.entity.RouterLoadFullGroup) ApiGroup(im.actor.core.api.ApiGroup) Group(im.actor.core.entity.Group)

Example 2 with Group

use of im.actor.core.entity.Group 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 3 with Group

use of im.actor.core.entity.Group 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 4 with Group

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

the class RouterActor method notifyActiveDialogsVM.

private void notifyActiveDialogsVM() {
    int counter = 0;
    ArrayList<DialogGroup> groups = new ArrayList<>();
    for (ActiveDialogGroup i : activeDialogStorage.getGroups()) {
        ArrayListDialogSmall dialogSmalls = new ArrayListDialogSmall();
        for (Peer p : i.getPeers()) {
            String title;
            Avatar avatar;
            if (p.getPeerType() == PeerType.GROUP) {
                Group group = getGroup(p.getPeerId());
                title = group.getTitle();
                avatar = group.getAvatar();
            } else if (p.getPeerType() == PeerType.PRIVATE) {
                User user = getUser(p.getPeerId());
                title = user.getName();
                avatar = user.getAvatar();
            } else {
                continue;
            }
            int unreadCount = conversationStates.getValue(p.getUnuqueId()).getUnreadCount();
            counter += unreadCount;
            dialogSmalls.add(new DialogSmall(p, title, avatar, unreadCount));
        }
        groups.add(new DialogGroup(i.getTitle(), i.getKey(), dialogSmalls));
    }
    context().getMessagesModule().getDialogGroupsVM().getGroupsValueModel().change(groups);
    context().getConductor().getGlobalStateVM().onGlobalCounterChanged(counter);
}
Also used : ApiDialogGroup(im.actor.core.api.ApiDialogGroup) Group(im.actor.core.entity.Group) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) User(im.actor.core.entity.User) ApiDialogGroup(im.actor.core.api.ApiDialogGroup) DialogGroup(im.actor.core.viewmodel.DialogGroup) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) Peer(im.actor.core.entity.Peer) ArrayList(java.util.ArrayList) ActiveDialogGroup(im.actor.core.modules.messaging.router.entity.ActiveDialogGroup) DialogSmall(im.actor.core.viewmodel.DialogSmall) ArrayListDialogSmall(im.actor.core.viewmodel.generics.ArrayListDialogSmall) Avatar(im.actor.core.entity.Avatar)

Example 5 with Group

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

the class PresenceActor method subscribe.

@Verified
private void subscribe(Peer peer) {
    if (peer.getPeerType() == PeerType.PRIVATE) {
        // Already subscribed
        if (uids.contains(peer.getPeerId())) {
            return;
        }
        User user = getUser(peer.getPeerId());
        if (user == null) {
            return;
        }
        // Subscribing to user online sates
        uids.add(user.getUid());
    } else if (peer.getPeerType() == PeerType.GROUP) {
        // Already subscribed
        if (gids.contains(peer.getPeerId())) {
            return;
        }
        Group group = getGroup(peer.getPeerId());
        if (group == null) {
            return;
        }
        // Ignore subscription to channels
        if (group.getGroupType() == GroupType.CHANNEL) {
            return;
        }
        // Subscribing to group online sates
        gids.add(peer.getPeerId());
    } else {
        return;
    }
    // Adding Pending Peer
    if (pendingPeers.contains(peer)) {
        return;
    }
    pendingPeers.add(peer);
    onCheckQueue();
}
Also used : Group(im.actor.core.entity.Group) User(im.actor.core.entity.User) Verified(im.actor.runtime.annotations.Verified)

Aggregations

Group (im.actor.core.entity.Group)12 User (im.actor.core.entity.User)8 ArrayList (java.util.ArrayList)8 ModuleContext (im.actor.core.modules.ModuleContext)6 Peer (im.actor.core.entity.Peer)5 Void (im.actor.runtime.actors.messages.Void)5 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)4 GroupMember (im.actor.core.entity.GroupMember)4 ModuleActor (im.actor.core.modules.ModuleActor)4 Promise (im.actor.runtime.promise.Promise)4 PeerType (im.actor.core.entity.PeerType)3 PeerChatOpened (im.actor.core.events.PeerChatOpened)3 ActorRef (im.actor.runtime.actors.ActorRef)3 BusSubscriber (im.actor.runtime.eventbus.BusSubscriber)3 Event (im.actor.runtime.eventbus.Event)3 Function (im.actor.runtime.function.Function)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ApiDialogGroup (im.actor.core.api.ApiDialogGroup)2 ApiGroup (im.actor.core.api.ApiGroup)2