From b8fb6a437335ce16e658f8acda632916bb28e574 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 17:09:20 -0800 Subject: more chat infrastructure --- mod/chat.php | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 mod/chat.php (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php new file mode 100644 index 000000000..bc981b76b --- /dev/null +++ b/mod/chat.php @@ -0,0 +1,62 @@ + 1) + $which = argv(1); + if(! $which) { + if(local_user()) { + $channel = $a->get_channel(); + if($channel && $channel['channel_address']) + $which = $channel['channel_address']; + } + } + if(! $which) { + notice( t('You must be logged in to see this page.') . EOL ); + return; + } + + $profile = 0; + $channel = $a->get_channel(); + + if((local_user()) && (argc() > 2) && (argv(2) === 'view')) { + $which = $channel['channel_address']; + $profile = argv(1); + } + + $a->page['htmlhead'] .= '' . "\r\n" ; + + // Run profile_load() here to make sure the theme is set before + // we start loading content + + profile_load($a,$which,$profile); + +} + + +function chat_content(&$a) { + + if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'chat')) { + notice( t('Permission denied.') . EOL); + return; + } + + if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { + chatroom_leave(get_observer_hash(),$room_id,$_SERVER['REMOTE_ADDR']); + goaway(z_root() . '/channel/' . argv(1)); + } + + + if(argc() > 2 && intval(argv(2))) { + $room_id = intval(argv(2)); + $x = chatroom_enter(get_observer_hash(),$room_id,'online',$_SERVER['REMOTE_ADDR']); + if(! $x) + return; + $o = replace_macros(get_markup_template('chat.tpl'),array()); + return $o; + } + +} \ No newline at end of file -- cgit v1.2.3 From c24aa824fe49d6dc803fb58c577d2238db416f2f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 18:19:19 -0800 Subject: chat is a members only feature, there is no "guest" access. --- mod/chat.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index bc981b76b..42a7808d9 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -39,20 +39,26 @@ function chat_init(&$a) { function chat_content(&$a) { - if(! perm_is_allowed($a->profile['profile_uid'],get_observer_hash(),'chat')) { + $observer = get_observer_hash(); + if(! $observer) { + notice( t('Permission denied.') . EOL); + return; + } + + if(! perm_is_allowed($a->profile['profile_uid'],$observer,'chat')) { notice( t('Permission denied.') . EOL); return; } if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { - chatroom_leave(get_observer_hash(),$room_id,$_SERVER['REMOTE_ADDR']); + chatroom_leave($observer,$room_id,$_SERVER['REMOTE_ADDR']); goaway(z_root() . '/channel/' . argv(1)); } if(argc() > 2 && intval(argv(2))) { $room_id = intval(argv(2)); - $x = chatroom_enter(get_observer_hash(),$room_id,'online',$_SERVER['REMOTE_ADDR']); + $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; $o = replace_macros(get_markup_template('chat.tpl'),array()); -- cgit v1.2.3 From 9fdee53c9a35d584de8cacd071c6608de88a18b6 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 20:14:18 -0800 Subject: start on the ajax bits --- mod/chat.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index 42a7808d9..b8af4c1a6 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -61,7 +61,10 @@ function chat_content(&$a) { $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; - $o = replace_macros(get_markup_template('chat.tpl'),array()); + $o = replace_macros(get_markup_template('chat.tpl'),array( + '$room_id' => $room_id, + '$submit' => t('Submit') + )); return $o; } -- cgit v1.2.3 From 7b609782623d91c2bdf81c04cd801aaae927e9fa Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 20:40:37 -0800 Subject: back-end for changing online status and keeping presence refreshed --- mod/chat.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index b8af4c1a6..fa3d05364 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -67,5 +67,8 @@ function chat_content(&$a) { )); return $o; } + require_once('include/widgets.php'); + + return widget_chatroom_list(array()); } \ No newline at end of file -- cgit v1.2.3 From 080928f214c9f83879f1578e05baa6032fa2b7b8 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 29 Jan 2014 21:29:48 -0800 Subject: chatroom management front-end stuff --- mod/chat.php | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index fa3d05364..54fa58092 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -36,6 +36,46 @@ function chat_init(&$a) { } +function chat_post(&$a) { + + if($_POST['room_name']) + $room = strip_tags(trim($_POST['room_name'])); + + if((! $room) || (! local_user())) + return; + + $channel = $a->get_channel(); + + + if($_POST['action'] === 'drop') { + chatroom_destroy($channel,array('cr_name' => $room)); + goaway(z_root() . '/chat/' . $channel['channel_address']); + } + + + $arr = array('name' => $room); + $arr['allow_gid'] = perms2str($_REQUEST['group_allow']); + $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']); + $arr['deny_gid'] = perms2str($_REQUEST['group_deny']); + $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']); + + chatroom_create($channel,$arr); + + $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1", + dbesc($room), + intval(local_user()) + ); + + if($x) + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); + + // that failed. Try again perhaps? + + goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new'); + + +} + function chat_content(&$a) { @@ -62,11 +102,44 @@ function chat_content(&$a) { if(! $x) return; $o = replace_macros(get_markup_template('chat.tpl'),array( + '$room_name' => '', // should we get this from the API? '$room_id' => $room_id, '$submit' => t('Submit') )); return $o; } + + + + + + if(local_user() && argc() > 2 && argv(2) === 'new') { + + + $channel = $a->get_channel(); + $channel_acl = array( + 'allow_cid' => $channel['channel_allow_cid'], + 'allow_gid' => $channel['channel_allow_gid'], + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'] + ); + + require_once('include/acl_selectors.php'); + + $o = replace_macros(get_markup_template('chatroom_new.tpl'),array( + '$header' => t('New Chatroom'), + '$name' => array('room_name',t('Chatroom Name'),'', ''), + '$acl' => populate_acl($channel_acl), + '$submit' => t('Submit') + )); + return $o; + } + + + + + + require_once('include/widgets.php'); return widget_chatroom_list(array()); -- cgit v1.2.3 From d14afc0ee442a2ba4013c193fa80917026bb6111 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 1 Feb 2014 00:54:20 -0800 Subject: provide the room name for the room you're in. --- mod/chat.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index 54fa58092..612878cb2 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -101,8 +101,15 @@ function chat_content(&$a) { $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; + $x = q("select * from chatroom where cr_id = %d and cr_uid = %d $sql_extra limit 1", + intval($room_id), + intval($a->profile['profile_uid']) + ); + if($x) { + $room_name = $x[0]['cr_name']; + } $o = replace_macros(get_markup_template('chat.tpl'),array( - '$room_name' => '', // should we get this from the API? + '$room_name' => $room_name, '$room_id' => $room_id, '$submit' => t('Submit') )); -- cgit v1.2.3 From e83419b53e27078867f8449f476d87b064b9d502 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 2 Feb 2014 03:43:52 -0800 Subject: add links to change chat status and leave room --- mod/chat.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index 612878cb2..e79973aef 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -91,7 +91,7 @@ function chat_content(&$a) { } if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) { - chatroom_leave($observer,$room_id,$_SERVER['REMOTE_ADDR']); + chatroom_leave($observer,argv(2),$_SERVER['REMOTE_ADDR']); goaway(z_root() . '/channel/' . argv(1)); } @@ -111,7 +111,13 @@ function chat_content(&$a) { $o = replace_macros(get_markup_template('chat.tpl'),array( '$room_name' => $room_name, '$room_id' => $room_id, - '$submit' => t('Submit') + '$baseurl' => z_root(), + '$nickname' => argv(1), + '$submit' => t('Submit'), + '$leave' => t('Leave Room'), + '$away' => t('I am away right now'), + '$online' => t('I am online') + )); return $o; } -- cgit v1.2.3 From 05a70a8760d705e80c548d96a9d083ab032dbd8b Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 5 Feb 2014 19:16:12 -0800 Subject: add chatroom links --- mod/chat.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index e79973aef..e3725830c 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -155,6 +155,15 @@ function chat_content(&$a) { require_once('include/widgets.php'); - return widget_chatroom_list(array()); + $o = replace_macros(get_markup_template('chatrooms.tpl'), array( + '$header' => sprintf( t('%1$s\'s Chatrooms'), $a->profile['name']), + '$baseurl' => z_root(), + '$nickname' => $channel['channel_address'], + '$rooms' => widget_chatroom_list(array()), + '$newroom' => t('New Chatroom'), + '$is_owner' => ((local_user() && local_user() == $a->profile['profile_uid']) ? 1 : 0) + )); + + return $o; } \ No newline at end of file -- cgit v1.2.3 From cda1224066f0bbf63dbd0b0e69a78c8e27c18afd Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 6 Feb 2014 23:10:14 -0800 Subject: missing element in new chatroom link --- mod/chat.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index e3725830c..872571f8c 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -79,6 +79,9 @@ function chat_post(&$a) { function chat_content(&$a) { + if(local_user()) + $channel = $a->get_channel(); + $observer = get_observer_hash(); if(! $observer) { notice( t('Permission denied.') . EOL); @@ -129,7 +132,7 @@ function chat_content(&$a) { if(local_user() && argc() > 2 && argv(2) === 'new') { - $channel = $a->get_channel(); + $channel_acl = array( 'allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], -- cgit v1.2.3 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/chat.php') 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 From b1021df485fb6129acda5bba616bac10aea75a45 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 24 Feb 2014 21:34:49 -0800 Subject: provide ability to bookmark chatrooms using rbmark --- mod/chat.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'mod/chat.php') diff --git a/mod/chat.php b/mod/chat.php index a960f4f37..0f2b94b9d 100644 --- a/mod/chat.php +++ b/mod/chat.php @@ -1,6 +1,7 @@ get_channel(); + $ob = $a->get_observer(); $observer = get_observer_hash(); if(! $observer) { notice( t('Permission denied.') . EOL); @@ -144,6 +146,8 @@ function chat_content(&$a) { if(argc() > 2 && intval(argv(2))) { $room_id = intval(argv(2)); + $bookmark_link = get_bookmark_link($ob); + $x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']); if(! $x) return; @@ -152,8 +156,16 @@ function chat_content(&$a) { intval($a->profile['profile_uid']) ); if($x) { + $private = ((($x[0]['allow_cid']) || ($x[0]['allow_gid']) || ($x[0]['deny_cid']) || ($x[0]['deny_gid'])) ? true : false); $room_name = $x[0]['cr_name']; + if($bookmark_link) + $bookmark_link .= '&url=' . z_root() . '/chat/' . argv(1) . '/' . argv(2) . '&title=' . urlencode($x[0]['cr_name']) . (($private) ? '&private=1' : '') . '&ischat=1'; + } + else { + notice( t('Room not found') . EOL); + return; } + $o = replace_macros(get_markup_template('chat.tpl'),array( '$room_name' => $room_name, '$room_id' => $room_id, @@ -162,7 +174,9 @@ function chat_content(&$a) { '$submit' => t('Submit'), '$leave' => t('Leave Room'), '$away' => t('I am away right now'), - '$online' => t('I am online') + '$online' => t('I am online'), + '$bookmark_link' => $bookmark_link, + '$bookmark' => t('Bookmark this room') )); return $o; -- cgit v1.2.3