use of org.matrix.androidsdk.rest.model.identityserver.LookUpV2Params in project matrix-android-sdk by matrix-org.
the class ThirdPidRestClient method lookup3PidsV2.
/**
* Retrieve user matrix id from a 3rd party id.
*
* @param addresses 3rd party ids
* @param mediums the media.
* @param callback the 3rd parties callback
*/
public void lookup3PidsV2(final HashDetailResponse hashDetailResponse, final List<String> addresses, final List<String> mediums, final ApiCallback<List<String>> callback) {
// sanity checks
if ((null == addresses) || (null == mediums) || (addresses.size() != mediums.size())) {
callback.onUnexpectedError(new Exception("invalid params"));
return;
}
// nothing to check
if (0 == mediums.size()) {
callback.onSuccess(new ArrayList<>());
return;
}
// Check that hashDetailResponse support sha256
if (!hashDetailResponse.algorithms.contains("sha256")) {
// We wont do better on the legacy SDK, in particular, we do not support "none"
callback.onUnexpectedError(new Exception("sha256 is not supported"));
return;
}
OlmUtility olmUtility;
try {
olmUtility = new OlmUtility();
} catch (Exception e) {
callback.onUnexpectedError(e);
return;
}
final List<String> hashedPids = new ArrayList<>();
for (int i = 0; i < addresses.size(); i++) {
hashedPids.add(StringUtilsKt.base64ToBase64Url(olmUtility.sha256(addresses.get(i).toLowerCase(Locale.ROOT) + " " + mediums.get(i) + " " + hashDetailResponse.pepper)));
}
olmUtility.releaseUtility();
LookUpV2Params lookUpV2Params = new LookUpV2Params(hashedPids, "sha256", hashDetailResponse.pepper);
mApi.bulkLookupV2(lookUpV2Params).enqueue(new RestAdapterCallback<>("bulkLookupV2", null, new SimpleApiCallback<LookUpV2Response>(callback) {
@Override
public void onSuccess(LookUpV2Response info) {
handleLookupV2Success(info, hashedPids, callback);
}
}, null));
}
Aggregations