Browse Source

updater improvements; store user last_message

Andrew Dolgov 2 years ago
parent
commit
059d440f60

+ 2 - 0
backend.php

@@ -205,6 +205,8 @@
 					}
 				}
 
+				update_last_message();
+
 				if (is_instance($connection_id)) {
 
 					$lines = array_map("trim", explode("\n", $message));

+ 1 - 1
daemon/src/org/fox/ttirc/Master.java

@@ -16,7 +16,7 @@ public class Master {
 	
 	public static enum DbType { MYSQL, PGSQL };
 	
-	private final int m_schemaVersion = 14;
+	private final int m_schemaVersion = 15;
 	
 	private String m_dbKeyParam;
 	

+ 14 - 0
include/functions.php

@@ -1227,6 +1227,20 @@
 		return $rcolors[$sum];
 	}
 
+	function update_last_message() {
+
+		$dbh = DB::get();
+
+		if (time() - $_SESSION["message_last"] > 180) {
+
+			$sth = $dbh->prepare("UPDATE ttirc_users SET last_message = NOW()
+				WHERE id = ?");
+			$sth->execute([$_SESSION['uid']]);
+
+			$_SESSION["message_last"] = time();
+		}
+	}
+
 	function update_heartbeat() {
 
 		$dbh = DB::get();

+ 1 - 1
include/sanity_check.php

@@ -1,7 +1,7 @@
 <?php
 	require_once "functions.php";
 
-	define('SCHEMA_VERSION', 14);
+	define('SCHEMA_VERSION', 15);
 	define('EXPECTED_CONFIG_VERSION', 2);
 
 	$err_msg = "";

+ 2 - 1
schema/ttirc_schema_pgsql.sql

@@ -34,6 +34,7 @@ create table ttirc_users (id serial not null primary key,
 	email varchar(250) not null,
 	nick varchar(120) not null,
 	heartbeat timestamp default null,
+	last_message timestamp default null,
 	quit_message varchar(120) not null default '',
 	hide_join_part boolean not null default false,
 	realname varchar(120) not null,
@@ -160,6 +161,6 @@ create table ttirc_emoticons_popcon (id serial not null primary key,
 
 create table ttirc_version (schema_version int not null);
 
-insert into ttirc_version values (14);
+insert into ttirc_version values (15);
 
 commit;

+ 7 - 0
schema/versions/pgsql/15.sql

@@ -0,0 +1,7 @@
+begin;
+
+alter table ttirc_users add column last_message timestamp;
+
+update ttirc_version set schema_version = 15;
+
+commit;

+ 8 - 2
update.php

@@ -136,7 +136,10 @@ function confirmOP() {
 						$query = trim(getline($fp, ";"));
 						if ($query != "") {
 							print "<p class='query'>$query</p>";
-							$dbh->query($query);
+
+							if (!$dbh->query($query)) {
+								print "<p class='warning'>Query failed!</p>";
+							}
 						}
 					}
 				}
@@ -145,7 +148,10 @@ function confirmOP() {
 				print "<p>".__("Checking version... ");
 
 				$row = $dbh->query("SELECT schema_version FROM ttirc_version")->fetch();
-				$version = $row['version'];
+
+				$version = $row['schema_version'];
+
+				print "(got: $version): ";
 
 				if ($version == $v) {
 					print __("OK!");