Forum Discussion

Claudius's avatar
4 years ago

How to obtain the current user's threaded message sort order?

I need to know what the thread message sort order of the current viewing user is. I am referring to this setting with the threaded view:

I looked at the admin page at /t5/bizapps/bizappspage/tab/community%3Aadmin%3Ainteractions%3Aforums%3Aforum-display and "Threaded format: Sorting order within topics" setting's radio ID to obtain the setting name "layout.threading_order". But when I query them  either way:

<#assign sort_order = restadmin("/settings/name/layout.sort_view_by_last_post_date").value />
${coreNode.settings.name.get("layout.sort_view_by_last_post_date", "none")}

both just returned "thread_descending" regardless of how I change this via the dropdown menu in above screenshot.

Anyone can share a way how I can obtain the currently active thread sort order programmatically?

(Client side looking via JavaScript at which dropdown item is selected won't work.)

  • Claudius,

    Code below will give you "Linear Format: Sorting order within topics"

    ${coreNode.settings.name.get("layout.linear_in_thread_sort", "none")}
     

     

    Code you have mentioned is for "Sort topics by", its value either true or false only.

    <#assign sort_order = restadmin("/settings/name/layout.sort_view_by_last_post_date").value />
    ${coreNode.settings.name.get("layout.sort_view_by_last_post_date", "none")}

     

    • Claudius's avatar
      Claudius
      Boss

      I indeed copied an older version of my code. But even the setting you suggested doesn't change when switching between "Oldest to Newest" and "Oldest to Newest". Here are the other settings I was looking at and the values they always return:
      layout.threading_order: thread_descending
      layout.linear_in_thread_sort: by_threading

      Someone else has any ideas what setting exposes the thread order sorting?

  • Claudius I cannot find much more info then this, and the above values only represent the initial setting of the ordering, not the current ordering.

    have you found a solution for this? I hope so, as I need the exact same thing (to hide a component depending on the sort order).

     

  • I have a way to detect the current sort order using javascript. I have added the following to my component and this seems to work fine!

     

     

    <#-- Hide the thing if the sort order is not Oldest to Newest -->
    
    <script>
    
    const sortObserver = new MutationObserver((mutations, obs) => {
        const sortMenu = document.querySelector('.lia-thread-sort-menu');
        if (sortMenu) {
            const divToHide = document.getElementById('highlighted_section');
            const sortOrderOldtonew = sortMenu.querySelector('[aria-label="Van oudste naar nieuwste"], [aria-label="Oldest to Newest"]');
            if (!sortOrderOldtonew && divToHide) {
                divToHide.style.display = 'none';
            }
            obs.disconnect();
            return;
      }
    });
    
    sortObserver.observe(document, {
      childList: true,
      subtree: true
    });
    
    </script>

     

     

    This searches for the id #actionMenuDropDown_4, inside class .lia-thread-sort-menu. If this doesn't exist drop down option#4 is not currently set and thus my target div is hidden.

    Claudius I am still curious if you found a better way to detect the current sort order.

    • Claudius's avatar
      Claudius
      Boss

      I couldn't find any context object or API call returning the sorting reliably, unfortunately 😐 So your client side solution seems to be the only feasible way so far.

      • Hoekstra_VFZ's avatar
        Hoekstra_VFZ
        Advisor

        Thanks, yeah the only thing we can retrieve out of the API are the initial settings, not the dynamic current setting of the sort order.

        Because the OOTB display for the solution/best answer is working fine based on the dynamic sort order I still think there is some trick only Khoros knows about.