4chan / 4chan-API

Documentation for 4chan's read-only JSON API.
http://www.4chan.org/
1.02k stars 73 forks source link

Document tail api #79

Open shiimizu opened 4 years ago

shiimizu commented 4 years ago

Document tail_size and tail_id. https://github.com/4chan/4chan-API/issues/46#issuecomment-254887337

From what I understand, this endpoint ({thread-id}-tail.json) is exclusively used by the JavaScript extension but would be a great asset to developers wanting to reduce bandwidth by knowing how & when it's emitted.

Furthermore, tail_size seems to appear randomly in threads ({thread-id}.json), no matter how big or small the thread. Maybe with {thread-id}-tail.json, is there a way to reliably get a list of posts past a specified If-Modified-Since?

catamphetamine commented 3 years ago

@shiimizu Doesn't the following tactics work?

On auto-refresh timer:

  1. Query -tail.json. If it doesn't exist, then perform a full thread refresh and go to step 5.
  2. Check if posts[0].tail_id is less than or equal to the current latestCommentId.
  3. If it is, then there're no missed comments. Append new comments starting from id > latestCommentId.
  4. If it's not, then it means that since the last "auto-refresh" there have been too much new comments and some of them are missing in -tail.json, so perform a full thread refresh.
  5. Update the latestCommentId and wait for the next auto-refresh.
posts[0] = {
    // Thread id.
    "no": 185776347,

    // Is "bump limit" reached?
    "bumplimit": 0,

    // Is "image limit" reached?
    "imagelimit": 0,

    // Total comments count in the thread,
    // not including the "main" ("original") comment.
    "replies": 195,

    // Total attachments count in the thread.
    "images": 82,

    // Unique poster IPs count.
    "unique_ips": 44,

    // The length of the `posts[]` array
    // (minus one for the opening post)
    // in this API response.
    "tail_size": 50,

    // The `id` of the comment which comes before
    // the first comment of the "tail".
    // In other words, the `id` of the last comment
    // not included in the "tail" API response.
    "tail_id": 185788827
}