use of im.actor.core.api.rpc.RequestLoadFullUsers in project actor-platform by actorapp.
the class UserRouter method onLoadFullUser.
//
// Users changed
//
@Verified
private void onLoadFullUser(int uid) {
if (requestedFullUsers.contains(uid)) {
return;
}
requestedFullUsers.add(uid);
freeze();
users().getValueAsync(uid).flatMap((Function<User, Promise<Tuple2<ResponseLoadFullUsers, User>>>) u -> {
if (!u.isHaveExtension()) {
ArrayList<ApiUserOutPeer> users = new ArrayList<>();
users.add(new ApiUserOutPeer(u.getUid(), u.getAccessHash()));
return api(new RequestLoadFullUsers(users)).map(responseLoadFullUsers -> new Tuple2<>(responseLoadFullUsers, u));
} else {
if (!getUserVM(uid).isInPhoneBook().get()) {
return checkIsInPhoneBook(u).flatMap(new Function<Void, Promise<Tuple2<ResponseLoadFullUsers, User>>>() {
@Override
public Promise<Tuple2<ResponseLoadFullUsers, User>> apply(Void aVoid) {
return Promise.failure(new RuntimeException("Already loaded"));
}
});
} else {
return Promise.failure(new RuntimeException("Already loaded"));
}
}
}).then(r -> {
// Changing user extension
User upd = r.getT2().updateExt(r.getT1().getFullUsers().get(0));
// Updating user in collection
users().addOrUpdateItem(upd);
}).chain(r -> checkIsInPhoneBook(r.getT2().updateExt(r.getT1().getFullUsers().get(0)))).after((r, e) -> unfreeze());
}
Aggregations