use of im.actor.core.api.ApiUserOutPeer 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());
}
}
use of im.actor.core.api.ApiUserOutPeer 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 -> {
User upd = r.getT2().updateExt(r.getT1().getFullUsers().get(0));
users().addOrUpdateItem(upd);
}).chain(r -> checkIsInPhoneBook(r.getT2().updateExt(r.getT1().getFullUsers().get(0)))).after((r, e) -> unfreeze());
}
use of im.actor.core.api.ApiUserOutPeer 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;
}
Aggregations