Returning Topic User avatar template with RSS feed


(Simon Cossar) #1

Could topic.user.avatar_template be returned with the latest and top RSS feed? It’s possible to get it with a API call, but it’s an expensive query if you’re looping through multiple items. There might be a more standard way of doing it, but this seems to work:

// list.rss.erb
// ...
        <% avatar_template = topic.user ? topic.user.avatar_template : "" %>
        <item>
          <title><%= topic.title %></title>
          <dc:creator><![CDATA[<%= "@#{username}#{" #{name}" if (name.present? && SiteSetting.enable_names?)}" -%>]]></dc:creator>
          <dc:avatar_template><%= "#{avatar_template}" -%></dc:avatar_template>

I’m turning the RSS feed into something like this:

Edit: I’ve looked into this a bit. Custom tags should be added to the discourse namespace, not the dc (Dublin Core) namespace.

This should be valid, but will only be recognized by a feed reader that’s written specifically for Discourse.

<discourse:avatarTemplate><%= "#{avatar_template}" -%></discourse:avatarTemplate>
<discourse:postsCount><%="#{topic.posts_count}" -%></discourse:postsCount>