From 0259051a87233f32efaaa7f0b4dafc71c2f3c13d Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 11 Jan 2015 14:41:33 -0800 Subject: basic backend work for creating consensus items --- include/conversation.php | 65 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) (limited to 'include/conversation.php') diff --git a/include/conversation.php b/include/conversation.php index 986892fff..0d59ff92e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -399,10 +399,15 @@ function count_descendants($item) { function visible_activity($item) { - // likes can apply to other things besides posts. Check if they are post children, in which case we handle them specially + // likes (etc.) can apply to other things besides posts. Check if they are post children, + // in which case we handle them specially - if((activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)) && ($item['mid'] != $item['parent_mid'])) - return false; + $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN); + foreach($hidden_activities as $act) { + if((activity_match($item['verb'],$act)) && ($item['mid'] != $item['parent_mid'])) { + return false; + } + } return true; } @@ -547,8 +552,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $items = $cb['items']; - $alike = array(); - $dlike = array(); + $conv_responses = array(array('like'),array('dislike'),array('agree'),array('disagree'),array('abstain')); // array with html for each thread (parent+comments) $threads = array(); @@ -779,10 +783,14 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ } } - like_puller($a, $item, $alike, 'like'); + like_puller($a, $item, $conv_responses, 'like'); if(feature_enabled($profile_owner, 'dislike')) - like_puller($a, $item, $dlike, 'dislike'); + like_puller($a, $item, $conv_responses, 'dislike'); + + like_puller($a, $item, $conv_responses, 'agree'); + like_puller($a, $item, $conv_responses, 'disagree'); + like_puller($a, $item, $conv_responses, 'abstain'); if(! visible_activity($item)) { continue; @@ -801,7 +809,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ } } - $threads = $conv->get_template_data($alike, $dlike); + $threads = $conv->get_template_data($conv_responses); if(!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); @@ -972,7 +980,32 @@ function item_photo_menu($item){ function like_puller($a, $item, &$arr, $mode) { $url = ''; - $verb = (($mode === 'like') ? ACTIVITY_LIKE : ACTIVITY_DISLIKE); + + switch($mode) { + case 'like': + case 'unlike': + $verb = ACTIVITY_LIKE; + break; + case 'dislike': + case 'undislike': + $verb = ACTIVITY_DISLIKE; + break; + case 'agree': + case 'unagree': + $verb = ACTIVITY_AGREE; + break; + case 'disagree': + case 'undisagree': + $verb = ACTIVITY_DISAGREE; + break; + case 'abstain': + case 'unabstain': + $verb = ACTIVITY_ABSTAIN; + break; + default: + return; + break; + } if((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { @@ -982,20 +1015,20 @@ function like_puller($a, $item, &$arr, $mode) { if(! $item['thr_parent']) $item['thr_parent'] = $item['parent_mid']; - if(! ((isset($arr[$item['thr_parent'] . '-l'])) && (is_array($arr[$item['thr_parent'] . '-l'])))) - $arr[$item['thr_parent'] . '-l'] = array(); + if(! ((isset($arr[$mode][$item['thr_parent'] . '-l'])) && (is_array($arr[$mode][$item['thr_parent'] . '-l'])))) + $arr[$mode][$item['thr_parent'] . '-l'] = array(); - if(! isset($arr[$item['thr_parent']])) - $arr[$item['thr_parent']] = 1; + if(! isset($arr[$mode][$item['thr_parent']])) + $arr[$mode][$item['thr_parent']] = 1; else - $arr[$item['thr_parent']] ++; + $arr[$mode][$item['thr_parent']] ++; $name = (($item['author']['xchan_name']) ? $item['author']['xchan_name'] : t('Unknown')); if($url) - $arr[$item['thr_parent'] . '-l'][] = '' . $name . ''; + $arr[$mode][$item['thr_parent'] . '-l'][] = '' . $name . ''; else - $arr[$item['thr_parent'] . '-l'][] = '' . $name . ''; + $arr[$mode][$item['thr_parent'] . '-l'][] = '' . $name . ''; } return; } -- cgit v1.2.3