aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xboot.php2
-rw-r--r--include/chat.php10
-rw-r--r--install/database.sql4
-rw-r--r--install/update.php11
4 files changed, 22 insertions, 5 deletions
diff --git a/boot.php b/boot.php
index 7be74e64a..9048223bf 100755
--- a/boot.php
+++ b/boot.php
@@ -46,7 +46,7 @@ define ( 'RED_PLATFORM', 'Red Matrix' );
define ( 'RED_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 );
-define ( 'DB_UPDATE_VERSION', 1094 );
+define ( 'DB_UPDATE_VERSION', 1095 );
define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
diff --git a/include/chat.php b/include/chat.php
index b88c63fc3..08fd154b5 100644
--- a/include/chat.php
+++ b/include/chat.php
@@ -31,16 +31,19 @@ function chatroom_create($channel,$arr) {
return $ret;
}
+ if(! array_key_exists('expire',$arr))
+ $arr['expire'] = 120; // minutes, e.g. 2 hours
$created = datetime_convert();
- $x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, allow_cid, allow_gid, deny_cid, deny_gid )
- values ( %d, %d , '%s', '%s', '%s', '%s', '%s', '%s', '%s' ) ",
+ $x = q("insert into chatroom ( cr_aid, cr_uid, cr_name, cr_created, cr_edited, cr_expire, allow_cid, allow_gid, deny_cid, deny_gid )
+ values ( %d, %d , '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s' ) ",
intval($channel['channel_account_id']),
intval($channel['channel_id']),
dbesc($name),
dbesc($created),
dbesc($created),
+ intval($arr['expire']),
dbesc($arr['allow_cid']),
dbesc($arr['allow_gid']),
dbesc($arr['deny_cid']),
@@ -111,6 +114,9 @@ function chatroom_enter($observer_xchan,$room_id,$status,$client) {
return false;
}
+ if(intval($x[0]['cr_expire']))
+ $r = q("delete from chat where created < UTC_TIMESTAMP() - INTERVAL " . intval($x[0]['cr_expire']) . " MINUTE and chat_room = " . intval($x[0]['cr_id']));
+
$r = q("select * from chatpresence where cp_xchan = '%s' and cp_room = %d limit 1",
dbesc($observer_xchan),
intval($room_id)
diff --git a/install/database.sql b/install/database.sql
index dba03da65..c89e4cef2 100644
--- a/install/database.sql
+++ b/install/database.sql
@@ -247,6 +247,7 @@ CREATE TABLE IF NOT EXISTS `chatroom` (
`cr_name` char(255) NOT NULL DEFAULT '',
`cr_created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`cr_edited` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `cr_expire` int(10) unsigned NOT NULL DEFAULT '0',
`allow_cid` mediumtext NOT NULL,
`allow_gid` mediumtext NOT NULL,
`deny_cid` mediumtext NOT NULL,
@@ -256,7 +257,8 @@ CREATE TABLE IF NOT EXISTS `chatroom` (
KEY `cr_uid` (`cr_uid`),
KEY `cr_name` (`cr_name`),
KEY `cr_created` (`cr_created`),
- KEY `cr_edited` (`cr_edited`)
+ KEY `cr_edited` (`cr_edited`),
+ KEY `cr_expire` (`cr_expire`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `clients` (
diff --git a/install/update.php b/install/update.php
index 180b8d5a0..e8b6d37f6 100644
--- a/install/update.php
+++ b/install/update.php
@@ -1,6 +1,6 @@
<?php
-define( 'UPDATE_VERSION' , 1094 );
+define( 'UPDATE_VERSION' , 1095 );
/**
*
@@ -1060,3 +1060,12 @@ function update_r1093() {
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}
+
+function update_r1094() {
+ $r = q("ALTER TABLE `chatroom` ADD `cr_expire` INT UNSIGNED NOT NULL DEFAULT '0' AFTER `cr_edited` ,
+ADD INDEX ( `cr_expire` )");
+ if($r)
+ return UPDATE_SUCCESS;
+ return UPDATE_FAILED;
+}
+