Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Created December 18, 2015 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiny-Giant/db5476b7ff159d01ade7 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/db5476b7ff159d01ade7 to your computer and use it in GitHub Desktop.
Retrieves a variable number of events from the chat transcript.
/***************************************************
* GetChatEvents *
* You can only retrieve a maximum of 500 messages *
* from the transcript at one time, so you have to *
* search recursively. *
***************************************************/
var events = [];
function GetChatEvents(count, callback, before) {
if (count <= 0) return callback(events), false;
var data = {
fkey: fkey,
msgCount: count > 500 ? 500 : count,
mode: 'Messages',
};
if (before) data.before = before;
$.ajax({
type: 'POST',
url: '/chats/' + room + '/events',
data: data,
success: function(response) {
events.push(response.events);
GetChatEvents(count - 500, callback, response.events[0].message_id);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment