lots more diaspora communications - can see light at the end

This commit is contained in:
Friendika 2011-08-18 21:09:44 -07:00
parent 457f8c3e95
commit d2c6c21a88
2 changed files with 151 additions and 9 deletions

View file

@ -801,7 +801,7 @@ function diaspora_share($me,$contact) {
function diaspora_send_status($item,$owner,$contact) { function diaspora_send_status($item,$owner,$contact) {
$a = get_app(); $a = get_app();
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3); $myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
$theiraddr = $contact['addr']; $theiraddr = $contact['addr'];
require_once('include/bbcode.php'); require_once('include/bbcode.php');
@ -830,3 +830,141 @@ function diaspora_send_status($item,$owner,$contact) {
return $return_code; return $return_code;
} }
function diaspora_send_followup($item,$owner,$contact) {
$a = get_app();
$myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
$theiraddr = $contact['addr'];
$p = q("select guid from item where parent = %d limit 1",
$item['parent']
);
if(count($p))
$parent_guid = $p[0]['guid'];
else
return;
if($item['verb'] === ACTIVITY_LIKE) {
$tpl = get_markup_template('diaspora_like.tpl');
$like = true;
$target_type = 'Post';
$positive = (($item['deleted']) ? 'false' : 'true');
}
else {
$tpl = get_markup_template('diaspora_comment.tpl');
$like = false;
}
$text = bbcode($item['body']);
// sign it
if($like)
$signed_text = $item['guid'] . ';' . $target_type . ';' . $positive . ';' . $myaddr;
else
$signed_text = $item['guid'] . ';' . $parent_guid . ';' . $text . $myaddr;
$authorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey']));
$msg = replace_macros($tpl,array(
'$guid' => xmlify($item['guid']),
'$parent_guid' => xmlify($parent_guid),
'$target_type' =>xmlify($target_type),
'$authorsig' => xmlify($authorsig),
'$text' => xmlify($text),
'$positive' => xmlify($positive),
'$diaspora_handle' => xmlify($myaddr)
));
logger('diaspora_followup: base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']));
post_url($contact['notify'],$slap);
$return_code = $a->get_curl_code();
logger('diaspora_send_status: returns: ' . $return_code);
return $return_code;
}
function diaspora_send_relay($item,$owner,$contact) {
$p = q("select guid from item where parent = %d limit 1",
$item['parent']
);
if(count($p))
$parent_guid = $p[0]['guid'];
else
return;
// fetch the original signature
$r = q("select * from sign where iid = %d limit 1",
intval($item['id'])
);
if(! count($r))
return;
$orig_sign = $r[0];
if($item['verb'] === ACTIVITY_LIKE) {
$tpl = get_markup_template('diaspora_like_relay.tpl');
$like = true;
$target_type = 'Post';
$positive = (($item['deleted']) ? 'false' : 'true');
}
else {
$tpl = get_markup_template('diaspora_comment_relay.tpl');
$like = false;
}
$text = bbcode($item['body']);
// sign it
if($like)
$parent_signed_text = $orig_sign['signed_text'];
else
$parent_signed_text = $orig_sign['signed_text'];
$parentauthorsig = base64_encode(rsa_sign($signed_text,$owner['uprvkey']));
$msg = replace_macros($tpl,array(
'$guid' => xmlify($item['guid']),
'$parent_guid' => xmlify($parent_guid),
'$target_type' =>xmlify($target_type),
'$authorsig' => xmlify($orig_sign['signature']),
'$parentsig' => xmlify($parentauthorsig),
'$text' => xmlify($text),
'$positive' => xmlify($positive),
'$diaspora_handle' => xmlify($myaddr)
));
// fetch the original signature
$r = q("select * from sign where iid = %d limit 1",
intval($item['id'])
);
if(! count($r))
return;
logger('diaspora_relay_comment: base message: ' . $msg, LOGGER_DATA);
$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey']));
post_url($contact['notify'],$slap);
$return_code = $a->get_curl_code();
logger('diaspora_send_status: returns: ' . $return_code);
return $return_code;
}
function diaspora_send_retraction($item,$owner,$contact) {
}

View file

@ -504,20 +504,24 @@ function notifier_run($argv, $argc){
case NETWORK_DIASPORA: case NETWORK_DIASPORA:
if(get_config('system','dfrn_only') || (! get_config('diaspora_enabled')) || (! $normal_mode)) if(get_config('system','dfrn_only') || (! get_config('diaspora_enabled')) || (! $normal_mode))
break; break;
if($target_item['deleted']) { if($target_item['verb'] === ACTIVITY_DISLIKE) {
// diaspora delete, (check for like) // unsupported
break;
}
elseif($target_item['deleted'] && (! $parent_item['verb'] === ACTIVITY_LIKE)) {
// diaspora delete,
diaspora_send_retraction($target_item,$owner,$contact);
break; break;
} }
elseif($followup) { elseif($followup) {
// send to owner to relay // send comments, likes and retractions of likes to owner to relay
diaspora_send_followup($target_item,$owner,$contact);
break; break;
} }
elseif($target_item['parent'] != $target_item['id']) { elseif($target_item['parent'] != $target_item['id']) {
// we are the relay // we are the relay - send comments, likes and unlikes to our conversants
diaspora_send_relay($target_item,$owner,$contact);
break; break;
} }
elseif($top_level) { elseif($top_level) {