Search in sources :

Example 1 with User

use of org.matrix.androidsdk.rest.model.User in project matrix-android-sdk by matrix-org.

the class MXMemoryStore method setDisplayName.

@Override
public boolean setDisplayName(String displayName, long ts) {
    boolean isUpdated;
    synchronized (LOG_TAG) {
        if (null != mMetadata) {
            Log.d(LOG_TAG, "## setDisplayName() : from " + mMetadata.mUserDisplayName + " to " + displayName + " ts " + ts);
        }
        isUpdated = (null != mMetadata) && !TextUtils.equals(mMetadata.mUserDisplayName, displayName) && (mUserDisplayNameTs < ts) && (ts != 0) && (ts <= System.currentTimeMillis());
        if (isUpdated) {
            mMetadata.mUserDisplayName = (null != displayName) ? displayName.trim() : null;
            mUserDisplayNameTs = ts;
            // update the cached oneself User
            User myUser = getUser(mMetadata.mUserId);
            if (null != myUser) {
                myUser.displayname = mMetadata.mUserDisplayName;
            }
            Log.d(LOG_TAG, "## setDisplayName() : updated");
            commit();
        }
    }
    return isUpdated;
}
Also used : User(org.matrix.androidsdk.rest.model.User)

Example 2 with User

use of org.matrix.androidsdk.rest.model.User in project matrix-android-sdk by matrix-org.

the class RoomState method getMemberName.

/**
 * Return an unique display name of the member userId.
 *
 * @param userId the user id
 * @return unique display name
 */
public String getMemberName(String userId) {
    // sanity check
    if (null == userId) {
        return null;
    }
    String displayName;
    synchronized (this) {
        if (null == mMemberDisplayNameByUserId) {
            mMemberDisplayNameByUserId = new HashMap<>();
        }
        displayName = mMemberDisplayNameByUserId.get(userId);
    }
    if (null != displayName) {
        return displayName;
    }
    // Get the user display name from the member list of the room
    RoomMember member = getMember(userId);
    // Do not consider null display name
    if ((null != member) && !TextUtils.isEmpty(member.displayname)) {
        displayName = member.displayname;
        synchronized (this) {
            ArrayList<String> matrixIds = new ArrayList<>();
            // Disambiguate users who have the same display name in the room
            for (RoomMember aMember : mMembers.values()) {
                if (displayName.equals(aMember.displayname)) {
                    matrixIds.add(aMember.getUserId());
                }
            }
            // index it i.e bob (<Matrix id>)
            if (matrixIds.size() > 1) {
                displayName += " (" + userId + ")";
            }
        }
    } else if ((null != member) && TextUtils.equals(member.membership, RoomMember.MEMBERSHIP_INVITE)) {
        User user = ((MXDataHandler) mDataHandler).getUser(userId);
        if (null != user) {
            displayName = user.displayname;
        }
    }
    if (null == displayName) {
        // By default, use the user ID
        displayName = userId;
    }
    mMemberDisplayNameByUserId.put(userId, displayName);
    return displayName;
}
Also used : User(org.matrix.androidsdk.rest.model.User) RoomMember(org.matrix.androidsdk.rest.model.RoomMember) ArrayList(java.util.ArrayList)

Example 3 with User

use of org.matrix.androidsdk.rest.model.User in project matrix-android-sdk by matrix-org.

the class EventsRestClient method searchUsers.

/**
 * Search users with a patter,
 *
 * @param text          the text to search for.
 * @param limit         the maximum nbr of users in the response
 * @param userIdsFilter the userIds to exclude from the result
 * @param callback      the request callback
 */
public void searchUsers(final String text, final Integer limit, final Set<String> userIdsFilter, final ApiCallback<SearchUsersResponse> callback) {
    SearchUsersParams searchParams = new SearchUsersParams();
    searchParams.search_term = text;
    searchParams.limit = limit + ((null != userIdsFilter) ? userIdsFilter.size() : 0);
    final String uid = mSearchUsersPatternIdentifier = System.currentTimeMillis() + " " + text + " " + limit;
    final String description = "searchUsers";
    try {
        // don't retry to send the request
        // if the search fails, stop it
        mApi.searchUsers(searchParams, new RestAdapterCallback<SearchUsersRequestResponse>(description, null, new ApiCallback<SearchUsersRequestResponse>() {

            /**
             * Tells if the current response for the latest request.
             *
             * @return true if it is the response of the latest request.
             */
            private boolean isActiveRequest() {
                return TextUtils.equals(mSearchUsersPatternIdentifier, uid);
            }

            @Override
            public void onSuccess(SearchUsersRequestResponse aResponse) {
                if (isActiveRequest()) {
                    SearchUsersResponse response = new SearchUsersResponse();
                    response.limited = aResponse.limited;
                    response.results = new ArrayList<>();
                    Set<String> filter = (null != userIdsFilter) ? userIdsFilter : new HashSet<String>();
                    if (null != aResponse.results) {
                        for (SearchUsersRequestResponse.User user : aResponse.results) {
                            if ((null != user.user_id) && !filter.contains(user.user_id)) {
                                User addedUser = new User();
                                addedUser.user_id = user.user_id;
                                addedUser.avatar_url = user.avatar_url;
                                addedUser.displayname = user.display_name;
                                response.results.add(addedUser);
                            }
                        }
                    }
                    callback.onSuccess(response);
                    mSearchUsersPatternIdentifier = null;
                }
            }

            @Override
            public void onNetworkError(Exception e) {
                if (isActiveRequest()) {
                    callback.onNetworkError(e);
                    mSearchUsersPatternIdentifier = null;
                }
            }

            @Override
            public void onMatrixError(MatrixError e) {
                if (isActiveRequest()) {
                    callback.onMatrixError(e);
                    mSearchUsersPatternIdentifier = null;
                }
            }

            @Override
            public void onUnexpectedError(Exception e) {
                if (isActiveRequest()) {
                    callback.onUnexpectedError(e);
                    mSearchUsersPatternIdentifier = null;
                }
            }
        }, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                searchUsers(text, limit, userIdsFilter, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : User(org.matrix.androidsdk.rest.model.User) ApiCallback(org.matrix.androidsdk.rest.callback.ApiCallback) SearchUsersParams(org.matrix.androidsdk.rest.model.search.SearchUsersParams) SearchUsersRequestResponse(org.matrix.androidsdk.rest.model.search.SearchUsersRequestResponse) MatrixError(org.matrix.androidsdk.rest.model.MatrixError) SearchUsersResponse(org.matrix.androidsdk.rest.model.search.SearchUsersResponse)

Example 4 with User

use of org.matrix.androidsdk.rest.model.User in project matrix-android-sdk by matrix-org.

the class ProfileRestClient method updateDisplayname.

/**
 * Update this user's own display name.
 * @param newName the new name
 * @param callback the callback if the call succeeds
 */
public void updateDisplayname(final String newName, final ApiCallback<Void> callback) {
    // privacy
    // final String description = "updateDisplayname newName : " + newName;
    final String description = "update display name";
    User user = new User();
    user.displayname = newName;
    try {
        // don't retry if the network comes back
        // let the user chooses what he want to do
        mApi.displayname(mCredentials.userId, user, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateDisplayname(newName, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : User(org.matrix.androidsdk.rest.model.User)

Example 5 with User

use of org.matrix.androidsdk.rest.model.User in project matrix-android-sdk by matrix-org.

the class ProfileRestClient method updateAvatarUrl.

/**
 * Update this user's own avatar URL.
 * @param newUrl the new name
 * @param callback the callback if the call succeeds
 */
public void updateAvatarUrl(final String newUrl, final ApiCallback<Void> callback) {
    // privacy
    // final String description = "updateAvatarUrl newUrl : " + newUrl;
    final String description = "updateAvatarUrl";
    User user = new User();
    user.setAvatarUrl(newUrl);
    try {
        mApi.avatarUrl(mCredentials.userId, user, new RestAdapterCallback<Void>(description, mUnsentEventsManager, callback, new RestAdapterCallback.RequestRetryCallBack() {

            @Override
            public void onRetry() {
                updateAvatarUrl(newUrl, callback);
            }
        }));
    } catch (Throwable t) {
        callback.onUnexpectedError(new Exception(t));
    }
}
Also used : User(org.matrix.androidsdk.rest.model.User)

Aggregations

User (org.matrix.androidsdk.rest.model.User)12 ArrayList (java.util.ArrayList)4 File (java.io.File)2 BannedUser (org.matrix.androidsdk.rest.model.BannedUser)2 HandlerThread (android.os.HandlerThread)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 MyUser (org.matrix.androidsdk.data.MyUser)1 IMXEventListener (org.matrix.androidsdk.listeners.IMXEventListener)1 MXEventListener (org.matrix.androidsdk.listeners.MXEventListener)1 ApiCallback (org.matrix.androidsdk.rest.callback.ApiCallback)1 Event (org.matrix.androidsdk.rest.model.Event)1 MatrixError (org.matrix.androidsdk.rest.model.MatrixError)1 RoomMember (org.matrix.androidsdk.rest.model.RoomMember)1 SearchUsersParams (org.matrix.androidsdk.rest.model.search.SearchUsersParams)1 SearchUsersRequestResponse (org.matrix.androidsdk.rest.model.search.SearchUsersRequestResponse)1 SearchUsersResponse (org.matrix.androidsdk.rest.model.search.SearchUsersResponse)1