Search in sources :

Example 1 with ApiEncryptionKeyGroup

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

the class KeyManagerActor method fetchUserGroups.

// 
// User keys fetching
// 
/**
 * Fetching all user's key groups
 *
 * @param uid User's id
 */
private Promise<UserKeys> fetchUserGroups(final int uid) {
    User user = users().getValue(uid);
    if (user == null) {
        throw new RuntimeException("Unable to find user #" + uid);
    }
    final UserKeys userKeys = getCachedUserKeys(uid);
    if (userKeys != null) {
        return Promise.success(userKeys);
    }
    return api(new RequestLoadPublicKeyGroups(new ApiUserOutPeer(uid, user.getAccessHash()))).map(new Function<ResponsePublicKeyGroups, ArrayList<UserKeysGroup>>() {

        @Override
        public ArrayList<UserKeysGroup> apply(ResponsePublicKeyGroups response) {
            ArrayList<UserKeysGroup> keysGroups = new ArrayList<>();
            for (ApiEncryptionKeyGroup keyGroup : response.getPublicKeyGroups()) {
                UserKeysGroup validatedKeysGroup = validateUserKeysGroup(uid, keyGroup);
                if (validatedKeysGroup != null) {
                    keysGroups.add(validatedKeysGroup);
                }
            }
            return keysGroups;
        }
    }).map(new Function<ArrayList<UserKeysGroup>, UserKeys>() {

        @Override
        public UserKeys apply(ArrayList<UserKeysGroup> userKeysGroups) {
            UserKeys userKeys = new UserKeys(uid, userKeysGroups.toArray(new UserKeysGroup[userKeysGroups.size()]));
            cacheUserKeys(userKeys);
            return userKeys;
        }
    });
}
Also used : ResponsePublicKeyGroups(im.actor.core.api.rpc.ResponsePublicKeyGroups) User(im.actor.core.entity.User) RequestLoadPublicKeyGroups(im.actor.core.api.rpc.RequestLoadPublicKeyGroups) ApiUserOutPeer(im.actor.core.api.ApiUserOutPeer) ArrayList(java.util.ArrayList) UserKeys(im.actor.core.modules.encryption.entity.UserKeys) UserKeysGroup(im.actor.core.modules.encryption.entity.UserKeysGroup) Function(im.actor.runtime.function.Function) ApiEncryptionKeyGroup(im.actor.core.api.ApiEncryptionKeyGroup)

Aggregations

ApiEncryptionKeyGroup (im.actor.core.api.ApiEncryptionKeyGroup)1 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)1 RequestLoadPublicKeyGroups (im.actor.core.api.rpc.RequestLoadPublicKeyGroups)1 ResponsePublicKeyGroups (im.actor.core.api.rpc.ResponsePublicKeyGroups)1 User (im.actor.core.entity.User)1 UserKeys (im.actor.core.modules.encryption.entity.UserKeys)1 UserKeysGroup (im.actor.core.modules.encryption.entity.UserKeysGroup)1 Function (im.actor.runtime.function.Function)1 ArrayList (java.util.ArrayList)1