From 0e91810ed6764fbbee54e918711bfb45a1d9fd72 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 26 Nov 2017 18:29:24 -0800 Subject: pubstream comments and a few other bugfixes that were discovered along the way --- include/conversation.php | 4 +-- include/feedutils.php | 31 +++++++++++++++++---- include/items.php | 72 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 83 insertions(+), 24 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 70a38ee8e..841a00d85 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -482,10 +482,10 @@ function conversation($items, $mode, $update, $page_mode = 'traditional', $prepa $previewing = (($preview) ? ' preview ' : ''); $preview_lbl = t('This is an unsaved preview'); - if ($mode === 'network') { + if (in_array($mode, [ 'network', 'pubstream'])) { $profile_owner = local_channel(); - $page_writeable = true; + $page_writeable = ((local_channel()) ? true : false); if (!$update) { // The special div is needed for liveUpdate to kick in for this page. diff --git a/include/feedutils.php b/include/feedutils.php index 50f76b550..8f2c5d988 100644 --- a/include/feedutils.php +++ b/include/feedutils.php @@ -65,15 +65,34 @@ function get_feed_for($channel, $observer_hash, $params) { if(! $channel) http_status_exit(401); + + // logger('params: ' . print_r($params,true)); + + + $interactive = ((is_array($params) && array_key_exists('interactive',$params)) ? intval($params['interactive']) : 0); + + if($params['pages']) { - if(! perm_is_allowed($channel['channel_id'],$observer_hash,'view_pages')) - http_status_exit(403); - } else { - if(! perm_is_allowed($channel['channel_id'],$observer_hash,'view_stream')) - http_status_exit(403); + if(! perm_is_allowed($channel['channel_id'],$observer_hash,'view_pages')) { + if($interactive) { + return ''; + } + else { + http_status_exit(403); + } + } + } + else { + if(! perm_is_allowed($channel['channel_id'],$observer_hash,'view_stream')) { + if($interactive) { + return ''; + } + else { + http_status_exit(403); + } + } } - // logger('params: ' . print_r($params,true)); $feed_template = get_markup_template('atom_feed.tpl'); diff --git a/include/items.php b/include/items.php index 042deed1b..baf11ac69 100755 --- a/include/items.php +++ b/include/items.php @@ -1749,22 +1749,6 @@ function item_store($arr, $allow_exec = false, $deliver = true) { intval($arr['uid']) ); - // perhaps the system channel owns the post and it's a pubstream item - - if(! $r) { - $s = q("select channel_id from channel where channel_system = 1 limit 1"); - if($s) { - $r = q("SELECT * FROM item WHERE mid = '%s' AND uid = %d ORDER BY id ASC LIMIT 1", - dbesc($arr['parent_mid']), - intval($s[0]['channel_id']) - ); - } - if($r) { - $arr['uid'] = $r[0]['uid']; - $arr['aid'] = 0; - } - } - if($r) { // in case item_store was killed before the parent's parent attribute got set, @@ -4725,3 +4709,59 @@ function item_create_edit_activity($post) { \Zotlabs\Daemon\Master::Summon(array('Notifier', 'edit_activity', $post_id)); } + +/** + * @brief copies an entire conversation from the pubstream to this channel's stream + * which will allow you to interact with it. + */ + + + +function copy_of_pubitem($channel,$mid) { + + $result = null; + $syschan = get_sys_channel(); + + // logger('copy_of_pubitem: ' . $channel['channel_id'] . ' mid: ' . $mid); + + $r = q("select * from item where mid = '%s' and uid = %d limit 1", + dbesc($mid), + intval($channel['channel_id']) + ); + + if($r) { + logger('exists'); + $item = fetch_post_tags($r,true); + return $item[0]; + } + + + $r = q("select * from item where parent_mid = (select parent_mid from item where mid = '%s' and uid = %d ) order by id ", + dbesc($mid), + intval($syschan['channel_id']) + ); + + if($r) { + $items = fetch_post_tags($r,true); + foreach($items as $rv) { + $d = q("select id from item where mid = '%s' and uid = %d limit 1", + dbesc($rv['mid']), + intval($channel['channel_id']) + ); + if($d) { + continue; + } + + unset($rv['id']); + unset($rv['parent']); + $rv['aid'] = $channel['channel_account_id']; + $rv['uid'] = $channel['channel_id']; + $x = item_store($rv); + if($x['item_id'] && $x['item']['mid'] === $mid) { + $result = $x['item']; + } + + } + } + return $result; +} -- cgit v1.2.3