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 1 commit
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 @@ -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.getProfile(userId) }
userStore.createOrUpdate(
userId = userId,
displayName = user?.get(ProfileService.DISPLAY_NAME_KEY) as? String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe take the opportunity to create some helper to avoid doing that everywhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other places we're using this logic, could be a function in the class for now until we have another usage?

or do you mean helpers for fun User.getDisplayName() : String?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ganfra if we add the small part in a private method in SyncTask class is enough for you ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed a similar code in that file
We can probably have a function returning a User object from the given userId and the related profile dictionary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, @Claire1817 add it to the interface ProfileService please.

Something like:

    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
            )
        }
    }

avatarUrl = user?.get(ProfileService.AVATAR_URL_KEY) as? String)
defaultSyncStatusService.startRoot(InitSyncStep.ImportingAccount, 100)
}
// Maybe refresh the homeserver capabilities data we know
Expand Down