first work for consensus

This commit is contained in:
rabuzarus 2015-06-01 01:23:04 +02:00 committed by rabuzarus
parent 2e8caf7f27
commit 37fccee503
5 changed files with 76 additions and 20 deletions

View file

@ -270,6 +270,10 @@ define ( 'NAMESPACE_ATOM1', 'http://www.w3.org/2005/Atom' );
define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' ); define ( 'ACTIVITY_LIKE', NAMESPACE_ACTIVITY_SCHEMA . 'like' );
define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' ); 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_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' ); define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );

View file

@ -341,8 +341,15 @@ function count_descendants($item) {
function visible_activity($item) { function visible_activity($item) {
if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)) // 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; return false;
}
}
if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
if(! (($item['self']) && ($item['uid'] == local_user()))) { 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'); $cmnt_tpl = get_markup_template('comment_item.tpl');
$hide_comments_tpl = get_markup_template('hide_comments.tpl'); $hide_comments_tpl = get_markup_template('hide_comments.tpl');
$alike = array(); $conv_responses = array(array('like'),array('dislike'),array('agree'),array('disagree'),array('abstain'));
$dlike = array();
// array with html for each thread (parent+comments) // array with html for each thread (parent+comments)
$threads = array(); $threads = array();
@ -734,8 +740,11 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
// Can we put this after the visibility check? // Can we put this after the visibility check?
like_puller($a,$item,$alike,'like'); like_puller($a, $item, $conv_responses, 'like');
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');
// Only add what is visible // Only add what is visible
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { 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) { if(!$threads) {
logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
@ -904,7 +913,31 @@ function like_puller($a,$item,&$arr,$mode) {
$url = ''; $url = '';
$sparkle = ''; $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'])) { if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
$url = $item['author-link']; $url = $item['author-link'];
@ -918,13 +951,14 @@ function like_puller($a,$item,&$arr,$mode) {
if(! $item['thr-parent']) if(! $item['thr-parent'])
$item['thr-parent'] = $item['parent-uri']; $item['thr-parent'] = $item['parent-uri'];
if(! ((isset($arr[$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l'])))) if(! ((isset($arr[$mode][$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l']))))
$arr[$item['thr-parent'] . '-l'] = array(); $arr[$mode][$item['thr-parent'] . '-l'] = array();
if(! isset($arr[$item['thr-parent']])) if(! isset($arr[$mode][$item['thr-parent']]))
$arr[$item['thr-parent']] = 1; $arr[$mode][$item['thr-parent']] = 1;
else else
$arr[$item['thr-parent']] ++; $arr[$mode][$item['thr-parent']] ++;
$arr[$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
$arr[$mode][$item['thr-parent'] . '-l'][] = '<a href="'. $url . '"'. $sparkle .'>' . $item['author-name'] . '</a>';
} }
return; return;
}} }}

View file

@ -26,6 +26,18 @@ function like_content(&$a) {
case 'undislike': case 'undislike':
$activity = ACTIVITY_DISLIKE; $activity = ACTIVITY_DISLIKE;
break; 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: default:
return; return;
break; break;
@ -166,6 +178,12 @@ EOT;
$bodyverb = t('%1$s likes %2$s\'s %3$s'); $bodyverb = t('%1$s likes %2$s\'s %3$s');
if($verb === 'dislike') if($verb === 'dislike')
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); $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)) if(! isset($bodyverb))
return; return;

View file

@ -126,7 +126,7 @@ class Conversation extends BaseObject {
* _ The data requested on success * _ The data requested on success
* _ false on failure * _ false on failure
*/ */
public function get_template_data($alike, $dlike) { public function get_template_data($conv_responses) {
global $a; global $a;
$result = array(); $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')) if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
continue; continue;
$item_data = $item->get_template_data($alike, $dlike); $item_data = $item->get_template_data($conv_responses);
if(!$item_data) { if(!$item_data) {
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG); logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);

View file

@ -81,7 +81,7 @@ class Item extends BaseObject {
* _ The data requested on success * _ The data requested on success
* _ false on failure * _ 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"); require_once("mod/proxy.php");
$result = array(); $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']) : ''); $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($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$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 * 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); $nb_children = count($children);
if($nb_children > 0) { if($nb_children > 0) {
foreach($children as $child) { 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 // Collapse
if(($nb_children > 2) || ($thread_level > 1)) { if(($nb_children > 2) || ($thread_level > 1)) {