chatreverse-engineeringstackexchange

Getting the exact timestamp of a Stack Exchange chat message


I'm currently working on (yet another) chat library, and I've been mostly successful gleaning data from the existing libraries, except for one tidbit:
Is there a way to get the exact timestamp of an arbitrary message?

/history only contains timestamps like "Sat 3:42 PM" (which require parsing, ugh), while the events websocket, the /events endpoint, and even /new return an exact timestamp. I've looked through master-chat.js to no avail.
Is there a way to do this for an arbitrary message given an id, or is inexact parsing needed?


Solution

  • Assuming you know the roomId of the room the message was posted you can do the following:

    1. POST to /chats/<roomId>/events passing the following information:

      fkey: "<your fkey>"
      msgCount: 2
      mode: "Messages"
      before: <msgId> + 1
      
    2. Grab the .events array from the JSON response.

    3. Search for the object with these properties: event_type: 1 (1 means message was posted) and message_id: <msgId>.

    Then, time_stamp is what you need (Unix epoch time).