From 6e22aa25cc941f542a192ef32a2e8ee4f23bb1c1 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 28 Jan 2014 15:52:54 -0800 Subject: basic presence indication --- mod/ping.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'mod/ping.php') diff --git a/mod/ping.php b/mod/ping.php index dda87dec2..b9ecf9b41 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -43,6 +43,31 @@ function ping_init(&$a) { unset($_SESSION['sysmsg_info']); } + if(get_observer_hash() && (! $result['invalid'])) { + $r = q("select cp_id from chatpresence where cp_xchan = '%s'", + dbesc(get_observer_hash()) + ); + if($r) { + foreach($r as $rr) { + q("update chatpresence set cp_last = '%s' where cp_id = %d limit 1", + intval($rr['cp_id']) + ); + } + } + else { + q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client) + values( '%s', '%s', '%s', '%s' ) ", + dbesc(get_observer_hash()), + dbesc(datetime_convert()), + dbesc('online'), + dbesc($_SERVER['REMOTE_ADDR']) + ); + } + } + + q("delete from chatpresence where cp_last < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); + + if((! local_user()) || ($result['invalid'])) { echo json_encode($result); killme(); -- cgit v1.2.3