We handle this for non-tabbed chat by fetching "new" messages, merging them with other messages we have queued up from KoLmafia chat, and then generating a response to the browser that has all of the messages. We don't do that for tabbed chat; we merge the new messages into the internal list, but we don't merge other messages and rewrite the response.
I envision we'd do it like this:
- Keep track of the timestamp (or something) of the last message we sent down to the browser
- when the Relay Browser wants to get new messages, ask KoL for them.
- extract them from the JSON into a list.
- If there are any messages on the internal list which arrived and were processed since the last time we send messages to the browser (which we can tell by comparing the saved timestamp, or something)
-- insert them into the list of messages from the latest request
-- generate a new JSON which includes all the the (new and old) messages
-- convert the JSON into a new responseText to send down to the browser.
- send the responseText to the browser - either exactly what KoL sent us, if there are no messages we got from the GUI chat, or the munged/combined list of messages.
That's not conceptually difficult, but I have the feeling getting it "right" will be tricky. Fortunately, our JSON package, which we use only to read JSON - api.php, volcano maze, CAB - also has the ability to write JSON into a string. I've been intending to figure out how to do that, anyway, for use by the ASH to_json() function.
I'm not sure I want to be the one to do it for new chat.
This probably deserves to go into a new Feature Request, since I don't think it has anything to do with this Bug report; the OP was not running KoLmafia's chat GUI.
I envision we'd do it like this:
- Keep track of the timestamp (or something) of the last message we sent down to the browser
- when the Relay Browser wants to get new messages, ask KoL for them.
- extract them from the JSON into a list.
- If there are any messages on the internal list which arrived and were processed since the last time we send messages to the browser (which we can tell by comparing the saved timestamp, or something)
-- insert them into the list of messages from the latest request
-- generate a new JSON which includes all the the (new and old) messages
-- convert the JSON into a new responseText to send down to the browser.
- send the responseText to the browser - either exactly what KoL sent us, if there are no messages we got from the GUI chat, or the munged/combined list of messages.
That's not conceptually difficult, but I have the feeling getting it "right" will be tricky. Fortunately, our JSON package, which we use only to read JSON - api.php, volcano maze, CAB - also has the ability to write JSON into a string. I've been intending to figure out how to do that, anyway, for use by the ASH to_json() function.
I'm not sure I want to be the one to do it for new chat.
This probably deserves to go into a new Feature Request, since I don't think it has anything to do with this Bug report; the OP was not running KoLmafia's chat GUI.