Forum Discussion

William's avatar
William
Helper
13 years ago

How to get the topic status via api?

as subject, we are looking for a way to get this via api, we noticed that there are couple status for the topics, like hot topic, topic with new content, topic replied by youself, locked topic and so on, but i seems that we cannot find those api from the api docs. is there anybody can help? we want to track this, and display those status icons.

 

thanks

William

2 Replies

  • I'm also very interested in this for our community. Ideally, I'd like the API to be able to give me both the status as a string and as a href to the icon that matches the status in question.

     

    Is this possible already or am I better off creating an idea in the Ideas section?

  • I don't see any direct API to do this, but this is all buildable indirectly using, for example, the User and Messages APIs.  For example, let's say you want to determine if a thread is "hot".  First, get the value of the layout.messages_per_thread_hot setting using the REST Settings API.  Then, if the number of messages in a given thread are greater or equal to that number, then you know the thread is hot.

     

    <#assign hot_threshold = restadmin("/settings/name/layout.messages_per_thread_hot").value />
    <#assign thread = rest("/threads/id/${myId}").thread />
    <#if (thread.messages.count >= hot_threshold)>
      <font style="color: #FF0000;">HOT!</font>
    </#if>

     For new content, you want to use the "read" count method of the Messages API.  Compare that to the total number of messages in the thread.  You know there is unread content if the two numbers are not the same.

     

    <#assign thread = rest("/threads/id/${myId}").thread />
    <#assign read_count = rest("/threads/id/${myId}/messages/read/count").value />
    <#if (thread.messages.count > read_count)>
      <p>Thread has ${thread.messages.count - read_count} unread messages.</p>
    </#if>

     

    For replies, it's a bit more involved, but you can get a list of replies the user has made using the /users/id/${user.id?c}/replies/get/messages API.  Then, for each message in the thread, see if that message ID is found in the list of user replies.  There may be an easier way here, but I haven't found a way to do an O(1) lookup of a message ID in the list of user replies.

     

    For locked, I'm not sure.  Maybe the read_only property of the thread message is reflective of that state?  We don't use the locked state, so I cannot comment.