Forum Discussion

snaffle's avatar
snaffle
Expert
11 years ago

Sort Topics list by latest message reply

I'm looking for some help/advice on sorting

I've got a custom component that displays the topics for any given forum board and I'm trying to work out how to sort the topics in order of the most recent reply to any of the topics.

So if a topic from a couple of weeks ago gets a new reply it should then appear at the top of the topics list.

At the moment, the topics list is being generated with the following:

<#assign msgList = restadmin("/boards/id/${coreNode.id}/topics?restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />

..and is being displayed with:

<#list msgList.message as msg>
topic goes here
</list>

I've had a look through the developer community and found some references to a "sort_by" parameter but it seems to only work with search queries to the API.

Is there a parameter I can add to the "restadmin" call to sort the topics by the date/time of the most recent reply?

Thanks

Nathan

5 Replies

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi snaffle ,

     

    fist of all, if there is no particular reason, we should always use "rest()' instead of 'restadmin()', as restadmin() may carry some private inforamtion which should not been seen by normal user.

     

    for your query, is there any chances to convert /boards/id/${coreNode.id}/topics to /boards/id/${coreNode.id}/search/messages/count?q=is_root:true, which has the same effect to bring topic-only nodes. from that you will be able to use sort_by.

     

    last but very minor, it is not necessary to add "restapi.response_style=view" to rest() or restadmin() calls, as both calls with automatically add "restapi.response_style=view" to your query string.

     

    I hope that it helps.

  • snaffle's avatar
    snaffle
    Expert
    11 years ago

    Hi @Haidong.

    I've taken over this component from another developer and to be honest I am still in the process of learning Freemarker and in particular what API calls work where, so I really appreciate your help.

    The custom component in question is basically replacing the default topics list for each forum board. This was done to satisfy design requirements for the client. You can see what I mean at this link - http://saneforums.org/t5/Our-stories/bd-p/forum-001.

    So I'm not 100% sure, but I believe "restadmin()" was used instead of just "rest()" because there are administrator/moderator only forum boards that need to be accessed. Access to these boards is managed through the use of Roles and if/else statements. Nonetheless, I will test on the staging server replacing the calls with just "rest()" and see if everything still functions.

    Likewise, I'll remove the "restapi.response_style=view" part from the API call and make sure it all still works.

    Now, in terms of the query itself, I've tried both your method and NicoB's method and they partly work.

    The custom component also includes a call to generate the page navigation so I updated that call as well. So, using your example for the page navigation:

    Old - <#assign resultSize = restadmin("/boards/id/${coreNode.id}/topics/count").value />

    New - <#assign resultSize = restadmin("/boards/id/${coreNode.id}/search/messages/count?q=is_root:true").value />

    And for the main API call:

    Old - <#assign msgList = restadmin("/boards/id/${coreNode.id}/topics?restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />

    New - <#assign msgList = restadmin("/boards/id/${coreNode.id}/search/messages/count?q=is_root:true&restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />

    Changing the above correctly returns the page navigation, showing 3 pages and a link to each page.

    The problem though is that it doesn't return any of the topic content itself, just a blank page. I've attached a screenshot which shows the result.

    So it seems that the code which displays the topics doesn't work once I've changed the main API call:

    <#list msgList.message as msg>
        topics go here
    </#list>

    So I'm working my way through the API docs to figure out why it's not working but if you have any ideas on what needs to change here I'd be greatly appreciative.

    Thanks

    Nathan


    navigation_no_topics.jpg
  • snaffle's avatar
    snaffle
    Expert
    11 years ago

    Hi @NicoB,

    Thanks for your suggestion, but as per my reply to Haidong, when I change the calls:

    Page Navigation - <#assign resultSize = restadmin("/boards/id/${coreNode.id}/topics/recent/count").value />

    Topics List Call - <#assign msgList = restadmin("/boards/id/${coreNode.id}/topics/recent?restapi.format_detail=full_list_element&restapi.response_style=view&page_size=${page_size}&page=${page_number}").node_message_context />

    I get the page navigation returned correctly, but the topics themselves don't display.

    Likewise, any suggestions you might have as to what needs to change with <#list msgList.message as msg> would be greatly appreciated.

    Thanks

    Nathan

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi snaffle ,

     

    There is no node_message_context under /messages/search node, you may try out this URL on your web browser to understand the returned data structure.

     

    http://<community_url>/restapi/vc/search/messages?q=is_root:true

     

    I hope that it helps.

     

    btw: it is tough to replace the whole message list component, it could be better to customize existing message list instead of creating one your own. maybe you can talk to the business user and understand their needs on this.