Skip to content
Mostey edited this page Mar 10, 2015 · 5 revisions

Thread Replies

Introduction

As presented earlier in another wiki page you can query the available threads of a section and get some basic information about them. You may also update the replies to this thread using the functions described and illustrated in the samples below.

Sample

As of now, replies can be retrieved using the SectionThread.Replies function demonstrated below:

foreach (var thread in Section.Main.Threads(session)) // get all threads of the main section
{
    var replies = thread.Replies(session); // get all replies for every thread
    // or: thread.Replies(session, 5, 2) that gets 5 pages starting from page 2
    Console.WriteLine("Thread: " + thread.InitialPost.Title); // print the thread title to the screen
    foreach (var reply in replies)
    {
        // print the post creator (Sender) and the post content to the screen
        Console.WriteLine("Reply from {0}: {1}", reply.Sender.Name, reply.Content); 
    }
}

Further usage

The function definitions are declared as follows:

List<SectionPost> Replies<TUser>(AuthenticatedSession<TUser> session, uint firstPage = 1)

Fetches all replies (optionally beginning from the firstPage offset) based on the PageCount property in the SectionThread class that is set when updating using the SectionThread.Update method.

List<SectionPost> Replies<TUser>(AuthenticatedSession<TUser> session, uint pageCount, uint firstPage)

Fetches all replies beginning from the firstPage offset (that needs to be greater equals 1) for n (pageCount) number of pages. If pageCount is 5 and firstPage is 2, 5 pages will be fetched: 2, 3, 4, 5 and 6.

  • pageCount stands for the amount of pages to get replies from. The higher this count, the more data will be generated and received
  • firstPage is the index of the first page to parse. By default, this value is set to 1 representing the first page of the thread. Note that this value can't be 0 although offsets typically start at 0. Actually this shouldn't make any difference since the forum software should automatically detect that and redirect you. However, be warned if something awkward is happening if you do that.

Affected properties

The following SectionPost properties are currently implemented to be updated on execution:

  • ID as uint
  • Date as DateTime
  • Title as string
  • Content as Content
  • Sender.ID as uint
  • Sender.Name as string
  • Sender.Title as string
  • Sender.Ranks as List<User.Rank>
  • Sender.EliteGold as uint
  • Sender.TBMProfile.Ratings as TBM.Ratings
  • Sender.TBMProfile.Mediations as TBM.Mediations (if the sender enabled his middleman setting)
  • Sender.JoinDate as DateTime
  • Sender.Posts as uint
  • Sender.ReceivedThanks as uint

Remarks

Besides the actual replies, this code also updates the mentioned properties of the SectionThread.InitialPost object which is referring to the post that originally started the SectionThread.

Please note that the code behind this is still maintained and improved. We know that the post contents do only contain plain-text responses so don't worry if images aren't returned. To manage quotes, code formattings and images, a new framework will be implemented soon that deals with these issues.


Updating information about Threads

Introduction

You may update your SectionThread object to get some useful properties filled with values. The function performs a HTTP GET request and parses the returned HTML response.

Sample

Updating is as easy as it get's:

foreach (var thread in Section.Main.Threads(session)) // get all threads of the main section
{
    thread.Update(session); // fill the thread with additional data
    // although more properties got filled with values (due to retrieving the section threads),
    // these properties are affected of the call on thread.Update
    Console.WriteLine("Closed? {0}", thread.Closed);
    Console.WriteLine("Rating: {0}", thread.Rating);
    Console.WriteLine("Amount of pages: {0}", thread.PageCount);
    Console.WriteLine("Tags: ");
    foreach(var tag in thread.Tags)
        Console.WriteLine("- {0}", tag);
}

If you want to learn more about querying threads directly from a Section for getting more information about threads, refer to this wiki page

Affected properties

The following SectionThread properties are currently implemented to be updated on execution:

  • Closed as bool
  • Rating as double
  • PageCount as uint
  • Tags as List<string>

Remarks

ID and the section represented by a Section object is required in order to update.