aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2014-02-09 16:47:06 -0800
committerfriendica <info@friendica.com>2014-02-09 16:47:06 -0800
commitcf3b76c0460888c56263f0f03a2115c7c666b8c7 (patch)
tree1432d8c7eab5eed97030addbfd519f040dad9c6b
parent9f6d0a2676b6eeba2458eff4d98d735a20360d04 (diff)
downloadvolse-hubzilla-cf3b76c0460888c56263f0f03a2115c7c666b8c7.tar.gz
volse-hubzilla-cf3b76c0460888c56263f0f03a2115c7c666b8c7.tar.bz2
volse-hubzilla-cf3b76c0460888c56263f0f03a2115c7c666b8c7.zip
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.
-rw-r--r--mod/chat.php43
1 files changed, 43 insertions, 0 deletions
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']);