Forum Discussion

dasyurid's avatar
11 years ago

Displaying most recent thread by user

Hi,

 

We want to make it easier for our members using our Help forum to relocate their threads more easily - specifically by placing a widget at the top of the forum index that shows them only their own created threads. Preferably, we'd only show them the threads that remain unsolved.

 

Any pointers on possible approaches? As a learner, I'm assuming I'd start with retrieving the threads, as these will include the information on who started the thread and whether it's been solved or not. That's simple - what I've struggled with it setting up the rest of the code to then restrict it to only display threads originated by the user and exclude those that have been solved.

 

Thanks in advance!

5 Replies

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

    Hi dasyurid ,

     

    for your requirement "the rest of the code to then restrict it to only display threads originated by the user and exclude those that have been solved."

     

    please look at this query

     

    http://community.lithium.com/restapi/vc/search/messages?solved=false&author_id=25880&q=is_root:true

     

    1. solved=false ==> exclude those that have been solved
    2. author_id=25880 ==> originated by the user 25880 (it is you :) )
    3. q=is_root:true ==> topics only, i.e. excluding replies.

     

    I hope that this helps.

     

  • dasyurid's avatar
    dasyurid
    Ace
    11 years ago

    HaidongG That's getting very close to what we want. When testing it on our staging board, however, it's picking up threads I've contributed to but was not the original thread creator. It's also picking up threads that are solved where I've contributed and my post is not the solution.

     

    What I'm specifically after maybe better illustrated with an example:

     

    Within the Help board, we have four threads:

     

    Thread A - started by me, has a solution marked.

    Thread B - started by you, no solution marked.

    Thread C - started by me, no solution marked.

    Thread D - started by a.n.other, I've posted a reply, no solution marked.

     

    The component we want to create would then look through the threads and:

     

    If I am logged in, it shows me Thread C

     

    If you are logged in, it shows Thread B

     

    If a.n.other is logged in, it shows Thread D

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

    Hi dasyurid ,

     

    I realised that we should use "author_id" instead of "user_id" in my previous example, may you want to try that out? I will update my original reply too.

  • dasyurid's avatar
    dasyurid
    Ace
    11 years ago

    Bingo!

     

    Many thanks - that's pulling nicely.

     

    We've further refined it, as follows, to get it to only pull from the one forum, get it to sort by most recently created thread at the top, and only return a maximum of 5 threads:

     

    /boards/id/[board_id]/search/messages?solved=false&author_id=${user.id}&q=is_root:true&sort_by=-latestPostDate&page_size=5

     

    This so far appears to be giving us what we wanted.