From 37fccee503341ce1363e57cc81d465ef224e702d Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 1 Jun 2015 01:23:04 +0200 Subject: [PATCH] first work for consensus --- boot.php | 4 +++ include/conversation.php | 62 +++++++++++++++++++++++++++++++--------- mod/like.php | 18 ++++++++++++ object/Conversation.php | 4 +-- object/Item.php | 8 +++--- 5 files changed, 76 insertions(+), 20 deletions(-) diff --git a/boot.php b/boot.php index 5f633fd878..4dcfdc4952 100644 --- a/boot.php +++ b/boot.php @@ -270,6 +270,10 @@ define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' ); define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' ); define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' ); +define ( 'ACTIVITY_AGREE', NAMESPACE_DFRN . '/activity/agree' ); +define ( 'ACTIVITY_DISAGREE', NAMESPACE_DFRN . '/activity/disagree' ); +define ( 'ACTIVITY_ABSTAIN', NAMESPACE_DFRN . '/activity/abstain' ); + define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' ); define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' ); diff --git a/include/conversation.php b/include/conversation.php index 5a84ca42a6..a5d8ac551f 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -341,8 +341,15 @@ function count_descendants($item) { function visible_activity($item) { - if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)) - return false; + // likes (etc.) can apply to other things besides posts. Check if they are post children, + // in which case we handle them specially + + $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN); + foreach($hidden_activities as $act) { + if(activity_match($item['verb'],$act)) { + return false; + } + } if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { if(! (($item['self']) && ($item['uid'] == local_user()))) { @@ -484,8 +491,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $cmnt_tpl = get_markup_template('comment_item.tpl'); $hide_comments_tpl = get_markup_template('hide_comments.tpl'); - $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(); @@ -734,8 +740,11 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // Can we put this after the visibility check? - like_puller($a,$item,$alike,'like'); - like_puller($a,$item,$dlike,'dislike'); + like_puller($a, $item, $conv_responses, 'like'); + 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'); // Only add what is visible if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { @@ -755,7 +764,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { } } - $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); @@ -904,7 +913,31 @@ function like_puller($a,$item,&$arr,$mode) { $url = ''; $sparkle = ''; - $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'])) { $url = $item['author-link']; @@ -918,13 +951,14 @@ function like_puller($a,$item,&$arr,$mode) { if(! $item['thr-parent']) $item['thr-parent'] = $item['parent-uri']; - if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l'])))) - $arr[$item['thr-parent'] . '-l'] = array(); - if(! isset($arr[$item['thr-parent']])) - $arr[$item['thr-parent']] = 1; + if(! ((isset($arr[$mode][$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l'])))) + $arr[$mode][$item['thr-parent'] . '-l'] = array(); + if(! isset($arr[$mode][$item['thr-parent']])) + $arr[$mode][$item['thr-parent']] = 1; else - $arr[$item['thr-parent']] ++; - $arr[$item['thr-parent'] . '-l'][] = '' . $item['author-name'] . ''; + $arr[$mode][$item['thr-parent']] ++; + + $arr[$mode][$item['thr-parent'] . '-l'][] = '' . $item['author-name'] . ''; } return; }} diff --git a/mod/like.php b/mod/like.php index bbb0728965..6f0c5a5095 100755 --- a/mod/like.php +++ b/mod/like.php @@ -26,6 +26,18 @@ function like_content(&$a) { case 'undislike': $activity = ACTIVITY_DISLIKE; break; + case 'agree': + case 'unagree': + $activity = ACTIVITY_AGREE; + break; + case 'disagree': + case 'undisagree': + $activity = ACTIVITY_DISAGREE; + break; + case 'abstain': + case 'unabstain': + $activity = ACTIVITY_ABSTAIN; + break; default: return; break; @@ -166,6 +178,12 @@ EOT; $bodyverb = t('%1$s likes %2$s\'s %3$s'); if($verb === 'dislike') $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); + if($verb === 'agree') + $bodyverb = t('%1$s agrees with %2$s\'s %3$s'); + if($verb === 'disagree') + $bodyverb = t('%1$s doesn\'t agree with %2$s\'s %3$s'); + if($verb === 'abstain') + $bodyverb = t('%1$s abstains from a decision on %2$s\'s %3$s'); if(! isset($bodyverb)) return; diff --git a/object/Conversation.php b/object/Conversation.php index fd1e282cab..94eed94d5f 100644 --- a/object/Conversation.php +++ b/object/Conversation.php @@ -126,7 +126,7 @@ class Conversation extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($alike, $dlike) { + public function get_template_data($conv_responses) { global $a; $result = array(); @@ -136,7 +136,7 @@ class Conversation extends BaseObject { if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) continue; - $item_data = $item->get_template_data($alike, $dlike); + $item_data = $item->get_template_data($conv_responses); if(!$item_data) { logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); diff --git a/object/Item.php b/object/Item.php index 8d364e6023..7ff4c438c7 100644 --- a/object/Item.php +++ b/object/Item.php @@ -81,7 +81,7 @@ class Item extends BaseObject { * _ The data requested on success * _ false on failure */ - public function get_template_data($alike, $dlike, $thread_level=1) { + public function get_template_data($conv_responses, $thread_level=1) { require_once("mod/proxy.php"); $result = array(); @@ -175,8 +175,8 @@ class Item extends BaseObject { } }*/ - $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); - $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); + $like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$item['uri']) : ''); + $dislike = ((x($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$item['uri'] . '-l'],'dislike',$item['uri']) : ''); /* * We should avoid doing this all the time, but it depends on the conversation mode @@ -381,7 +381,7 @@ class Item extends BaseObject { $nb_children = count($children); if($nb_children > 0) { foreach($children as $child) { - $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); + $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1); } // Collapse if(($nb_children > 2) || ($thread_level > 1)) {