Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Subscribing] Blank display name #5603

Merged
merged 6 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5497.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Subscribing] Blank display name
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -118,4 +119,17 @@ interface ProfileService {
* Remove a 3Pid from the Matrix account.
*/
suspend fun deleteThreePid(threePid: ThreePid)

/**
* Return an User object from an 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
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ 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
import org.matrix.android.sdk.api.session.initsync.SyncStatusService
import org.matrix.android.sdk.api.session.profile.ProfileService
import org.matrix.android.sdk.api.session.statistics.StatisticEvent
import org.matrix.android.sdk.api.session.sync.model.LazyRoomSyncEphemeral
import org.matrix.android.sdk.api.session.sync.model.SyncResponse
Expand Down Expand Up @@ -104,7 +106,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,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
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ class UserListViewModel @AssistedInject constructor(
ThreePidUser(email = search, user = null)
} else {
try {
val json = session.getProfile(foundThreePid.matrixId)
val user = session.getProfileAsUser(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
displayName = user.displayName,
avatarUrl = user.avatarUrl
)
)
} catch (failure: Throwable) {
Expand All @@ -241,11 +241,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
Claire1817 marked this conversation as resolved.
Show resolved Hide resolved
)
} else {
null
Expand Down