use of im.actor.core.api.rpc.ResponseGetContacts in project actor-platform by actorapp.
the class ContactsSyncActor method performSync.
public void performSync() {
if (ENABLE_LOG) {
Log.d(TAG, "Checking sync");
}
if (isInProgress) {
if (ENABLE_LOG) {
Log.d(TAG, "Sync in progress, invalidating current sync");
}
isInvalidated = true;
return;
}
isInProgress = true;
isInvalidated = false;
if (ENABLE_LOG) {
Log.d(TAG, "Starting sync");
}
Integer[] uids = contacts.toArray(new Integer[contacts.size()]);
Arrays.sort(uids);
String hash = "";
for (long u : uids) {
if (hash.length() != 0) {
hash += ",";
}
hash += u;
}
byte[] hashData;
try {
hashData = hash.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return;
}
String hashValue = Crypto.hex(Crypto.SHA256(hashData));
if (ENABLE_LOG) {
Log.d(TAG, "Performing sync with hash: " + hashValue);
Log.d(TAG, "Performing sync with uids: " + hash);
}
request(new RequestGetContacts(hashValue, ApiSupportConfiguration.OPTIMIZATIONS), new RpcCallback<ResponseGetContacts>() {
@Override
public void onResult(ResponseGetContacts response) {
if (ENABLE_LOG) {
Log.d(TAG, "Sync received " + (response.getUsers().size() + response.getUserPeers().size()) + " contacts");
}
if (response.getUserPeers().size() > 0) {
updates().loadRequiredPeers(response.getUserPeers(), new ArrayList<>()).then(v -> onContactsLoaded(response));
} else {
updates().applyRelatedData(response.getUsers()).then(v -> onContactsLoaded(response));
}
}
@Override
public void onError(RpcException e) {
isInProgress = false;
e.printStackTrace();
}
});
}
Aggregations