Forum Discussion

elbranscomb's avatar
elbranscomb
Executive
2 years ago

Trending Messages - Override component questions

I would like to override the Trending Messages (Discussions) component that has the following OOB code. I would like to have this component display the most popular posts on the Home Page, Category or Board page types by both kudos and comments. Is this possible?

I would also for this to not just be a list of hyperlinks to results but include potentially # of comments & kudos or the date of the last comment. Is this possible to add that in. 

Here is the OOB code for the component theme-lib.trending-messages that I would like to adapt. Has anyone had success with adapting this to display a more limited time frame and use kudos and comments as the criteria for the results?

<@liaMarkupCache ttl="100000" variation="node" anonymousOnly="true" />
<#include "theme-lib.common-functions" />
<#include "theme-lib.message-macros" />

<#assign targetNodeType = coreNode.nodeType />
<#assign targetNodeId = coreNode.id />
<#assign whereClause = "" />

<#if targetNodeType == "board">
	<#assign whereClause = "board.id = '${targetNodeId}' AND " />
<#elseif targetNodeType == "category">
	<#assign whereClause = "category.id = '${targetNodeId}' AND " />
</#if>

<#assign pageSize = coreNode.settings.name.get("custom.trending_messages_count", "3") />
<#assign prevTS = .now?date?long-(coreNode.settings.name.get("custom.trending_messages_history_days", "30")?number*24*60*60*1000) />

<#assign whereClause = whereClause + "post_time >= ${prevTS} AND depth = 0" />

<#assign articles = getMessages(pageSize, 0, "id, subject, view_href", whereClause, "kudos.sum(weight) DESC") />
<#if articles?size gt 0>
	<@generateComponentContent className="theme-lib-trending-messages" componentTitleKey="theme-lib.trending.messages.title" >
		<div class="trending-messages-list">
			<#list articles as article>
				<div class="trending-message-item">
					<a href="${(article.view_href)!""}">${(article.subject)!""}</a>
				</div>
			</#list>
		</div>
	</@generateComponentContent>
</#if>

 

  • elbranscomb 

    Kudos, comments counts and last comment date can be added with some customozation. 
    You can add these selectors(conversation.last_post_time, conversation.messages_count) in getMassages API call. 

    <#assign articles = getMessages(pageSize, 0, "id, subject, view_href,conversation.last_post_time, conversation.messages_count", whereClause, "kudos.sum(weight) DESC") />

     Inside the <#list>, get kudos count for every messaes as in API V2, we can not get the kudos count without passing message id. Here is the API to get it


    SELECT * FROM kudos WHERE message.id = 'article.id'

    Now you can use these new values inside the <#list> to show with every message hyperlink in the list. 

     

    You can not use two constraints(Kudos and Comments) in WHERE clouse.

  • Thanks for sharing these instructions. I was able to do the first part but am not sure I understand how to add the additional items into the <#list>. Can you confirm where I need to drop the select code into my existing code?

    <div class="trending-messages-list">
    <#list articles as article>
    <div class="trending-message-item">
    <a href="${(article.view_href)!""}">${(article.subject)!""}</a>
    </div>
    </#list>
    </div>

     

    I am assuming I need to drop both the Kudos and Comments count for the post into individual <div></div> to have them appear on separate lines beneath the linked subject?

  • elbranscomb 
    Yes, need to add this new query inside the <#list>

    <div class="trending-messages-list">
    <#list articles as article>
    
    <#assign kudosCount = rest("2.0","/search?q=" + ("SELECT * FROM kudos WHERE message.id = '${article.id}'")?url).data.size />
    
    <div class="trending-message-item">
    <a href="${(article.view_href)!""}">${(article.subject)!""}</a>
    </div>
    
    <div>Likes: ${kudosCount} Last Updated: ${article.conversation.messages_count-1}<div>
    </#list>
    </div>

    Here is the screenshot for refernece: https://prnt.sc/GBUnaQmMpuYZ