+ if (lt_msg < 9999999999) {
+ request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.lt|" + lt_msg, true);
+ }
+ else {
+ request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/msgs.gt|" + gt_msg, true);
+ }
+ request.onreadystatechange = function() {
+ if (this.readyState === 4) {
+ if ((this.status / 100) == 2) {
+ msgs = JSON.parse(this.responseText);
+ document.getElementById(target_div).innerHTML = "" ;
+
+ // If we were given an explicit starting point, by all means start there.
+ // Note that we don't have to remove them from the array because we did a 'msgs gt|xxx' command to Citadel.
+ if (gt_msg > 0) {
+ msgs = msgs.slice(0, messages_per_page);
+ }
+
+ // Otherwise, show us the last 20 messages
+ else {
+ if (msgs.length > messages_per_page) {
+ msgs = msgs.slice(msgs.length - messages_per_page);
+ }
+ new_old_div_name = randomString(5);
+ if (msgs.length < 1) {
+ newlt = lt_msg;
+ }
+ else {
+ newlt = msgs[0];
+ }
+ document.getElementById(target_div).innerHTML +=
+ "<div id=\"" + new_old_div_name + "\">" +
+ "<div align=\"center\">" +
+ "<a href=\"javascript:forum_readmessages('" + new_old_div_name + "', 0, " + newlt + ");\">" +
+ "<i class=\"fa fa-arrow-circle-up\"></i> " +
+ _("Older posts") + " <i class=\"fa fa-arrow-circle-up\"></a></div></div></a></div></div>" ;
+ }
+
+ // Render an empty div for each message. We will fill them in later.
+ for (var i in msgs) {
+ document.getElementById(target_div).innerHTML += "<div id=\"ctdl_msg_" + msgs[i] + "\"> </div>" ;
+ document.getElementById("ctdl_msg_"+msgs[i]).style.display = "none";
+ }
+ if (lt_msg == 9999999999) {
+ new_new_div_name = randomString(5);
+ if (msgs.length <= 0) {
+ newgt = gt_msg;
+ }
+ else {
+ newgt = msgs[msgs.length-1];
+ }
+ document.getElementById(target_div).innerHTML +=
+ "<div id=\"" + new_new_div_name + "\">" +
+ "<div align=\"center\">" +
+ "<a href=\"javascript:forum_readmessages('" + new_new_div_name + "', " + newgt + ", 9999999999);\">" +
+ "<i class=\"fa fa-arrow-circle-down\"></i> " +
+ _("Newer posts") + " <i class=\"fa fa-arrow-circle-down\"></a></div></div>" ;
+ }
+
+ // Now figure out where to scroll to after rendering.
+ if (gt_msg > 0) {
+ scroll_to = msgs[0];
+ }
+ else if (lt_msg < 9999999999) {
+ scroll_to = msgs[msgs.length-1];
+ }
+ else if ( (logged_in) && (gt_msg == 0) && (lt_msg == 9999999999) ) {
+ scroll_to = msgs[msgs.length-1];
+ }
+ else {
+ scroll_to = msgs[0]; // FIXME this is too naive
+ }
+
+ // Render the individual messages in the divs
+ forum_render_messages(msgs, "ctdl_msg_", scroll_to)