Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

How to display Favorited Users 5 Latest Post

Hi guyz,

 

Favorited Users 5 Latest Posts (previously known as 'Friends') with a link to follow through to the respective threads.

In short how can I display favourite user latest post?

Any API available there?

  • Hi guyz I got the solution for this requirement. Hope this may help someone else:


    <h3>Latest Posts from Favorites/Friends Users</h3> <br />
    <#assign whereclause = ""/>
    <#list restadmin("/users/id/${user.id}/addressbook/contacts/friends").users.user as user>
    <#if user??>
    <#assign whereclause = whereclause + "'" + user.id + "'" />
    <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
    </#if>
    </#list>

    <#if whereclause??>
    <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />
    <#if messages.data.items??>
    <#list messages.data.items as recent >
    <#if recent??>
    <a href="${recent.view_href}">${recent.subject}</a><br/>
    </#if>
    </#list>
    </#if>

    Note: If you will direct fetch the requirement using rest api then you can't show only 5 post. For that you have to use API V2. Like I did in above example.

     

    Cheers!

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)

    Hi bhupen 

     

    what about getting the contact list of the user 

     

    http://community.lithium.com/t5/Community-API/bd-p/developers-rest-api?leaf-id=Contacts.friends#Contacts.friends

     

    And then pull the recent posts for each friend? For the second part, I would use LIQL so that you can run one query for all the users you need. Something like

    SELECT id,view_href,subject FROM messages WHERE depth = 0 and author.id IN ('1','2','3') ORDER BY conversation.last_post_time DESC

    I haven't really tested the query - but you can have a look here and figure out which conditions to use to return the latest messages

     

    Hope this helps,

     

     

  • Hi guyz I got the solution for this requirement. Hope this may help someone else:


    <h3>Latest Posts from Favorites/Friends Users</h3> <br />
    <#assign whereclause = ""/>
    <#list restadmin("/users/id/${user.id}/addressbook/contacts/friends").users.user as user>
    <#if user??>
    <#assign whereclause = whereclause + "'" + user.id + "'" />
    <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
    </#if>
    </#list>

    <#if whereclause??>
    <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />
    <#if messages.data.items??>
    <#list messages.data.items as recent >
    <#if recent??>
    <a href="${recent.view_href}">${recent.subject}</a><br/>
    </#if>
    </#list>
    </#if>

    Note: If you will direct fetch the requirement using rest api then you can't show only 5 post. For that you have to use API V2. Like I did in above example.

     

    Cheers!