[Subscribing] Blank display name

This commit is contained in:
ClaireG 2022-03-28 10:34:22 +02:00 committed by GitHub
parent 10974366fb
commit a9b87de7a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 15 deletions

1
changelog.d/5497.bugfix Normal file
View File

@ -0,0 +1 @@
[Subscribing] Blank display name

View File

@ -21,6 +21,7 @@ import android.net.Uri
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor import org.matrix.android.sdk.api.auth.UserInteractiveAuthInterceptor
import org.matrix.android.sdk.api.session.identity.ThreePid 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.JsonDict
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
@ -118,4 +119,17 @@ interface ProfileService {
* Remove a 3Pid from the Matrix account. * Remove a 3Pid from the Matrix account.
*/ */
suspend fun deleteThreePid(threePid: ThreePid) 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
)
}
}
} }

View File

@ -18,6 +18,7 @@ package org.matrix.android.sdk.internal.session.sync
import android.os.SystemClock import android.os.SystemClock
import okhttp3.ResponseBody 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.logger.LoggerTag
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.initsync.InitSyncStep import org.matrix.android.sdk.api.session.initsync.InitSyncStep
@ -104,7 +105,11 @@ internal class DefaultSyncTask @Inject constructor(
val isInitialSync = token == null val isInitialSync = token == null
if (isInitialSync) { if (isInitialSync) {
// We might want to get the user information in parallel too // 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) defaultSyncStatusService.startRoot(InitSyncStep.ImportingAccount, 100)
} }
// Maybe refresh the homeserver capabilities data we know // Maybe refresh the homeserver capabilities data we know

View File

@ -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.EventType
import org.matrix.android.sdk.api.session.events.model.toContent 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.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.Room
import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams import org.matrix.android.sdk.api.session.room.members.roomMemberQueryParams
import org.matrix.android.sdk.api.session.room.model.Membership import org.matrix.android.sdk.api.session.room.model.Membership
@ -328,12 +327,12 @@ class RoomMemberProfileViewModel @AssistedInject constructor(
private suspend fun fetchProfileInfo() { private suspend fun fetchProfileInfo() {
val result = runCatchingToAsync { val result = runCatchingToAsync {
session.getProfile(initialState.userId) session.getProfileAsUser(initialState.userId)
.let { .let {
MatrixItem.UserItem( MatrixItem.UserItem(
id = initialState.userId, id = initialState.userId,
displayName = it[ProfileService.DISPLAY_NAME_KEY] as? String, displayName = it.displayName,
avatarUrl = it[ProfileService.AVATAR_URL_KEY] as? String avatarUrl = it.avatarUrl
) )
} }
} }

View File

@ -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.IdentityServiceError
import org.matrix.android.sdk.api.session.identity.IdentityServiceListener 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.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.session.user.model.User
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
@ -213,14 +212,10 @@ class UserListViewModel @AssistedInject constructor(
ThreePidUser(email = search, user = null) ThreePidUser(email = search, user = null)
} else { } else {
try { try {
val json = session.getProfile(foundThreePid.matrixId) val user = tryOrNull { session.getProfileAsUser(foundThreePid.matrixId) } ?: User(foundThreePid.matrixId)
ThreePidUser( ThreePidUser(
email = search, email = search,
user = User( user = user
userId = foundThreePid.matrixId,
displayName = json[ProfileService.DISPLAY_NAME_KEY] as? String,
avatarUrl = json[ProfileService.AVATAR_URL_KEY] as? String
)
) )
} catch (failure: Throwable) { } catch (failure: Throwable) {
ThreePidUser(email = search, user = User(foundThreePid.matrixId)) ThreePidUser(email = search, user = User(foundThreePid.matrixId))
@ -240,11 +235,11 @@ class UserListViewModel @AssistedInject constructor(
.searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty()) .searchUsersDirectory(search, 50, state.excludedUserIds.orEmpty())
.sortedBy { it.toMatrixItem().firstLetterOfDisplayName() } .sortedBy { it.toMatrixItem().firstLetterOfDisplayName() }
val userProfile = if (MatrixPatterns.isUserId(search)) { val userProfile = if (MatrixPatterns.isUserId(search)) {
val json = tryOrNull { session.getProfile(search) } val user = tryOrNull { session.getProfileAsUser(search) }
User( User(
userId = search, userId = search,
displayName = json?.get(ProfileService.DISPLAY_NAME_KEY) as? String, displayName = user?.displayName,
avatarUrl = json?.get(ProfileService.AVATAR_URL_KEY) as? String avatarUrl = user?.avatarUrl
) )
} else { } else {
null null