Search in sources :

Example 6 with UserKeysGroup

use of im.actor.core.modules.encryption.entity.UserKeysGroup 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

UserKeysGroup (im.actor.core.modules.encryption.entity.UserKeysGroup)6 UserKeys (im.actor.core.modules.encryption.entity.UserKeys)4 Function (im.actor.runtime.function.Function)4 ArrayList (java.util.ArrayList)4 ApiEncryptionKey (im.actor.core.api.ApiEncryptionKey)3 ApiEncryptionKeySignature (im.actor.core.api.ApiEncryptionKeySignature)3 ApiUserOutPeer (im.actor.core.api.ApiUserOutPeer)3 RequestLoadPublicKey (im.actor.core.api.rpc.RequestLoadPublicKey)3 PublicKey (im.actor.core.modules.encryption.entity.PublicKey)3 ResponsePublicKeys (im.actor.core.api.rpc.ResponsePublicKeys)2 User (im.actor.core.entity.User)2 Tuple2 (im.actor.runtime.function.Tuple2)2 Promise (im.actor.runtime.promise.Promise)2 ApiEncryptionKeyGroup (im.actor.core.api.ApiEncryptionKeyGroup)1 RequestLoadPrePublicKeys (im.actor.core.api.rpc.RequestLoadPrePublicKeys)1 RequestLoadPublicKeyGroups (im.actor.core.api.rpc.RequestLoadPublicKeyGroups)1 ResponsePublicKeyGroups (im.actor.core.api.rpc.ResponsePublicKeyGroups)1 PeerSession (im.actor.core.entity.encryption.PeerSession)1 EncryptedBox (im.actor.core.modules.encryption.entity.EncryptedBox)1 EncryptedBoxKey (im.actor.core.modules.encryption.entity.EncryptedBoxKey)1