more diaspora heavy lifting
This commit is contained in:
parent
df634f9853
commit
84ff380302
@ -423,7 +423,7 @@ function user_deny($hash) {
|
||||
if(! count($register))
|
||||
return false;
|
||||
|
||||
$account = q("SELECT account_id FROM account WHERE account_id = %d LIMIT 1",
|
||||
$account = q("SELECT account_id, account_email FROM account WHERE account_id = %d LIMIT 1",
|
||||
intval($register[0]['uid'])
|
||||
);
|
||||
|
||||
|
@ -121,7 +121,129 @@ function diaspora_is_blacklisted($s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function diaspora_process_outbound($arr) {
|
||||
|
||||
/*
|
||||
|
||||
We are passed the following array from the notifier, providing everything we need to make delivery decisions.
|
||||
|
||||
diaspora_process_outbound(array(
|
||||
'channel' => $channel,
|
||||
'env_recips' => $env_recips,
|
||||
'recipients' => $recipients,
|
||||
'item' => $item,
|
||||
'target_item' => $target_item,
|
||||
'hub' => $hub,
|
||||
'top_level_post' => $top_level_post,
|
||||
'private' => $private,
|
||||
'followup' => $followup,
|
||||
'relay_to_owner' => $relay_to_owner,
|
||||
'uplink' => $uplink,
|
||||
'cmd' => $cmd,
|
||||
'expire' => $expire,
|
||||
'mail' => $mail,
|
||||
'fsuggest' => $fsuggest,
|
||||
'normal_mode' => $normal_mode,
|
||||
'packet_type' => $packet_type,
|
||||
'walltowall' => $walltowall,
|
||||
));
|
||||
*/
|
||||
|
||||
|
||||
if($arr['walltowall'])
|
||||
return;
|
||||
|
||||
if($arr['recipients']) {
|
||||
$r = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where hubloc_url = '%s'
|
||||
and xchan_hash in (" . implode(',',$arr['recipients']) . ")
|
||||
and xchan_network in ('diaspora', 'friendica-over-diaspora') ",
|
||||
dbesc($arr['hub']['hubloc_url'])
|
||||
);
|
||||
if(! $r) {
|
||||
logger('diaspora_process_outbound: no recipients');
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($r as $contact) {
|
||||
|
||||
if($arr['mail']) {
|
||||
diaspora_send_mail($arr['item'],$arr['channel'],$contact);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! $arr['normal_mode'])
|
||||
continue;
|
||||
|
||||
// special handling for followup to public post
|
||||
// all other public posts processed as public batches further below
|
||||
|
||||
if((! $arr['private']) && ($arr['followup'])) {
|
||||
diaspora_send_followup($arr['target_item'],$arr['channel'],$contact, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! $contact['xchan_pubkey'])
|
||||
continue;
|
||||
|
||||
if(activity_match($arr['target_item']['verb'],ACTIVITY_DISLIKE)) {
|
||||
continue;
|
||||
}
|
||||
elseif(($arr['target_item']['item_restrict'] & ITEM_DELETED)
|
||||
&& (($arr['target_item']['mid'] === $arr['target_item']['parent_mid']) || $arr['followup'])) {
|
||||
// send both top-level retractions and relayable retractions for owner to relay
|
||||
diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact);
|
||||
continue;
|
||||
}
|
||||
elseif($arr['followup']) {
|
||||
// send comments and likes to owner to relay
|
||||
diaspora_send_followup($arr['target_item'],$arr['channel'],$contact);
|
||||
continue;
|
||||
}
|
||||
|
||||
elseif($target_item['mid'] !== $target_item['parent_mid']) {
|
||||
// we are the relay - send comments, likes and relayable_retractions
|
||||
// (of comments and likes) to our conversants
|
||||
diaspora_send_relay($arr['target_item'],$arr['channel'],$contact);
|
||||
continue;
|
||||
}
|
||||
elseif($arr['top_level']) {
|
||||
diaspora_send_status($arr['target_item'],$arr['channel'],$contact);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// public message
|
||||
|
||||
$contact = array('hubloc_callback' => $arr['hub']['hubloc_callback']);
|
||||
|
||||
if($target_item['verb'] === ACTIVITY_DISLIKE) {
|
||||
// unsupported
|
||||
return;
|
||||
}
|
||||
elseif(($arr['target_item']['deleted'])
|
||||
&& ($arr['target_item']['mid'] === $arr['target_item']['parent_mod'])) {
|
||||
// top-level retraction
|
||||
logger('delivery: diaspora retract: ' . $loc);
|
||||
diaspora_send_retraction($arr['target_item'],$arr['channel'],$contact,true);
|
||||
return;
|
||||
}
|
||||
elseif($arr['target_item']['mid'] !== $mid['target_item']['parent_mid']) {
|
||||
// we are the relay - send comments, likes and relayable_retractions to our conversants
|
||||
logger('delivery: diaspora relay: ' . $loc);
|
||||
diaspora_send_relay($arr['target_item'],$arr['channel'],$contact,true);
|
||||
return;
|
||||
}
|
||||
elseif(($arr['top_level_post']) && (! $arr['walltowall'])) {
|
||||
// currently no workable solution for sending walltowall
|
||||
logger('delivery: diaspora status: ' . $loc);
|
||||
diaspora_send_status($arr['target_item'],$arr['channel'],$contact,true);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2044,6 +2166,18 @@ function diaspora_profile($importer,$xml,$msg) {
|
||||
function diaspora_share($me,$contact) {
|
||||
$a = get_app();
|
||||
$myaddr = $me['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
|
||||
if(! array_key_exists('xchan_hash',$contact)) {
|
||||
$c = q("select * from xchan left join hubloc on xchan_hash = hubloc_hash where xchan_hash = '%s' limit 1",
|
||||
dbesc($contact['hubloc_hash'])
|
||||
);
|
||||
if(! $c) {
|
||||
logger('diaspora_share: ' . $contact['hubloc_hash'] . ' not found.');
|
||||
return;
|
||||
}
|
||||
$contact = $c[0];
|
||||
}
|
||||
|
||||
$theiraddr = $contact['xchan_addr'];
|
||||
|
||||
$tpl = get_markup_template('diaspora_share.tpl');
|
||||
@ -2052,29 +2186,25 @@ function diaspora_share($me,$contact) {
|
||||
'$recipient' => $theiraddr
|
||||
));
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']));
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['channel_prvkey'],$contact['xchan_pubkey'])));
|
||||
return(diaspora_transmit($owner,$contact,$slap, false));
|
||||
}
|
||||
|
||||
function diaspora_unshare($me,$contact) {
|
||||
|
||||
$a = get_app();
|
||||
$myaddr = $me['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
$myaddr = $me['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
|
||||
$tpl = get_markup_template('diaspora_retract.tpl');
|
||||
$msg = replace_macros($tpl, array(
|
||||
'$guid' => $me['guid'],
|
||||
'$guid' => $me['channel_guid'],
|
||||
'$type' => 'Person',
|
||||
'$handle' => $myaddr
|
||||
));
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey'])));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$me,$contact,$me['prvkey'],$contact['pubkey']));
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$me,$contact,$me['channel_prvkey'],$contact['xchan_pubkey'])));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap, false));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2082,7 +2212,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
|
||||
|
||||
$a = get_app();
|
||||
$myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
$theiraddr = $contact['xchan_addr'];
|
||||
|
||||
$images = array();
|
||||
|
||||
@ -2167,7 +2296,6 @@ function diaspora_send_status($item,$owner,$contact,$public_batch = false) {
|
||||
logger('diaspora_send_status: '.$owner['channel_name'].' -> '.$contact['xchan_name'].' base message: '.$msg, LOGGER_DATA);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
$return_code = diaspora_transmit($owner,$contact,$slap,$public_batch);
|
||||
|
||||
@ -2262,7 +2390,6 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals
|
||||
|
||||
logger('diaspora_send_photo: base message: ' . $msg, LOGGER_DATA);
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
|
||||
diaspora_transmit($owner,$contact,$slap,$public_batch);
|
||||
}
|
||||
@ -2346,7 +2473,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
|
||||
|
||||
$a = get_app();
|
||||
$myaddr = $owner['channel_address'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
|
||||
// $theiraddr = $contact['addr'];
|
||||
|
||||
|
||||
$body = $item['body'];
|
||||
$text = html_entity_decode(bb2diaspora($body));
|
||||
@ -2471,8 +2598,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
|
||||
logger('diaspora_send_relay: base message: ' . $msg, LOGGER_DATA);
|
||||
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch)));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
|
||||
|
||||
@ -2506,8 +2632,7 @@ function diaspora_send_retraction($item,$owner,$contact,$public_batch = false) {
|
||||
'$signature' => xmlify(base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256')))
|
||||
));
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],$public_batch));
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],$public_batch)));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,$public_batch));
|
||||
}
|
||||
@ -2542,7 +2667,7 @@ function diaspora_send_mail($item,$owner,$contact) {
|
||||
$signed_text = $item['guid'] . ';' . $cnv['guid'] . ';' . $body . ';'
|
||||
. $created . ';' . $myaddr . ';' . $cnv['guid'];
|
||||
|
||||
$sig = base64_encode(rsa_sign($signed_text,$owner['uprvkey'],'sha256'));
|
||||
$sig = base64_encode(rsa_sign($signed_text,$owner['channel_prvkey'],'sha256'));
|
||||
|
||||
$msg = array(
|
||||
'guid' => xmlify($item['guid']),
|
||||
@ -2567,8 +2692,7 @@ function diaspora_send_mail($item,$owner,$contact) {
|
||||
|
||||
logger('diaspora_conversation: ' . print_r($xmsg,true), LOGGER_DATA);
|
||||
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false)));
|
||||
//$slap = 'xml=' . urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['uprvkey'],$contact['pubkey'],false));
|
||||
$slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($xmsg,$owner,$contact,$owner['channel_prvkey'],$contact['xchan_pubkey'],false)));
|
||||
|
||||
return(diaspora_transmit($owner,$contact,$slap,false));
|
||||
|
||||
@ -2582,6 +2706,21 @@ function diaspora_transmit($owner,$contact,$slap,$public_batch,$queue_run=false)
|
||||
return 200;
|
||||
}
|
||||
|
||||
if($public_batch)
|
||||
$dest_url = $contact['hubloc_callback'] . '/public';
|
||||
else
|
||||
$dest_url = $contact['hubloc_callback'] . '/users/' . $contact['guid'];
|
||||
|
||||
|
||||
|
||||
if(intval(get_config('system','diaspora_test')))
|
||||
return 200;
|
||||
|
||||
|
||||
|
||||
return 200;
|
||||
|
||||
|
||||
$a = get_app();
|
||||
$logid = random_string(4);
|
||||
$dest_url = (($public_batch) ? $contact['batch'] : $contact['notify']);
|
||||
|
@ -103,11 +103,15 @@ function notifier_run($argv, $argc){
|
||||
);
|
||||
if($r) {
|
||||
// Get the sender
|
||||
$s = q("select * from channel where channel_id = %d limit 1",
|
||||
$s = q("select * from channel left join xchan on channel_hash = xchan_hash where channel_id = %d limit 1",
|
||||
intval($r[0]['abook_channel'])
|
||||
);
|
||||
if($s) {
|
||||
|
||||
if($r[0]['hubloc_network'] === 'diaspora' || $r[0]['hubloc_network'] === 'friendica_over_diaspora') {
|
||||
require_once('include/diaspora.php');
|
||||
diaspora_share($s[0],$r[0]);
|
||||
}
|
||||
else {
|
||||
// send a refresh message to each hub they have registered here
|
||||
$h = q("select * from hubloc where hubloc_hash = '%s'",
|
||||
dbesc($r[0]['hubloc_hash'])
|
||||
@ -130,6 +134,7 @@ function notifier_run($argv, $argc){
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -366,6 +371,8 @@ function notifier_run($argv, $argc){
|
||||
|
||||
}
|
||||
|
||||
$walltowall = (($top_level_post && $channel['xchan_hash'] === $target_item['author_xchan']) ? true : false);
|
||||
|
||||
// Generic delivery section, we have an encoded item and recipients
|
||||
// Now start the delivery process
|
||||
|
||||
@ -438,11 +445,11 @@ function notifier_run($argv, $argc){
|
||||
// aren't the owner or author.
|
||||
|
||||
|
||||
$r = q("select hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc
|
||||
$r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc
|
||||
where hubloc_hash in (" . implode(',',$recipients) . ") group by hubloc_sitekey order by hubloc_connected desc limit 1");
|
||||
}
|
||||
else {
|
||||
$r = q("select hubloc_sitekey, hubloc_flags, hubloc_callback, hubloc_host from hubloc
|
||||
$r = q("select hubloc_sitekey, hubloc_network, hubloc_flags, hubloc_callback, hubloc_host from hubloc
|
||||
where hubloc_hash in (" . implode(',',$recipients) . ") $sql_extra group by hubloc_sitekey");
|
||||
}
|
||||
|
||||
@ -485,6 +492,42 @@ function notifier_run($argv, $argc){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($hub['network'] === 'diaspora' || $hub['network'] === 'friendica-over-diaspora') {
|
||||
if(! get_config('system','diaspora_enabled'))
|
||||
continue;
|
||||
|
||||
require_once('include/diaspora.php');
|
||||
|
||||
diaspora_process_outbound(array(
|
||||
'channel' => $channel,
|
||||
'env_recips' => $env_recips,
|
||||
'recipients' => $recipients,
|
||||
'item' => $item,
|
||||
'target_item' => $target_item,
|
||||
'hub' => $hub,
|
||||
'top_level_post' => $top_level_post,
|
||||
'private' => $private,
|
||||
'followup' => $followup,
|
||||
'relay_to_owner' => $relay_to_owner,
|
||||
'uplink' => $uplink,
|
||||
'cmd' => $cmd,
|
||||
'expire' => $expire,
|
||||
'mail' => $mail,
|
||||
'fsuggest' => $fsuggest,
|
||||
'normal_mode' => $normal_mode,
|
||||
'packet_type' => $packet_type,
|
||||
'walltowall' => $walltowall
|
||||
));
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// default: zot protocol
|
||||
|
||||
|
||||
$hash = random_string();
|
||||
if($packet_type === 'refresh' || $packet_type === 'purge') {
|
||||
$n = zot_build_packet($channel,$packet_type);
|
||||
|
Reference in New Issue
Block a user