From a9b87de7a3fe2406c3dc546744f38bb75e38e571 Mon Sep 17 00:00:00 2001 From: ClaireG Date: Mon, 28 Mar 2022 10:34:22 +0200 Subject: [PATCH] [Subscribing] Blank display name --- changelog.d/5497.bugfix | 1 + .../sdk/api/session/profile/ProfileService.kt | 14 ++++++++++++++ .../android/sdk/internal/session/sync/SyncTask.kt | 7 ++++++- .../RoomMemberProfileViewModel.kt | 7 +++---- .../features/userdirectory/UserListViewModel.kt | 15 +++++---------- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 changelog.d/5497.bugfix diff --git a/changelog.d/5497.bugfix b/changelog.d/5497.bugfix new file mode 100644 index 0000000000..4228ebaafb --- /dev/null +++ b/changelog.d/5497.bugfix @@ -0,0 +1 @@ +[Subscribing] Blank display name \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/profile/ProfileService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/profile/ProfileService.kt index 05fa24946a..d2c677bb31 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/profile/ProfileService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/profile/ProfileService.kt @@ -21,6 +21,7 @@ import android.net.Uri import androidx.lifecycle.LiveData import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor import org.matrix.android.sdk.api.session.identity.ThreePid +import org.matrix.android.sdk.api.session.user.model.User import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.api.util.Optional @@ -118,4 +119,17 @@ interface ProfileService { * Remove a 3Pid from the Matrix account. */ suspend fun deleteThreePid(threePid: ThreePid) + + /** + * Return a User object from a userId + */ + suspend fun getProfileAsUser(userId: String): User { + return getProfile(userId).let { dict -> + User( + userId = userId, + displayName = dict[DISPLAY_NAME_KEY] as? String, + avatarUrl = dict[AVATAR_URL_KEY] as? String + ) + } + } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt index b4da1a02cd..2136259f22 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncTask.kt @@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.sync import android.os.SystemClock import okhttp3.ResponseBody +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.logger.LoggerTag import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.initsync.InitSyncStep @@ -104,7 +105,11 @@ internal class DefaultSyncTask @Inject constructor( val isInitialSync = token == null if (isInitialSync) { // We might want to get the user information in parallel too - userStore.createOrUpdate(userId) + val user = tryOrNull { session.getProfileAsUser(userId) } + userStore.createOrUpdate( + userId = userId, + displayName = user?.displayName, + avatarUrl = user?.avatarUrl) defaultSyncStatusService.startRoot(InitSyncStep.ImportingAccount, 100) } // Maybe refresh the homeserver capabilities data we know diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt index db54f27910..1f23fec327 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileViewModel.kt @@ -48,7 +48,6 @@ import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel -import org.matrix.android.sdk.api.session.profile.ProfileService import org.matrix.android.sdk.api.session.room.Room import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.model.Membership @@ -328,12 +327,12 @@ class RoomMemberProfileViewModel @AssistedInject constructor( private suspend fun fetchProfileInfo() { val result = runCatchingToAsync { - session.getProfile(initialState.userId) + session.getProfileAsUser(initialState.userId) .let { MatrixItem.UserItem( id = initialState.userId, - displayName = it[ProfileService.DISPLAY_NAME_KEY] as? String, - avatarUrl = it[ProfileService.AVATAR_URL_KEY] as? String + displayName = it.displayName, + avatarUrl = it.avatarUrl ) } } diff --git a/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt b/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt index 039c7041b0..783fddf8ad 100644 --- a/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/userdirectory/UserListViewModel.kt @@ -45,7 +45,6 @@ import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.identity.IdentityServiceError import org.matrix.android.sdk.api.session.identity.IdentityServiceListener import org.matrix.android.sdk.api.session.identity.ThreePid -import org.matrix.android.sdk.api.session.profile.ProfileService import org.matrix.android.sdk.api.session.user.model.User import org.matrix.android.sdk.api.util.toMatrixItem @@ -213,14 +212,10 @@ class UserListViewModel @AssistedInject constructor( ThreePidUser(email = search, user = null) } else { try { - val json = session.getProfile(foundThreePid.matrixId) + val user = tryOrNull { session.getProfileAsUser(foundThreePid.matrixId) } ?: User(foundThreePid.matrixId) ThreePidUser( email = search, - user = User( - userId = foundThreePid.matrixId, - displayName = json[ProfileService.DISPLAY_NAME_KEY] as? String, - avatarUrl = json[ProfileService.AVATAR_URL_KEY] as? String - ) + user = user ) } catch (failure: Throwable) { ThreePidUser(email = search, user = User(foundThreePid.matrixId)) @@ -240,11 +235,11 @@ class UserListViewModel @AssistedInject constructor( .searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty()) .sortedBy { it.toMatrixItem().firstLetterOfDisplayName() } val userProfile = if (MatrixPatterns.isUserId(search)) { - val json = tryOrNull { session.getProfile(search) } + val user = tryOrNull { session.getProfileAsUser(search) } User( userId = search, - displayName = json?.get(ProfileService.DISPLAY_NAME_KEY) as? String, - avatarUrl = json?.get(ProfileService.AVATAR_URL_KEY) as? String + displayName = user?.displayName, + avatarUrl = user?.avatarUrl ) } else { null