Search in sources :

Example 6 with ApiUser

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

the class User method editName.

public User editName(@NotNull String name) {
    ApiUser w = getWrapped();
    ApiUser res = new ApiUser(w.getId(), w.getAccessHash(), name, w.getLocalName(), 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 7 with ApiUser

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

the class ContactsSyncActor method onContactsLoaded.

public void onContactsLoaded(ResponseGetContacts result) {
    if (ENABLE_LOG) {
        Log.d(TAG, "Sync result received");
    }
    isInProgress = false;
    context().getConductor().getConductor().onContactsLoaded();
    if (result.isNotChanged()) {
        Log.d(TAG, "Sync: Not changed");
        if (isInvalidated) {
            performSync();
        } else {
        // ProfileSyncState.onContactsLoaded(contactUsers.size() == 0);
        }
        return;
    }
    // Reading all uids
    HashSet<Integer> uids = new HashSet<>();
    for (ApiUser u : result.getUsers()) {
        uids.add(u.getId());
    }
    for (ApiUserOutPeer u : result.getUserPeers()) {
        uids.add(u.getUid());
    }
    if (ENABLE_LOG) {
        Log.d(TAG, "Sync received " + uids.size() + " contacts");
    }
    outer: for (Integer uid : contacts.toArray(new Integer[contacts.size()])) {
        for (Integer u : uids) {
            if (u.equals(uid)) {
                continue outer;
            }
        }
        if (ENABLE_LOG) {
            Log.d(TAG, "Removing: #" + uid);
        }
        contacts.remove((Integer) uid);
        if (getUser(uid) != null) {
            getUserVM(uid).isContact().change(false);
        }
        context().getContactsModule().markNonContact(uid);
    }
    for (Integer u : uids) {
        if (contacts.contains(u)) {
            continue;
        }
        if (ENABLE_LOG) {
            Log.d(TAG, "Adding: #" + u);
        }
        contacts.add(u);
        if (getUser(u) != null) {
            getUserVM(u).isContact().change(true);
        }
        context().getContactsModule().markContact(u);
    }
    saveList();
    updateEngineList();
    if (isInvalidated) {
        self().send(new PerformSync());
    }
}
Also used : ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ApiUser(im.actor.core.api.ApiUser) HashSet(java.util.HashSet)

Example 8 with ApiUser

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

the class SequenceHandlerActor method onDifferenceUpdate.

private Promise<Void> onDifferenceUpdate(@NotNull List<ApiUser> users, @NotNull List<ApiGroup> groups, @NotNull List<ApiUserOutPeer> userOutPeers, @NotNull List<ApiGroupOutPeer> groupOutPeers, @NotNull List<Update> updates) {
    if (updates.size() > 0) {
        String command = "Difference updates:";
        for (Update u : updates) {
            command += "\n| " + u;
        }
        Log.d(TAG, command);
    }
    beginUpdates();
    // Related Users
    Promise<Void> currentPromise = updates().applyRelatedData(users, groups);
    // Loading missing peers
    currentPromise = currentPromise.chain(v -> updates().loadRequiredPeers(userOutPeers, groupOutPeers));
    // Apply Diff
    long applyStart = im.actor.runtime.Runtime.getCurrentTime();
    currentPromise = currentPromise.chain(v -> processor.applyDifferenceUpdate(updates)).then(v -> {
        Log.d(TAG, "Difference applied in " + (im.actor.runtime.Runtime.getCurrentTime() - applyStart) + " ms");
        endUpdates();
    });
    return currentPromise;
}
Also used : HandlerDifferenceUpdates(im.actor.core.modules.sequence.internal.HandlerDifferenceUpdates) ModuleContext(im.actor.core.modules.ModuleContext) ActorCreator(im.actor.runtime.actors.ActorCreator) Promise(im.actor.runtime.promise.Promise) ApiUser(im.actor.core.api.ApiUser) PromiseFunc(im.actor.runtime.promise.PromiseFunc) ArrayList(java.util.ArrayList) UpdateProcessor(im.actor.core.modules.sequence.processor.UpdateProcessor) HandlerRelatedResponse(im.actor.core.modules.sequence.internal.HandlerRelatedResponse) PromisesArray(im.actor.runtime.promise.PromisesArray) HandlerWeakUpdate(im.actor.core.modules.sequence.internal.HandlerWeakUpdate) RequestGetReferencedEntitites(im.actor.core.api.rpc.RequestGetReferencedEntitites) ApiGroup(im.actor.core.api.ApiGroup) Void(im.actor.runtime.actors.messages.Void) Runtime(im.actor.runtime.Runtime) Constructor(im.actor.runtime.function.Constructor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ModuleActor(im.actor.core.modules.ModuleActor) HandlerSeqUpdate(im.actor.core.modules.sequence.internal.HandlerSeqUpdate) ApiGroupOutPeer(im.actor.core.api.ApiGroupOutPeer) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) Log(im.actor.runtime.Log) NotNull(org.jetbrains.annotations.NotNull) Function(im.actor.runtime.function.Function) Update(im.actor.core.network.parser.Update) Promises(im.actor.runtime.promise.Promises) HandlerWeakUpdate(im.actor.core.modules.sequence.internal.HandlerWeakUpdate) HandlerSeqUpdate(im.actor.core.modules.sequence.internal.HandlerSeqUpdate) Update(im.actor.core.network.parser.Update) Void(im.actor.runtime.actors.messages.Void)

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