From cf3b76c0460888c56263f0f03a2115c7c666b8c7 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 9 Feb 2014 16:47:06 -0800 Subject: backend for chatroom activity monitor - honours permissions and returns (json) how many in room and last chat timestamp, regardless of whether the observer is actually in the room. --- mod/chat.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'mod') diff --git a/mod/chat.php b/mod/chat.php index 872571f8c..a960f4f37 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -99,6 +99,49 @@ function chat_content(&$a) { } + if((argc() > 3) && intval(argv(2)) && (argv(3) === 'status')) { + $ret = array('success' => false); + $room_id = intval(argv(2)); + if(! $room_id || ! $observer) + return; + + $r = q("select * from chatroom where cr_id = %d limit 1", + intval($room_id) + ); + if(! $r) { + json_return_and_die($ret); + } + require_once('include/security.php'); + $sql_extra = permissions_sql($r[0]['cr_uid']); + + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval($r[0]['cr_uid']) + ); + if(! $x) { + json_return_and_die($ret); + } + $y = q("select count(*) as total from chatpresence where cp_room = %d", + intval($room_id) + ); + if($y) { + $ret['success'] = true; + $ret['chatroom'] = $r[0]['cr_name']; + $ret['inroom'] = $y[0]['total']; + } + + // figure out how to present a timestamp of the last activity, since we don't know the observer's timezone. + + $z = q("select created from chat where chat_room = %d order by created desc limit 1", + intval($room_id) + ); + if($z) { + $ret['last'] = $z[0]['created']; + } + json_return_and_die($ret); + } + + if(argc() > 2 && intval(argv(2))) { $room_id = intval(argv(2)); $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); -- cgit v1.2.3