make event confirmation work

This commit is contained in:
rabuzarus 2015-06-01 13:57:45 +02:00 committed by rabuzarus
parent 37fccee503
commit 0077494396
4 changed files with 152 additions and 7 deletions

View file

@ -270,9 +270,12 @@ 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_AGREE', NAMESPACE_ZOT . '/activity/agree' );
define ( 'ACTIVITY_DISAGREE', NAMESPACE_DFRN . '/activity/disagree' ); define ( 'ACTIVITY_DISAGREE', NAMESPACE_ZOT . '/activity/disagree' );
define ( 'ACTIVITY_ABSTAIN', NAMESPACE_DFRN . '/activity/abstain' ); define ( 'ACTIVITY_ABSTAIN', NAMESPACE_ZOT . '/activity/abstain' );
define ( 'ACTIVITY_ATTEND', NAMESPACE_ZOT . '/activity/attendyes' );
define ( 'ACTIVITY_ATTENDNO', NAMESPACE_ZOT . '/activity/attendno' );
define ( 'ACTIVITY_ATTENDMAYBE', NAMESPACE_ZOT . '/activity/attendmaybe' );
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' ); define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );

View file

@ -344,7 +344,7 @@ function visible_activity($item) {
// likes (etc.) can apply to other things besides posts. Check if they are post children, // likes (etc.) can apply to other things besides posts. Check if they are post children,
// in which case we handle them specially // in which case we handle them specially
$hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN); $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
foreach($hidden_activities as $act) { foreach($hidden_activities as $act) {
if(activity_match($item['verb'],$act)) { if(activity_match($item['verb'],$act)) {
return false; return false;
@ -491,7 +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');
$conv_responses = array(array('like'),array('dislike'),array('agree'),array('disagree'),array('abstain')); $conv_responses = array(array('like'),array('dislike'),array('agree'),array('disagree'),array('abstain'),array('attendyes'),array('attendno'),array('attendmaybe'));
// array with html for each thread (parent+comments) // array with html for each thread (parent+comments)
$threads = array(); $threads = array();
@ -742,6 +742,14 @@ 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, $conv_responses, 'like'); like_puller($a, $item, $conv_responses, 'like');
like_puller($a, $item, $conv_responses, 'dislike'); like_puller($a, $item, $conv_responses, 'dislike');
// if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
like_puller($a, $item, $conv_responses, 'attendyes');
like_puller($a, $item, $conv_responses, 'attendno');
like_puller($a, $item, $conv_responses, 'attendmaybe');
logger('responses: ' . print_r($conv_responses,true));
like_puller($a, $item, $conv_responses, 'agree'); like_puller($a, $item, $conv_responses, 'agree');
like_puller($a, $item, $conv_responses, 'disagree'); like_puller($a, $item, $conv_responses, 'disagree');
like_puller($a, $item, $conv_responses, 'abstain'); like_puller($a, $item, $conv_responses, 'abstain');
@ -934,12 +942,29 @@ function like_puller($a,$item,&$arr,$mode) {
case 'unabstain': case 'unabstain':
$verb = ACTIVITY_ABSTAIN; $verb = ACTIVITY_ABSTAIN;
break; break;
case 'attendyes':
case 'unattendyes':
$verb = ACTIVITY_ATTEND;
break;
case 'attendno':
case 'unattendno':
$verb = ACTIVITY_ATTENDNO;
break;
case 'attendmaybe':
case 'unattendmaybe':
$verb = ACTIVITY_ATTENDMAYBE;
break;
default: default:
return; return;
break; break;
} }
logger('verb: ' . $verb);
if($verb === ACTIVITY_ATTENDNO)
logger('item: ' . $item['verb']);
if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) { if((activity_match($item['verb'],$verb)) && ($item['id'] != $item['parent'])) {
logger('match:' . $verb);
$url = $item['author-link']; $url = $item['author-link'];
if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) { if((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'],$item['url']))) {
$url = $a->get_baseurl(true) . '/redir/' . $item['contact-id']; $url = $a->get_baseurl(true) . '/redir/' . $item['contact-id'];
@ -951,7 +976,7 @@ 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[$mode][$item['thr-parent'] . '-l'])) && (is_array($arr[$item['thr-parent'] . '-l'])))) if(! ((isset($arr[$mode][$item['thr-parent'] . '-l'])) && (is_array($arr[$mode][$item['thr-parent'] . '-l']))))
$arr[$mode][$item['thr-parent'] . '-l'] = array(); $arr[$mode][$item['thr-parent'] . '-l'] = array();
if(! isset($arr[$mode][$item['thr-parent']])) if(! isset($arr[$mode][$item['thr-parent']]))
$arr[$mode][$item['thr-parent']] = 1; $arr[$mode][$item['thr-parent']] = 1;
@ -1270,3 +1295,54 @@ function render_location_dummy($item) {
if ($item['coord'] != "") if ($item['coord'] != "")
return $item['coord']; return $item['coord'];
} }
function get_responses($conv_responses,$response_verbs,$ob,$item) {
$ret = array();
foreach($response_verbs as $v) {
$ret[$v] = array();
$ret[$v]['count'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri']] : '');
$ret[$v]['list'] = ((x($conv_responses[$v],$item['uri'])) ? $conv_responses[$v][$item['uri'] . '-l'] : '');
if(count($ret[$v]['list']) > MAX_LIKERS) {
$ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);
array_push($ret[$v]['list_part'], '<a href="#" data-toggle="modal" data-target="#' . $v . 'Modal-'
. $ob->get_id() . '"><b>' . t('View all') . '</b></a>');
}
else {
$ret[$v]['list_part'] = '';
}
$ret[$v]['button'] = get_response_button_text($v,$ret[$v]['count']);
}
$ret['count'] = count($ret);
return $ret;
}
function get_response_button_text($v,$count) {
switch($v) {
case 'like':
return tt('Like','Likes',$count,'noun');
break;
case 'dislike':
return tt('Dislike','Dislikes',$count,'noun');
break;
case 'attendyes':
return tt('Attending','Attending',$count,'noun');
break;
case 'attendno':
return tt('Not Attending','Not Attending',$count,'noun');
break;
case 'attendmaybe':
return tt('Undecided','Undecided',$count,'noun');
break;
case 'agree':
return tt('Agree','Agrees',$count,'noun');
break;
case 'agree':
return tt('Disagree','Disagrees',$count,'noun');
break;
case 'abstain':
return tt('Abstain','Abstains',$count,'noun');
break;
default:
return '';
break;
}
}

View file

@ -38,6 +38,18 @@ function like_content(&$a) {
case 'unabstain': case 'unabstain':
$activity = ACTIVITY_ABSTAIN; $activity = ACTIVITY_ABSTAIN;
break; break;
case 'attendyes':
case 'unattendyes':
$activity = ACTIVITY_ATTEND;
break;
case 'attendno':
case 'unattendno':
$activity = ACTIVITY_ATTENDNO;
break;
case 'attendmaybe':
case 'unattendmaybe':
$activity = ACTIVITY_ATTENDMAYBE;
break;
default: default:
return; return;
break; break;
@ -159,6 +171,8 @@ function like_content(&$a) {
$uri = item_new_uri($a->get_hostname(),$owner_uid); $uri = item_new_uri($a->get_hostname(),$owner_uid);
$post_type = (($item['resource-id']) ? t('photo') : t('status')); $post_type = (($item['resource-id']) ? t('photo') : t('status'));
if($item['resource-type'] === 'event')
$post_type = t('event');
$objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
$link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ; $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
$body = $item['body']; $body = $item['body'];
@ -184,6 +198,12 @@ EOT;
$bodyverb = t('%1$s doesn\'t agree with %2$s\'s %3$s'); $bodyverb = t('%1$s doesn\'t agree with %2$s\'s %3$s');
if($verb === 'abstain') if($verb === 'abstain')
$bodyverb = t('%1$s abstains from a decision on %2$s\'s %3$s'); $bodyverb = t('%1$s abstains from a decision on %2$s\'s %3$s');
if($verb === 'attendyes')
$bodyverb = t('%1$s is attending %2$s\'s %3$s');
if($verb === 'attendno')
$bodyverb = t('%1$s is not attending %2$s\'s %3$s');
if($verb === 'attendmaybe')
$bodyverb = t('%1$s may attend %2$s\'s %3$s');
if(! isset($bodyverb)) if(! isset($bodyverb))
return; return;

View file

@ -175,8 +175,51 @@ class Item extends BaseObject {
} }
}*/ }*/
// process action responses - e.g. like/dislike/attend/agree/whatever
$response_verbs = array('like');
$response_verbs[] = 'dislike';
if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
$response_verbs[] = 'attendyes';
$response_verbs[] = 'attendno';
$response_verbs[] = 'attendmaybe';
$isevent = true;
$attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
}
$consensus = (($item['item_flags'] & ITEM_CONSENSUS)? true : false);
if($consensus) {
$response_verbs[] = 'agree';
$response_verbs[] = 'disagree';
$response_verbs[] = 'abstain';
}
$responses = get_responses($conv_responses,$response_verbs,$this,$item);
// like_button_label from red -> needs to be removed
//$like_button_label = tt('Like','Likes',$like_count,'noun');
// another part from red - it is here for compatility - maybe removed later
$like_count = ((x($conv_responses['like'],$item['uri'])) ? $conv_responses['like'][$item['uri']] : '');
$like_list = ((x($conv_responses['like'],$item['uri'])) ? $conv_responses['like'][$item['uri'] . '-l'] : '');
if (count($like_list) > MAX_LIKERS) {
$like_list_part = array_slice($like_list, 0, MAX_LIKERS);
array_push($like_list_part, '<a href="#" data-toggle="modal" data-target="#likeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
} else {
$like_list_part = '';
}
$like_button_label = tt('Like','Likes',$like_count,'noun');
$dislike_count = ((x($conv_responses['dislike'],$item['uri'])) ? $conv_responses['dislike'][$item['uri']] : '');
$dislike_list = ((x($conv_responses['dislike'],$item['uri'])) ? $conv_responses['dislike'][$item['uri'] . '-l'] : '');
$dislike_button_label = tt('Dislike','Dislikes',$dislike_count,'noun');
if (count($dislike_list) > MAX_LIKERS) {
$dislike_list_part = array_slice($dislike_list, 0, MAX_LIKERS);
array_push($dislike_list_part, '<a href="#" data-toggle="modal" data-target="#dislikeModal-' . $this->get_id() . '"><b>' . t('View all') . '</b></a>');
} else {
$dislike_list_part = '';
}
$like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$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($conv_responses['dislike'],$item['uri'])) ? format_like($conv_responses['dislike'][$item['uri']],$conv_responses['dislike'][$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']) : '');
$like = ((x($conv_responses['like'],$item['uri'])) ? format_like($conv_responses['like'][$item['uri']],$conv_responses['like'][$item['uri'] . '-l'],'like',$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
@ -324,7 +367,9 @@ class Item extends BaseObject {
'body' => $body_e, 'body' => $body_e,
'text' => $text_e, 'text' => $text_e,
'id' => $this->get_id(), 'id' => $this->get_id(),
'guid' => urlencode($item['guid']), 'guid' => $item['guid'],
'isevent' => $isevent,
'attend' => $attend,
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $this->get_owner_name(), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
'to' => t('to'), 'to' => t('to'),
@ -360,6 +405,7 @@ class Item extends BaseObject {
'vote' => $buttons, 'vote' => $buttons,
'like' => $like, 'like' => $like,
'dislike' => $dislike, 'dislike' => $dislike,
'responses' => $responses,
'switchcomment' => t('Comment'), 'switchcomment' => t('Comment'),
'comment' => $this->get_comment_box($indent), 'comment' => $this->get_comment_box($indent),
'previewing' => ($conv->is_preview() ? ' preview ' : ''), 'previewing' => ($conv->is_preview() ? ' preview ' : ''),