+ 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)
+ }
+ else {
+ // if xhr fails, this will make the link reappear so the user can try again
+ document.getElementById(target_div).innerHTML = original_text;
+ }
+ }
+ };
+ request.send();
+ request = null;
+}
+
+
+// Render a range of messages, with the div prefix specified
+//
+function forum_render_messages(msgs, prefix, scroll_to)
+{
+ for (i=0; i<msgs.length; ++i) {
+ forum_render_one(prefix+msgs[i], msgs[i], scroll_to)
+ }
+}
+
+
+// We have to put each XHR for forum_render_messages() into its own stack frame, otherwise it jumbles them together. I don't know why.
+function forum_render_one(div, msgnum, scroll_to)
+{
+ var request = new XMLHttpRequest();
+ request.open("GET", "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + msgs[i] + "/json", true);
+ request.onreadystatechange = function() {
+ if (this.readyState === 4) {
+ if ((this.status / 100) == 2) {
+ msg = JSON.parse(this.responseText);
+
+ document.getElementById(div).innerHTML =
+ "<div class=\"ctdl-msg-wrapper\">" // begin message wrapper
+ + "<div class=\"ctdl-avatar\">" // begin avatar
+ + "<img src=\"/ctdl/u/" + msg.from + "/userpic\" width=\"32\" "
+ + "onerror=\"this.parentNode.innerHTML='<i class="fa fa-user-circle fa-2x"></i> '\">"
+ + "</div>" // end avatar
+ + "<div class=\"ctdl-msg-content\">" // begin content
+ + "<div class=\"ctdl-msg-header\">" // begin header
+ + "<span class=\"ctdl-username\"><a href=\"#\">" // FIXME link to user profile
+ + msg.from
+ + "</a></span> "
+ + "<span class=\"ctdl-msgdate\">"
+ + msg.time
+ + "</span> "
+ + "</div>" // end header
+ + "<div>" // begin body
+ + msg.text
+ + "</div>" // end body
+ + "</div>" // end content
+ + "</div>" // end wrapper
+ ;