Solicitud de ayuda para encontrar el nombre completo de un usuario en el contexto de un componente de tema

Estoy intentando inyectar el nombre completo de un usuario en la plantilla Handlebars del tema destacado. No tengo problemas para insertar un valor de prueba en la plantilla, pero no logro obtener el valor que deseo. En el código a continuación, idealmente devolvería realname con el nombre completo del usuario como valor en lugar de “Test”:

<script type="text/discourse-plugin" version="0.8">
    var FeaturedTopicView = require('discourse/components/featured-topic').default;
    FeaturedTopicView.reopen({
        fullName: function() {
            // Obtener el nombre de usuario del último publicador
            let username = this.topic.last_poster.username;

            // Intentar obtener el nombre completo del usuario con el nombre de usuario establecido anteriormente
            let realname = Discourse.User.findByUsername(username).then(function(result) {
                               return result.name;
                           }).then(function(result) {
                               // ¡Esto nos da los nombres reales! Pero es inaccesible fuera de aquí
                               console.log(result);
                           });
            
            return "Test";
        }.property()
    });
</script>

El usuario que me interesa es el último publicador, por lo que en este caso parece que todo lo que tengo para trabajar es this.topic.last_poster. Esto tiene tres valores asociados: username, id y avatar_template. Lamentablemente, lo que realmente necesito es name.

Esperaba que hubiera algo que me permitiera buscar el nombre completo de un usuario usando id o username. No estoy muy familiarizado con el concepto de promesas y cómo usarlas, pero de alguna manera demostré un concepto usando Discourse.User.findByUsername(username). Puedo registrar correctamente con console.log los nombres completos que necesito, pero parecen estar atrapados en ese ámbito.

Podría estar abordando todo esto de la manera incorrecta, pero este fue mi mejor esfuerzo basado en mi conocimiento actual.

¡Cualquier ayuda o sugerencia sería muy apreciada! Por favor, hágame saber si necesito aclarar algo.

This is going to have to go in the serializer or you are going to be doing the worst kind of N+1 which is a Network+1

I am ok with last poster including name if the site has prioritize full names in the UI.

Otherwise you are going to need a plugin.

Thanks a bunch for your response, @sam!

It looks like “name” was included in the relevant serializer at one point, but was removed:

With that in mind, is it cool if I submit a PR with “name” back in place if the “prioritize full names” setting is enabled? Or is there a deeper reason to exclude this from core that I’m not aware of?

Hmmm @tgxworld is ill at the moment, can you hold a few days on this and remind me again Friday.

boop, reminder on Friday

It was added in this commit and I removed it because I was adding more overhead to the BasicUserSerializer when I only needed title/name in one spot of the app.

That reasoning makes sense. So with that in mind, what do you suggest as the most ideal solution to my problem? Is it worth doing a PR to include it once again for those concerned with prioritizing the full name of a user in any UI customizations, or is this something that should be restricted to a plugin? If you have any other suggestions on how to tackle this that I haven’t thought of, that would be great as well.

PS: Hope you are feeling all better :slight_smile: