diff options
author | Mario <mario@mariovavti.com> | 2020-02-10 12:25:11 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-02-10 12:25:11 +0100 |
commit | 50dbe1e62d8da44a710f1eb0f7e9d9eaf88c4084 (patch) | |
tree | a5a7646e1401b2c943d426f1198c3834f62baee6 | |
parent | 33be244d8a4ab62d52f7715b5f95ed293be79504 (diff) | |
parent | bbcb237f5b996e94af37611152105b2e965ea493 (diff) | |
download | volse-hubzilla-50dbe1e62d8da44a710f1eb0f7e9d9eaf88c4084.tar.gz volse-hubzilla-50dbe1e62d8da44a710f1eb0f7e9d9eaf88c4084.tar.bz2 volse-hubzilla-50dbe1e62d8da44a710f1eb0f7e9d9eaf88c4084.zip |
Merge branch 'dev' into 'dev'
poll updates
See merge request hubzilla/core!1828
-rw-r--r-- | Zotlabs/Lib/Activity.php | 44 | ||||
-rw-r--r-- | Zotlabs/Lib/Libzot.php | 12 | ||||
-rw-r--r-- | Zotlabs/Module/Item.php | 27 | ||||
-rw-r--r-- | Zotlabs/Module/Vote.php | 18 | ||||
-rw-r--r-- | include/conversation.php | 6 | ||||
-rw-r--r-- | include/text.php | 13 |
6 files changed, 84 insertions, 36 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index edc65d8e9..06aa3b931 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -325,6 +325,22 @@ class Activity { $ret['type'] = $objtype; + if ($objtype === 'Question') { + if ($i['obj']) { + if (is_array($i['obj'])) { + $ret = $i['obj']; + } + else { + $ret = json_decode($i['obj'],true); + } + + if(array_path_exists('actor/id',$ret)) { + $ret['actor'] = $ret['actor']['id']; + } + } + } + + $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid'])); if($i['title']) @@ -813,10 +829,6 @@ class Activity { static function activity_mapper($verb) { - if ($verb === 'Answer') { - return 'Note'; - } - if(strpos($verb,'/') === false) { return $verb; } @@ -916,7 +928,6 @@ class Activity { 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', 'Invite' => 'Invite', - ]; call_hooks('activity_obj_decode_mapper',$objs); @@ -1720,14 +1731,6 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } - if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name']) { - $s['mid'] = $act->id; - $s['parent_mid'] = $act->obj['id']; - $s['replyto'] = $act->replyto; - $s['verb'] = 'Answer'; - $content['content'] = EMPTY_STR; - } - if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { $response_activity = true; @@ -1794,11 +1797,6 @@ class Activity { $s['verb'] = self::activity_decode_mapper($act->type); - if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name'] && ! $content['content']) { - $s['verb'] = 'Answer'; - $s['title'] = purify_html($act->data['name']); - } - // Mastodon does not provide update timestamps when updating poll tallies which means race conditions may occur here. if ($act->type === 'Update' && $act->obj['type'] === 'Question' && $s['edited'] === $s['created']) { $s['edited'] = datetime_convert(); @@ -2190,7 +2188,7 @@ class Activity { set_iconfig($item,'activitypub','recips',$act->raw_recips); if(! $is_parent) { - $p = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", + $p = q("select parent_mid, id, obj_type from item where mid = '%s' and uid = %d limit 1", dbesc($item['parent_mid']), intval($item['uid']) ); @@ -2220,6 +2218,14 @@ class Activity { // $s['thr_parent'] = $s['mid']; } } + + if ($p[0]['obj_type'] === 'Question') { + if ($item['obj_type'] === ACTIVITY_OBJ_NOTE && $item['title'] && (! $item['content'])) { + $item['obj_type'] = 'Answer'; + } + } + + if($p[0]['parent_mid'] !== $item['parent_mid']) { $item['thr_parent'] = $item['parent_mid']; } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index bb70dfbf2..2776a681e 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1613,7 +1613,7 @@ class Libzot { // As a side effect we will also do a preliminary check that we have the top-level-post, otherwise // processing it is pointless. - $r = q("select route, id, owner_xchan, item_private from item where mid = '%s' and uid = %d limit 1", + $r = q("select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1", dbesc($arr['parent_mid']), intval($channel['channel_id']) ); @@ -1639,6 +1639,16 @@ class Libzot { continue; } + if ($r[0]['obj_type'] === 'Question') { + // route checking doesn't work correctly here because we've changed the privacy + $r[0]['route'] = EMPTY_STR; + // If this is a poll response, convert the obj_type to our (internal-only) "Answer" type + if ($arr['obj_type'] === ACTIVITY_OBJ_NOTE && $arr['title'] && (! $arr['content'])) { + $arr['obj_type'] = 'Answer'; + } + } + + if($relay || $friendofriend || (intval($r[0]['item_private']) === 0 && intval($arr['item_private']) === 0)) { // reset the route in case it travelled a great distance upstream // use our parent's route so when we go back downstream we'll match diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 21d59fbc1..e55192c7f 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -719,14 +719,6 @@ class Item extends Controller { // and will require alternatives for alternative content-types (text/html, text/markdown, text/plain, etc.) // we may need virtual or template classes to implement the possible alternatives - $obj = $this->extract_poll_data($body); - if ($obj) { - $datarray['obj'] = $obj; - $obj_type = 'Question'; - } - - - if(strpos($body,'[/summary]') !== false) { $match = ''; $cnt = preg_match("/\[summary\](.*?)\[\/summary\]/ism",$body,$match); @@ -928,6 +920,13 @@ class Item extends Controller { $mid = z_root() . '/item/' . $uuid; } + $obj = $this->extract_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]); + if ($obj) { + $obj['url'] = $mid; + $obj['attributedTo'] = channel_url($channel); + $datarray['obj'] = $obj; + $obj_type = 'Question'; + } if(! $parent_mid) { $parent_mid = $mid; @@ -1394,7 +1393,7 @@ class Item extends Controller { return $ret; } - function extract_poll_data(&$body) { + function extract_poll_data(&$body,$item) { $multiple = false; @@ -1438,7 +1437,15 @@ class Item extends Controller { if (preg_match('/\[ends\](.*?)\[\/ends\]/',$body,$matches)) { $obj['endTime'] = datetime_convert(date_default_timezone_get(),'UTC', $matches[1],ATOM_TIME); - $body = str_replace('[ends]' . $match[1] . '[/ends]', EMPTY_STR, $body); + $body = str_replace('[ends]' . $matches[1] . '[/ends]', EMPTY_STR, $body); + } + + + if ($item['item_private']) { + $obj['to'] = Activity::map_acl($item); + } + else { + $obj['to'] = [ ACTIVITY_PUBLIC_INBOX ]; } return $obj; diff --git a/Zotlabs/Module/Vote.php b/Zotlabs/Module/Vote.php index 52d6a4bea..2c31d84dc 100644 --- a/Zotlabs/Module/Vote.php +++ b/Zotlabs/Module/Vote.php @@ -88,15 +88,25 @@ class Vote extends Controller { $item['parent_mid'] = $fetch[0]['mid']; $item['uuid'] = new_uuid(); $item['mid'] = z_root() . '/item/' . $item['uuid']; - $item['verb'] = 'Answer'; + $item['verb'] = 'Create'; $item['title'] = $res; $item['author_xchan'] = $channel['channel_hash']; $item['owner_xchan'] = $fetch[0]['author_xchan']; - $item['obj'] = $obj; - $item['obj_type'] = 'Question'; + $item['obj_type'] = 'Note'; + $item['author'] = channelx_by_n($channel['channel_id']); + + $item['obj'] = Activity::encode_item($item,true); + + // now reset the placeholders + + $item['obj_type'] = 'Answer'; + unset($item['author']); + + + $x = item_store($item); + - $x = item_store($item); retain_item($fetch[0]['id']); diff --git a/include/conversation.php b/include/conversation.php index 45b2b4d80..327d89e53 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -408,11 +408,15 @@ function count_descendants($item) { * @return boolean */ function visible_activity($item) { - $hidden_activities = [ ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_POLLRESPONSE, 'Answer' ]; + $hidden_activities = [ ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_POLLRESPONSE ]; if(intval($item['item_notshown'])) return false; + if ($item['obj_type'] === 'Answer') { + return false; + } + foreach($hidden_activities as $act) { if((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) { return false; diff --git a/include/text.php b/include/text.php index caecae33e..992b455c8 100644 --- a/include/text.php +++ b/include/text.php @@ -1880,6 +1880,17 @@ function format_poll($item,$s,$opts) { } } } + if ($item['comments_closed'] > NULL_DATE) { + $t = datetime_convert('UTC',date_default_timezone_get(), $item['comments_closed'], 'Y-m-d h:i'); + $closed = ((datetime_convert() > $item['comments_closed']) ? true : false); + if ($closed) { + $message = t('Poll has ended.'); + } + else { + $message = sprintf(t('Poll ends: %s'),$t); + } + $output .= EOL . '<div>' . $message . '</div>'; + } if ($activated and $commentable) { $output .= EOL . '<input type="button" class="btn btn-std btn-success" name="vote" value="vote" onclick="submitPoll(' . $item['id'] . '); return false;">'. '</form>'; } @@ -3721,7 +3732,7 @@ function array_path_exists($str,$arr) { if($search) { foreach($search as $s) { - if(array_key_exists($s,$ptr)) { + if($ptr && array_key_exists($s,$ptr)) { $ptr = $ptr[$s]; } else { |