Search in sources :

Example 6 with SimpleApiCallback

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));
}
Also used : BulkLookupParams(org.matrix.androidsdk.rest.model.BulkLookupParams) ArrayList(java.util.ArrayList) BulkLookupResponse(org.matrix.androidsdk.rest.model.BulkLookupResponse) ArrayList(java.util.ArrayList) List(java.util.List) SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback)

Example 7 with SimpleApiCallback

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));
}
Also used : IdentityServerRequest3PIDValidationParams(org.matrix.androidsdk.rest.model.IdentityServerRequest3PIDValidationParams) SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback) IdentityServerRequestTokenResponse(org.matrix.androidsdk.rest.model.IdentityServerRequestTokenResponse)

Example 8 with SimpleApiCallback

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));
}
Also used : SuccessResult(org.matrix.androidsdk.rest.model.SuccessResult) MatrixError(org.matrix.androidsdk.core.model.MatrixError) RequestOwnershipParams(org.matrix.androidsdk.rest.model.RequestOwnershipParams) SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback)

Example 9 with SimpleApiCallback

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"));
        }
    }
}
Also used : SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback) ApiCallback(org.matrix.androidsdk.core.callback.ApiCallback) RoomMember(org.matrix.androidsdk.rest.model.RoomMember) ArrayList(java.util.ArrayList) List(java.util.List) MatrixError(org.matrix.androidsdk.core.model.MatrixError) Room(org.matrix.androidsdk.data.Room) SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback)

Example 10 with SimpleApiCallback

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();
    });
}
Also used : SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback) ApiCallback(org.matrix.androidsdk.core.callback.ApiCallback) MXDeviceInfo(org.matrix.androidsdk.crypto.data.MXDeviceInfo) RoomMember(org.matrix.androidsdk.rest.model.RoomMember) ArrayList(java.util.ArrayList) List(java.util.List) MatrixError(org.matrix.androidsdk.core.model.MatrixError) Room(org.matrix.androidsdk.data.Room) SimpleApiCallback(org.matrix.androidsdk.core.callback.SimpleApiCallback) MXCryptoError(org.matrix.androidsdk.crypto.MXCryptoError)

Aggregations

SimpleApiCallback (org.matrix.androidsdk.core.callback.SimpleApiCallback)17 ArrayList (java.util.ArrayList)7 MatrixError (org.matrix.androidsdk.core.model.MatrixError)5 Room (org.matrix.androidsdk.data.Room)5 List (java.util.List)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 RoomState (org.matrix.androidsdk.data.RoomState)4 Event (org.matrix.androidsdk.rest.model.Event)4 HashMap (java.util.HashMap)3 ApiCallback (org.matrix.androidsdk.core.callback.ApiCallback)3 Context (android.content.Context)2 JsonObject (com.google.gson.JsonObject)2 Test (org.junit.Test)2 MXSession (org.matrix.androidsdk.MXSession)2 CryptoTestData (org.matrix.androidsdk.common.CryptoTestData)2 MXCryptoError (org.matrix.androidsdk.crypto.MXCryptoError)2 EventTimeline (org.matrix.androidsdk.data.timeline.EventTimeline)2 MXEventListener (org.matrix.androidsdk.listeners.MXEventListener)2 IdentityServerRequest3PIDValidationParams (org.matrix.androidsdk.rest.model.IdentityServerRequest3PIDValidationParams)2 IdentityServerRequestTokenResponse (org.matrix.androidsdk.rest.model.IdentityServerRequestTokenResponse)2