Search in sources :

Example 1 with User

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

the class ContactsSyncActor method updateEngineList.

private void updateEngineList() {
    if (ENABLE_LOG) {
        Log.d(TAG, "Saving contact EngineList");
    }
    ArrayList<User> userList = new ArrayList<>();
    for (int u : contacts) {
        userList.add(getUser(u));
    }
    Collections.sort(userList, (lhs, rhs) -> lhs.getName().compareTo(rhs.getName()));
    List<Contact> registeredContacts = new ArrayList<>();
    int index = -1;
    for (User userModel : userList) {
        Contact contact = new Contact(userModel.getUid(), (long) index--, userModel.getAvatar(), userModel.getName());
        registeredContacts.add(contact);
    }
    context().getContactsModule().getContacts().replaceItems(registeredContacts);
    Integer[] sorted = new Integer[contacts.size()];
    int sindex = 0;
    for (User userModel : userList) {
        sorted[sindex++] = userModel.getUid();
    }
    context().getSearchModule().onContactsChanged(sorted);
    notifyState();
}
Also used : ApiUser(im.actor.core.api.ApiUser) User(im.actor.core.entity.User) ArrayList(java.util.ArrayList) Contact(im.actor.core.entity.Contact)

Example 2 with User

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

the class UserRouter method checkIsInPhoneBook.

@Verified
protected Promise<Void> checkIsInPhoneBook(User user) {
    if (!config().isEnableOnClientPrivacy()) {
        return Promise.success(null);
    }
    Log.d("ON_CLIENT_PRIVACY", "checking " + user.getName() + " is in phone book");
    return getPhoneBook().flatMap(new Function<List<PhoneBookContact>, Promise<Void>>() {

        @Override
        public Promise<Void> apply(List<PhoneBookContact> phoneBookContacts) {
            return new Promise<Void>(resolver -> {
                List<ContactRecord> userRecords = user.getRecords();
                Log.d("ON_CLIENT_PRIVACY", "phonebook have " + phoneBookContacts.size() + " records");
                Log.d("ON_CLIENT_PRIVACY", "user have " + userRecords.size() + " records");
                outer: for (ContactRecord record : userRecords) {
                    for (PhoneBookContact phoneBookContact : phoneBookContacts) {
                        for (PhoneBookPhone phone1 : phoneBookContact.getPhones()) {
                            if (record.getRecordType() == ContactRecordType.PHONE) {
                                if (record.getRecordData().equals(phone1.getNumber() + "")) {
                                    context().getContactsModule().markInPhoneBook(user.getUid());
                                    getUserVM(user.getUid()).isInPhoneBook().change(true);
                                    Log.d("ON_CLIENT_PRIVACY", "in record book!");
                                    break outer;
                                }
                            }
                        }
                        for (PhoneBookEmail email : phoneBookContact.getEmails()) {
                            if (record.getRecordType() == ContactRecordType.EMAIL) {
                                if (record.getRecordData().equals(email.getEmail())) {
                                    context().getContactsModule().markInPhoneBook(user.getUid());
                                    getUserVM(user.getUid()).isInPhoneBook().change(true);
                                    Log.d("ON_CLIENT_PRIVACY", "in record book!");
                                    break outer;
                                }
                            }
                        }
                    }
                }
                Log.d("ON_CLIENT_PRIVACY", "finish check");
                resolver.result(null);
            });
        }
    });
}
Also used : ModuleContext(im.actor.core.modules.ModuleContext) ContactRecord(im.actor.core.entity.ContactRecord) PhoneBookContact(im.actor.core.entity.PhoneBookContact) ApiUser(im.actor.core.api.ApiUser) UpdateUserContactsChanged(im.actor.core.api.updates.UpdateUserContactsChanged) ApiMapValue(im.actor.core.api.ApiMapValue) ApiBotCommand(im.actor.core.api.ApiBotCommand) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) PromisesArray(im.actor.runtime.promise.PromisesArray) RouterLoadFullUser(im.actor.core.modules.users.router.entity.RouterLoadFullUser) UpdateContactRegistered(im.actor.core.api.updates.UpdateContactRegistered) UpdateUserNameChanged(im.actor.core.api.updates.UpdateUserNameChanged) ContactRecordType(im.actor.core.entity.ContactRecordType) Tuple2(im.actor.runtime.function.Tuple2) UpdateUserBlocked(im.actor.core.api.updates.UpdateUserBlocked) Void(im.actor.runtime.actors.messages.Void) Verified(im.actor.runtime.annotations.Verified) UserPhone(im.actor.core.viewmodel.UserPhone) ResponseLoadFullUsers(im.actor.core.api.rpc.ResponseLoadFullUsers) UpdateUserAvatarChanged(im.actor.core.api.updates.UpdateUserAvatarChanged) List(java.util.List) UpdateUserAboutChanged(im.actor.core.api.updates.UpdateUserAboutChanged) ModuleActor(im.actor.core.modules.ModuleActor) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) UpdateUserFullExtChanged(im.actor.core.api.updates.UpdateUserFullExtChanged) UserEmail(im.actor.core.viewmodel.UserEmail) Peer(im.actor.core.entity.Peer) UpdateUserExtChanged(im.actor.core.api.updates.UpdateUserExtChanged) MessageState(im.actor.core.entity.MessageState) Message(im.actor.core.entity.Message) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiAvatar(im.actor.core.api.ApiAvatar) ApiContactRecord(im.actor.core.api.ApiContactRecord) UpdateUserTimeZoneChanged(im.actor.core.api.updates.UpdateUserTimeZoneChanged) Function(im.actor.runtime.function.Function) ServiceUserRegistered(im.actor.core.entity.content.ServiceUserRegistered) PhoneBookProvider(im.actor.core.providers.PhoneBookProvider) Promise(im.actor.runtime.promise.Promise) UpdateUserBotCommandsChanged(im.actor.core.api.updates.UpdateUserBotCommandsChanged) UpdateUserNickChanged(im.actor.core.api.updates.UpdateUserNickChanged) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) User(im.actor.core.entity.User) UpdateUserLocalNameChanged(im.actor.core.api.updates.UpdateUserLocalNameChanged) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) JavaUtil.equalsE(im.actor.core.util.JavaUtil.equalsE) UpdateUserUnblocked(im.actor.core.api.updates.UpdateUserUnblocked) RequestLoadFullUsers(im.actor.core.api.rpc.RequestLoadFullUsers) ContactsSyncActor(im.actor.core.modules.contacts.ContactsSyncActor) UserVM(im.actor.core.viewmodel.UserVM) RouterFetchMissingUsers(im.actor.core.modules.users.router.entity.RouterFetchMissingUsers) BookImportStorage(im.actor.core.modules.contacts.entity.BookImportStorage) RouterApplyUsers(im.actor.core.modules.users.router.entity.RouterApplyUsers) UpdateUserPreferredLanguagesChanged(im.actor.core.api.updates.UpdateUserPreferredLanguagesChanged) Log(im.actor.runtime.Log) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) Update(im.actor.core.network.parser.Update) RouterUserUpdate(im.actor.core.modules.users.router.entity.RouterUserUpdate) Promise(im.actor.runtime.promise.Promise) PhoneBookContact(im.actor.core.entity.PhoneBookContact) List(java.util.List) ArrayList(java.util.ArrayList) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) Void(im.actor.runtime.actors.messages.Void) ContactRecord(im.actor.core.entity.ContactRecord) ApiContactRecord(im.actor.core.api.ApiContactRecord) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) Verified(im.actor.runtime.annotations.Verified)

Example 3 with User

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

use of im.actor.core.entity.User 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 User

use of im.actor.core.entity.User 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

User (im.actor.core.entity.User)19 ArrayList (java.util.ArrayList)14 Promise (im.actor.runtime.promise.Promise)8 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)7 Group (im.actor.core.entity.Group)7 Peer (im.actor.core.entity.Peer)6 ApiUser (im.actor.core.api.ApiUser)5 Message (im.actor.core.entity.Message)5 ModuleContext (im.actor.core.modules.ModuleContext)5 ModuleActor (im.actor.core.modules.ModuleActor)4 UserVM (im.actor.core.viewmodel.UserVM)4 Log (im.actor.runtime.Log)4 ActorRef (im.actor.runtime.actors.ActorRef)4 Props (im.actor.runtime.actors.Props)4 Function (im.actor.runtime.function.Function)4 ApiOutPeer (im.actor.core.api.ApiOutPeer)3 SeqUpdate (im.actor.core.api.base.SeqUpdate)3 ResponseSeq (im.actor.core.api.rpc.ResponseSeq)3 AbsModule (im.actor.core.modules.AbsModule)3 RpcCallback (im.actor.core.network.RpcCallback)3