more federation work

This commit is contained in:
redmatrix 2016-03-20 21:41:19 -07:00
parent d3e7ef70e8
commit 28599fe652
2 changed files with 28 additions and 32 deletions

View File

@ -134,26 +134,29 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
$their_perms = 0; $their_perms = 0;
$xchan_hash = ''; $xchan_hash = '';
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1",
dbesc($url), dbesc($url),
dbesc($url) dbesc($url)
); );
if(! $r) { if(! $r) {
// attempt network auto-discovery // attempt network auto-discovery
if(strpos($url,'@') && (! $is_http)) {
$d = discover_by_webbie($url); $d = discover_by_webbie($url);
}
elseif($is_http) { if((! $d) && ($is_http)) {
if(get_config('system','feed_contacts'))
// try RSS discovery
if(get_config('system','feed_contacts')) {
$d = discover_by_url($url); $d = discover_by_url($url);
}
else { else {
$result['message'] = t('Protocol disabled.'); $result['message'] = t('Protocol disabled.');
return $result; return $result;
} }
} }
if($d) { if($d) {
$r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1", $r = q("select * from xchan where xchan_hash = '%s' or xchan_url = '%s' limit 1",
dbesc($url), dbesc($url),
@ -161,6 +164,9 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
); );
} }
} }
// if discovery was a success we should have an xchan record in $r
if($r) { if($r) {
$xchan = $r[0]; $xchan = $r[0];
$xchan_hash = $r[0]['xchan_hash']; $xchan_hash = $r[0]['xchan_hash'];
@ -187,28 +193,13 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
} }
$singleton = intval($x['singleton']); $singleton = intval($x['singleton']);
if((local_channel()) && $uid == local_channel()) { $aid = $channel['channel_account_id'];
$aid = get_account_id(); $hash = get_observer_hash();
$hash = get_observer_hash(); $default_group = $channel['channel_default_group'];
$ch = $a->get_channel();
$default_group = $ch['channel_default_group'];
}
else {
$r = q("select * from channel where channel_id = %d limit 1",
intval($uid)
);
if(! $r) {
$result['message'] = t('local account not found.');
return $result;
}
$aid = $r[0]['channel_account_id'];
$hash = $r[0]['channel_hash'];
$default_group = $r[0]['channel_default_group'];
}
if($xchan['xchan_network'] === 'rss') {
if($is_http) { // check service class feed limits
$r = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ", $r = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ",
intval($aid) intval($aid)
@ -232,7 +223,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
intval($uid) intval($uid)
); );
if($r) { if($r) {
$abook_instance = $r[0]['abook_instance']; $abook_instance = $r[0]['abook_instance'];
@ -282,7 +272,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false)
proc_run('php', 'include/notifier.php', 'permission_create', $result['abook']['abook_id']); proc_run('php', 'include/notifier.php', 'permission_create', $result['abook']['abook_id']);
} }
$arr = array('channel_id' => $uid, 'abook' => $result['abook']); $arr = array('channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook']);
call_hooks('follow', $arr); call_hooks('follow', $arr);

View File

@ -1113,8 +1113,7 @@ function discover_by_webbie($webbie) {
} }
} }
logger('webfing: ' . print_r($x,true), LOGGER_DATA, LOG_INFO);
logger('webfing: ' . print_r($x,true));
$arr = array('address' => $webbie, 'success' => false, 'webfinger' => $x); $arr = array('address' => $webbie, 'success' => false, 'webfinger' => $x);
call_hooks('discover_channel_webfinger', $arr); call_hooks('discover_channel_webfinger', $arr);
@ -1131,6 +1130,13 @@ function discover_by_webbie($webbie) {
$k = z_fetch_url($atom_feed); $k = z_fetch_url($atom_feed);
if($k['success']) if($k['success'])
$feed_meta = feed_meta($k['body']); $feed_meta = feed_meta($k['body']);
// stash any discovered pubsubhubbub hubs in case we need to follow them
// this will save an expensive lookup later
if($feed_meta['hubs'])
set_xconfig($addr,'system','push_hubs',$feed_meta['hubs']);
if($feed_meta && $feed_meta['author']) { if($feed_meta && $feed_meta['author']) {
$r = q("select * from xchan where xchan_hash = '%s' limit 1", $r = q("select * from xchan where xchan_hash = '%s' limit 1",
dbesc($addr) dbesc($addr)
@ -1156,7 +1162,7 @@ function discover_by_webbie($webbie) {
dbescdate(datetime_convert()) dbescdate(datetime_convert())
); );
} }
$r = q("select * from hubloc where hubloc_hash = '%s' limit 1", $r = q("select * from hubloc where hubloc_hash = '%s' limit 1",
dbesc($addr) dbesc($addr)
); );