Browse Source

always load old scrollback buffer (up to 50 lines) instead of limiting by timestamp (2)

Andrew Dolgov 7 years ago
parent
commit
005cfbfd7f
1 changed files with 18 additions and 0 deletions
  1. 18 0
      functions.php

+ 18 - 0
functions.php

@@ -575,7 +575,23 @@
 			'$message_type', NOW())");
 	}
 
+	function get_initial_last_id($link) {
+		$result = db_query($link, "SELECT ttirc_messages.id
+			FROM ttirc_messages, ttirc_connections
+			WHERE
+				owner_uid = ".$_SESSION["uid"]." AND
+				connection_id = ttirc_connections.id
+			ORDER BY id DESC LIMIT 1 OFFSET 50");
+
+		if (db_num_rows($result) != 0) {
+			return db_fetch_result($result, 0, "id");
+		} else {
+			return 0;
+		}
+	}
+
 	function num_new_lines($link, $last_id) {
+		if (!$last_id) $last_id = get_initial_last_id($link);
 
 		$result = db_query($link, "SELECT COUNT(*) AS cl
 			FROM ttirc_messages, ttirc_connections WHERE
@@ -589,6 +605,8 @@
 
 	function get_new_lines($link, $last_id, $rewrite_urls = true) {
 
+		if (!$last_id) $last_id = get_initial_last_id($link);
+
 		$result = db_query($link, "SELECT ttirc_messages.id,
 			message_type, sender, channel, connection_id, incoming,
 			message, ".SUBSTRING_FOR_DATE."(ts,1,19) AS ts