use of org.matrix.androidsdk.core.callback.SimpleApiCallback in project matrix-android-sdk by matrix-org.
the class ThirdPidRestClient method lookup3Pids.
/**
* Retrieve user matrix id from a 3rd party id.
*
* @param addresses 3rd party ids
* @param mediums the media.
* @param callback the 3rd parties callback
* @Deprecated Try to use first v2 API
*/
@Deprecated
public void lookup3Pids(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;
}
BulkLookupParams threePidsParams = new BulkLookupParams();
List<List<String>> list = new ArrayList<>();
for (int i = 0; i < addresses.size(); i++) {
list.add(Arrays.asList(mediums.get(i), addresses.get(i)));
}
threePidsParams.threepids = list;
mApi.bulkLookup(threePidsParams).enqueue(new RestAdapterCallback<>("lookup3PidsLegacy", null, new SimpleApiCallback<BulkLookupResponse>(callback) {
@Override
public void onSuccess(BulkLookupResponse info) {
handleBulkLookupSuccess(info, addresses, callback);
}
}, null));
}
use of org.matrix.androidsdk.core.callback.SimpleApiCallback in project matrix-android-sdk by matrix-org.
the class ThirdPidRestClient method requestPhoneNumberValidationToken.
public void requestPhoneNumberValidationToken(ThreePid pid, @Nullable String nextLink, ApiCallback<Void> callback) {
IdentityServerRequest3PIDValidationParams params = IdentityServerRequest3PIDValidationParams.forPhoneNumber(pid.getPhoneNumber(), pid.getCountry(), pid.getClientSecret(), pid.getSendAttempt());
pid.setState(ThreePid.State.TOKEN_REQUESTED);
mApi.requestPhoneNumberValidationToken(params).enqueue(new RestAdapterCallback<>("chandeBindStatus", null, new SimpleApiCallback<IdentityServerRequestTokenResponse>(callback) {
@Override
public void onSuccess(IdentityServerRequestTokenResponse response) {
pid.setSid(response.sid);
callback.onSuccess(null);
}
}, null));
}
use of org.matrix.androidsdk.core.callback.SimpleApiCallback in project matrix-android-sdk by matrix-org.
the class ThirdPidRestClient method submitValidationToken.
/**
* Request the ownership validation of an email address or a phone number previously set
* by {@link ThirdPidRestClient#requestEmailValidationToken(ThreePid, String, ApiCallback)}
*
* @param medium the medium of the 3pid
* @param token the token generated by the requestEmailValidationToken call
* @param clientSecret the client secret which was supplied in the requestEmailValidationToken call
* @param sid the sid for the session
* @param callback asynchronous callback response
*/
public void submitValidationToken(final String medium, final String token, final String clientSecret, final String sid, final ApiCallback<Boolean> callback) {
RequestOwnershipParams params = RequestOwnershipParams.Companion.with(clientSecret, sid, token);
mApi.requestOwnershipValidationV2(medium, params).enqueue(new RestAdapterCallback<>("submitValidationToken", null, new SimpleApiCallback<SuccessResult>(callback) {
@Override
public void onSuccess(SuccessResult info) {
callback.onSuccess(info.success);
}
@Override
public void onMatrixError(MatrixError e) {
if (e.mStatus == HttpURLConnection.HTTP_NOT_FOUND) /*404*/
{
// Use legacy request
submitValidationTokenLegacy(medium, token, clientSecret, sid, callback);
} else {
super.onMatrixError(e);
}
}
}, null));
}
use of org.matrix.androidsdk.core.callback.SimpleApiCallback in project matrix-android-sdk by matrix-org.
the class MXCallsManager method createCallInRoom.
/**
* Create an IMXCall in the room defines by its room Id.
* -> for a 1:1 call, it is a standard call.
* -> for a conference call,
* ----> the conference user is invited to the room (if it was not yet invited)
* ----> the call signaling room is created (or retrieved) with the conference
* ----> and the call is started
*
* @param roomId the room roomId
* @param isVideo true to start a video call
* @param callback the async callback
*/
public void createCallInRoom(final String roomId, final boolean isVideo, final ApiCallback<IMXCall> callback) {
Log.d(LOG_TAG, "createCallInRoom in " + roomId);
final Room room = mSession.getDataHandler().getRoom(roomId);
// sanity check
if (null != room) {
if (isSupported()) {
int joinedMembers = room.getNumberOfJoinedMembers();
Log.d(LOG_TAG, "createCallInRoom : the room has " + joinedMembers + " joined members");
if (joinedMembers > 1) {
if (joinedMembers == 2) {
// So it seems safer to reject the call creation it it will fail.
if (room.isEncrypted() && mSession.getCrypto() != null && mSession.getCrypto().warnOnUnknownDevices()) {
room.getJoinedMembersAsync(new SimpleApiCallback<List<RoomMember>>(callback) {
@Override
public void onSuccess(List<RoomMember> members) {
if (members.size() != 2) {
// Safety check
callback.onUnexpectedError(new Exception("Wrong number of members"));
return;
}
String userId1 = members.get(0).getUserId();
String userId2 = members.get(1).getUserId();
// force the refresh to ensure that the devices list is up-to-date
mSession.getCrypto().checkUnknownDevices(Arrays.asList(userId1, userId2), new SimpleApiCallback<Void>(callback) {
@Override
public void onSuccess(Void anything) {
final IMXCall call = getCallWithCallId(null, true);
call.setRooms(room, room);
call.setIsVideo(isVideo);
dispatchOnOutgoingCall(call);
if (null != callback) {
mUIThreadHandler.post(() -> callback.onSuccess(call));
}
}
});
}
});
} else {
final IMXCall call = getCallWithCallId(null, true);
call.setIsVideo(isVideo);
dispatchOnOutgoingCall(call);
call.setRooms(room, room);
if (null != callback) {
mUIThreadHandler.post(() -> callback.onSuccess(call));
}
}
} else {
Log.d(LOG_TAG, "createCallInRoom : inviteConferenceUser");
inviteConferenceUser(room, new ApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
Log.d(LOG_TAG, "createCallInRoom : inviteConferenceUser succeeds");
getConferenceUserRoom(room.getRoomId(), new ApiCallback<Room>() {
@Override
public void onSuccess(Room conferenceRoom) {
Log.d(LOG_TAG, "createCallInRoom : getConferenceUserRoom succeeds");
final IMXCall call = getCallWithCallId(null, true);
call.setRooms(room, conferenceRoom);
call.setIsConference(true);
call.setIsVideo(isVideo);
dispatchOnOutgoingCall(call);
if (null != callback) {
mUIThreadHandler.post(() -> callback.onSuccess(call));
}
}
@Override
public void onNetworkError(Exception e) {
Log.e(LOG_TAG, "createCallInRoom : getConferenceUserRoom failed " + e.getMessage(), e);
if (null != callback) {
callback.onNetworkError(e);
}
}
@Override
public void onMatrixError(MatrixError e) {
Log.e(LOG_TAG, "createCallInRoom : getConferenceUserRoom failed " + e.getMessage());
if (null != callback) {
callback.onMatrixError(e);
}
}
@Override
public void onUnexpectedError(Exception e) {
Log.e(LOG_TAG, "createCallInRoom : getConferenceUserRoom failed " + e.getMessage(), e);
if (null != callback) {
callback.onUnexpectedError(e);
}
}
});
}
@Override
public void onNetworkError(Exception e) {
Log.e(LOG_TAG, "createCallInRoom : inviteConferenceUser fails " + e.getMessage(), e);
if (null != callback) {
callback.onNetworkError(e);
}
}
@Override
public void onMatrixError(MatrixError e) {
Log.e(LOG_TAG, "createCallInRoom : inviteConferenceUser fails " + e.getMessage());
if (null != callback) {
callback.onMatrixError(e);
}
}
@Override
public void onUnexpectedError(Exception e) {
Log.e(LOG_TAG, "createCallInRoom : inviteConferenceUser fails " + e.getMessage(), e);
if (null != callback) {
callback.onUnexpectedError(e);
}
}
});
}
} else {
if (null != callback) {
callback.onMatrixError(new MatrixError(MatrixError.NOT_SUPPORTED, "too few users"));
}
}
} else {
if (null != callback) {
callback.onMatrixError(new MatrixError(MatrixError.NOT_SUPPORTED, "VOIP is not supported"));
}
}
} else {
if (null != callback) {
callback.onMatrixError(new MatrixError(MatrixError.NOT_FOUND, "room not found"));
}
}
}
use of org.matrix.androidsdk.core.callback.SimpleApiCallback in project matrix-android-sdk by matrix-org.
the class MXCallsManager method checkPendingIncomingCalls.
/**
* check if there is a pending incoming call
*/
public void checkPendingIncomingCalls() {
// Log.d(LOG_TAG, "checkPendingIncomingCalls");
mUIThreadHandler.post(() -> {
if (mxPendingIncomingCallId.size() > 0) {
for (String callId : mxPendingIncomingCallId) {
final IMXCall call = getCallWithCallId(callId);
if (null != call) {
final Room room = call.getRoom();
// If there are some unknown devices, the answer event would not be encrypted.
if ((null != room) && room.isEncrypted() && mSession.getCrypto() != null && mSession.getCrypto().warnOnUnknownDevices() && room.getNumberOfJoinedMembers() == 2) {
// test if the encrypted events are sent only to the verified devices (any room)
mSession.getCrypto().getGlobalBlacklistUnverifiedDevices(new SimpleApiCallback<Boolean>() {
@Override
public void onSuccess(Boolean sendToVerifiedDevicesOnly) {
if (sendToVerifiedDevicesOnly) {
dispatchOnIncomingCall(call, null);
} else {
// test if the encrypted events are sent only to the verified devices (only this room)
mSession.getCrypto().isRoomBlacklistUnverifiedDevices(room.getRoomId(), new SimpleApiCallback<Boolean>() {
@Override
public void onSuccess(Boolean sendToVerifiedDevicesOnly) {
if (sendToVerifiedDevicesOnly) {
dispatchOnIncomingCall(call, null);
} else {
room.getJoinedMembersAsync(new ApiCallback<List<RoomMember>>() {
@Override
public void onNetworkError(Exception e) {
dispatchOnIncomingCall(call, null);
}
@Override
public void onMatrixError(MatrixError e) {
dispatchOnIncomingCall(call, null);
}
@Override
public void onUnexpectedError(Exception e) {
dispatchOnIncomingCall(call, null);
}
@Override
public void onSuccess(List<RoomMember> members) {
String userId1 = members.get(0).getUserId();
String userId2 = members.get(1).getUserId();
Log.d(LOG_TAG, "## checkPendingIncomingCalls() : check the unknown devices");
//
mSession.getCrypto().checkUnknownDevices(Arrays.asList(userId1, userId2), new ApiCallback<Void>() {
@Override
public void onSuccess(Void anything) {
Log.d(LOG_TAG, "## checkPendingIncomingCalls() : no unknown device");
dispatchOnIncomingCall(call, null);
}
@Override
public void onNetworkError(Exception e) {
Log.e(LOG_TAG, "## checkPendingIncomingCalls() : checkUnknownDevices failed " + e.getMessage(), e);
dispatchOnIncomingCall(call, null);
}
@Override
public void onMatrixError(MatrixError e) {
MXUsersDevicesMap<MXDeviceInfo> unknownDevices = null;
if (e instanceof MXCryptoError) {
MXCryptoError cryptoError = (MXCryptoError) e;
if (MXCryptoError.UNKNOWN_DEVICES_CODE.equals(cryptoError.errcode)) {
unknownDevices = (MXUsersDevicesMap<MXDeviceInfo>) cryptoError.mExceptionData;
}
}
if (null != unknownDevices) {
Log.d(LOG_TAG, "## checkPendingIncomingCalls() :" + " checkUnknownDevices found some unknown devices");
} else {
Log.e(LOG_TAG, "## checkPendingIncomingCalls() :" + " checkUnknownDevices failed " + e.getMessage());
}
dispatchOnIncomingCall(call, unknownDevices);
}
@Override
public void onUnexpectedError(Exception e) {
Log.e(LOG_TAG, "## checkPendingIncomingCalls() :" + " checkUnknownDevices failed " + e.getMessage(), e);
dispatchOnIncomingCall(call, null);
}
});
}
});
}
}
});
}
}
});
} else {
dispatchOnIncomingCall(call, null);
}
}
}
}
mxPendingIncomingCallId.clear();
});
}
Aggregations