Search in sources :

Example 1 with ApiUser

use of im.actor.core.api.ApiUser in project actor-platform by actorapp.

the class User method editExt.

public User editExt(@Nullable ApiMapValue ext) {
    ApiUser w = getWrapped();
    ApiUser res = new ApiUser(w.getId(), w.getAccessHash(), w.getName(), w.getLocalName(), w.getNick(), w.getSex(), w.getAvatar(), w.isBot(), ext);
    res.setUnmappedObjects(w.getUnmappedObjects());
    return new User(res, getWrappedExt());
}
Also used : ApiUser(im.actor.core.api.ApiUser) ApiFullUser(im.actor.core.api.ApiFullUser) ApiUser(im.actor.core.api.ApiUser)

Example 2 with ApiUser

use of im.actor.core.api.ApiUser in project actor-platform by actorapp.

the class User method editLocalName.

public User editLocalName(@NotNull String localName) {
    ApiUser w = getWrapped();
    ApiUser res = new ApiUser(w.getId(), w.getAccessHash(), w.getName(), localName, w.getNick(), w.getSex(), w.getAvatar(), w.isBot(), w.getExt());
    res.setUnmappedObjects(w.getUnmappedObjects());
    return new User(res, getWrappedExt());
}
Also used : ApiUser(im.actor.core.api.ApiUser) ApiFullUser(im.actor.core.api.ApiFullUser) ApiUser(im.actor.core.api.ApiUser)

Example 3 with ApiUser

use of im.actor.core.api.ApiUser in project actor-platform by actorapp.

the class User method editAvatar.

public User editAvatar(@Nullable ApiAvatar avatar) {
    ApiUser w = getWrapped();
    ApiUser res = new ApiUser(w.getId(), w.getAccessHash(), w.getName(), w.getLocalName(), w.getNick(), w.getSex(), avatar, w.isBot(), w.getExt());
    res.setUnmappedObjects(w.getUnmappedObjects());
    return new User(res, getWrappedExt());
}
Also used : ApiUser(im.actor.core.api.ApiUser) ApiFullUser(im.actor.core.api.ApiFullUser) ApiUser(im.actor.core.api.ApiUser)

Example 4 with ApiUser

use of im.actor.core.api.ApiUser in project actor-platform by actorapp.

the class User method editNick.

public User editNick(@Nullable String nick) {
    ApiUser w = getWrapped();
    ApiUser res = new ApiUser(w.getId(), w.getAccessHash(), w.getName(), w.getLocalName(), nick, w.getSex(), w.getAvatar(), w.isBot(), w.getExt());
    res.setUnmappedObjects(w.getUnmappedObjects());
    return new User(res, getWrappedExt());
}
Also used : ApiUser(im.actor.core.api.ApiUser) ApiFullUser(im.actor.core.api.ApiFullUser) ApiUser(im.actor.core.api.ApiUser)

Example 5 with ApiUser

use of im.actor.core.api.ApiUser in project actor-platform by actorapp.

the class BookImportActor method performImportIfRequired.

private void performImportIfRequired() {
    if (ENABLE_LOG) {
        Log.d(TAG, "performImportIfRequired called");
    }
    if (isUploadingContacts) {
        if (ENABLE_LOG) {
            Log.d(TAG, "performImportIfRequired:exiting:already importing");
        }
        return;
    }
    if (importQueue.size() == 0) {
        if (ENABLE_LOG) {
            Log.d(TAG, "performImportIfRequired:exiting:nothing to import");
        }
        // Marking as everything is imported
        context().getConductor().getConductor().onPhoneBookImported();
        return;
    }
    // 
    // Performing import
    // 
    isUploadingContacts = true;
    final ArrayList<ApiPhoneToImport> phoneToImports = new ArrayList<>();
    final ArrayList<ApiEmailToImport> emailToImports = new ArrayList<>();
    for (int i = 0; i < MAX_IMPORT_SIZE && importQueue.size() > 0; i++) {
        ImportQueueItem importQueueItem = importQueue.remove(0);
        if (importQueueItem instanceof ImportEmailQueueItem) {
            emailToImports.add(new ApiEmailToImport(((ImportEmailQueueItem) importQueueItem).getEmail(), ((ImportEmailQueueItem) importQueueItem).getName()));
        } else if (importQueueItem instanceof ImportPhoneQueueItem) {
            phoneToImports.add(new ApiPhoneToImport(((ImportPhoneQueueItem) importQueueItem).getPhoneNumber(), ((ImportPhoneQueueItem) importQueueItem).getName()));
        } else {
            throw new RuntimeException();
        }
    }
    request(new RequestImportContacts(phoneToImports, emailToImports, ApiSupportConfiguration.OPTIMIZATIONS), new RpcCallback<ResponseImportContacts>() {

        @Override
        public void onResult(ResponseImportContacts response) {
            for (ApiPhoneToImport phoneToImport : phoneToImports) {
                storage.markAsImported(phoneToImport.getPhoneNumber());
                importingPhones.remove(phoneToImport.getPhoneNumber());
            }
            for (ApiEmailToImport emailToImport : emailToImports) {
                storage.markAsImported(emailToImport.getEmail());
                importingEmails.remove(emailToImport.getEmail());
            }
            context().getContactsModule().getBookImportState().put(0, storage.toByteArray());
            // 
            if (response.getUsers().size() != 0 || response.getUserPeers().size() != 0) {
                if (ENABLE_LOG) {
                    Log.d(TAG, "Import success with " + (response.getUsers().size() + response.getUserPeers().size()) + " new contacts");
                }
                if (response.getUserPeers().size() != 0) {
                    // Optimized version
                    ArrayList<Integer> uids = new ArrayList<>();
                    for (ApiUserOutPeer u : response.getUserPeers()) {
                        uids.add(u.getUid());
                    }
                    updates().loadRequiredPeers(response.getUserPeers(), new ArrayList<>()).flatMap(v -> updates().applyUpdate(response.getSeq(), response.getState(), new UpdateContactsAdded(uids)));
                } else {
                    // Old version
                    ArrayList<Integer> uids = new ArrayList<>();
                    for (ApiUser u : response.getUsers()) {
                        uids.add(u.getId());
                    }
                    updates().onUpdateReceived(new FatSeqUpdate(response.getSeq(), response.getState(), UpdateContactsAdded.HEADER, new UpdateContactsAdded(uids).toByteArray(), response.getUsers(), new ArrayList<>()));
                }
            } else {
                if (ENABLE_LOG) {
                    Log.d(TAG, "Import success, but no new contacts found");
                }
            }
            // 
            // Launching next iteration
            // 
            isUploadingContacts = false;
            performImportIfRequired();
        }

        @Override
        public void onError(RpcException e) {
            // TODO: Better error handling
            if (ENABLE_LOG) {
                Log.d(TAG, "Import failure");
            }
            e.printStackTrace();
            // 
            // Launching next iteration
            // 
            isUploadingContacts = false;
            performImportIfRequired();
        }
    });
}
Also used : ApiSupportConfiguration(im.actor.core.modules.api.ApiSupportConfiguration) ApiEmailToImport(im.actor.core.api.ApiEmailToImport) ModuleContext(im.actor.core.modules.ModuleContext) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) Void(im.actor.runtime.actors.messages.Void) Bser(im.actor.runtime.bser.Bser) ApiPhoneToImport(im.actor.core.api.ApiPhoneToImport) PhoneBookContact(im.actor.core.entity.PhoneBookContact) PhoneBookIds(im.actor.core.entity.PhoneBookIds) ApiUser(im.actor.core.api.ApiUser) FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) ResponseImportContacts(im.actor.core.api.rpc.ResponseImportContacts) RpcException(im.actor.core.network.RpcException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestImportContacts(im.actor.core.api.rpc.RequestImportContacts) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) PhoneBookEmail(im.actor.core.entity.PhoneBookEmail) BookImportStorage(im.actor.core.modules.contacts.entity.BookImportStorage) RpcCallback(im.actor.core.network.RpcCallback) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Log(im.actor.runtime.Log) PhoneBookPhone(im.actor.core.entity.PhoneBookPhone) UpdateContactsAdded(im.actor.core.api.updates.UpdateContactsAdded) FatSeqUpdate(im.actor.core.api.base.FatSeqUpdate) ApiPhoneToImport(im.actor.core.api.ApiPhoneToImport) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiUser(im.actor.core.api.ApiUser) ArrayList(java.util.ArrayList) ResponseImportContacts(im.actor.core.api.rpc.ResponseImportContacts) ApiEmailToImport(im.actor.core.api.ApiEmailToImport) RpcException(im.actor.core.network.RpcException) RequestImportContacts(im.actor.core.api.rpc.RequestImportContacts)

Aggregations

ApiUser (im.actor.core.api.ApiUser)8 ApiFullUser (im.actor.core.api.ApiFullUser)5 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)3 ModuleActor (im.actor.core.modules.ModuleActor)2 ModuleContext (im.actor.core.modules.ModuleContext)2 Log (im.actor.runtime.Log)2 Void (im.actor.runtime.actors.messages.Void)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ApiEmailToImport (im.actor.core.api.ApiEmailToImport)1 ApiGroup (im.actor.core.api.ApiGroup)1 ApiGroupOutPeer (im.actor.core.api.ApiGroupOutPeer)1 ApiPhoneToImport (im.actor.core.api.ApiPhoneToImport)1 FatSeqUpdate (im.actor.core.api.base.FatSeqUpdate)1 RequestGetReferencedEntitites (im.actor.core.api.rpc.RequestGetReferencedEntitites)1 RequestImportContacts (im.actor.core.api.rpc.RequestImportContacts)1 ResponseImportContacts (im.actor.core.api.rpc.ResponseImportContacts)1 UpdateContactsAdded (im.actor.core.api.updates.UpdateContactsAdded)1 PhoneBookContact (im.actor.core.entity.PhoneBookContact)1