new function hubloc_change_primary()
This commit is contained in:
parent
a512d1a4aa
commit
1b0390af06
@ -113,4 +113,46 @@ function remove_obsolete_hublocs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hubloc_change_primary($hubloc) {
|
||||||
|
|
||||||
|
if(! is_array($hubloc))
|
||||||
|
return false;
|
||||||
|
if(! $hubloc['hubloc_flags'] & HUBLOC_FLAGS_PRIMARY)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// See if there's a local channel
|
||||||
|
|
||||||
|
$r = q("select channel_id, channel_primary from channel where channel_hash = '%s' limit 1",
|
||||||
|
dbesc($hubloc['hubloc_hash'])
|
||||||
|
);
|
||||||
|
if(($r) && (! $r[0]['channel_primary'])) {
|
||||||
|
q("update channel set channel_primary = 1 where channel_id = %d limit 1",
|
||||||
|
intval($r[0]['channel_id'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// do we even have an xchan for this hubloc and if so is it already set as primary?
|
||||||
|
|
||||||
|
$r = q("select * from xchan where xchan_hash = '%s' limit 1",
|
||||||
|
dbesc($hubloc['hubloc_hash'])
|
||||||
|
);
|
||||||
|
if(! $r)
|
||||||
|
return false;
|
||||||
|
if($r[0]['xchan_addr'] === $hubloc['hubloc_addr'])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$url = $hubloc['hubloc_url'];
|
||||||
|
$lwebbie = substr($hubloc['hubloc_addr'],0,strpos($hubloc['hubloc_addr'],'@'));
|
||||||
|
|
||||||
|
$r = q("update xchan set xchan_addr, xchan_url = '%s', xchan_follow = '%s', xchan_connurl = '%s', where xchan_hash = '%s' limit 1",
|
||||||
|
dbesc($hubloc['hubloc_addr']),
|
||||||
|
dbesc($url . '/channel/' . $lwebbie),
|
||||||
|
dbesc($url . '/follow?f=&url=%s'),
|
||||||
|
dbesc($url . '/poco/' . $lwebbie),
|
||||||
|
dbesc($hubloc['hubloc_hash'])
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
require_once('include/crypto.php');
|
require_once('include/crypto.php');
|
||||||
require_once('include/items.php');
|
require_once('include/items.php');
|
||||||
|
require_once('include/hubloc.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Red implementation of zot protocol.
|
* Red implementation of zot protocol.
|
||||||
@ -1714,9 +1715,14 @@ function process_location_delivery($sender,$arr,$deliveries) {
|
|||||||
);
|
);
|
||||||
if($r)
|
if($r)
|
||||||
$sender['key'] = $r[0]['xchan_pubkey'];
|
$sender['key'] = $r[0]['xchan_pubkey'];
|
||||||
|
if(array_key_exists('locations',$arr) && $arr['locations']) {
|
||||||
$x = sync_locations($sender,$arr,true);
|
$x = sync_locations($sender,$arr,true);
|
||||||
logger('process_location_delivery: results: ' . print_r($x,true), LOGGER_DEBUG);
|
logger('process_location_delivery: results: ' . print_r($x,true), LOGGER_DEBUG);
|
||||||
|
if($x['changed']) {
|
||||||
|
$guid = random_string() . '@' . get_app()->get_hostname();
|
||||||
|
update_modtime($sender['hash'],$sender['guid'],$arr['locations'][0]['address'],UPDATE_FLAGS_UPDATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1837,6 +1843,7 @@ function sync_locations($sender,$arr,$absolute = false) {
|
|||||||
dbesc(datetime_convert()),
|
dbesc(datetime_convert()),
|
||||||
intval($r[0]['hubloc_id'])
|
intval($r[0]['hubloc_id'])
|
||||||
);
|
);
|
||||||
|
hubloc_change_primary($r[0]);
|
||||||
$what .= 'primary_hub ';
|
$what .= 'primary_hub ';
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
@ -1884,6 +1891,14 @@ function sync_locations($sender,$arr,$absolute = false) {
|
|||||||
$what .= 'newhub ';
|
$what .= 'newhub ';
|
||||||
$changed = true;
|
$changed = true;
|
||||||
|
|
||||||
|
if($location['primary']) {
|
||||||
|
$r = q("select * from hubloc where hubloc_addr = '%s' and hubloc_sitekey = '%s' limit 1",
|
||||||
|
dbesc($location['address']),
|
||||||
|
dbesc($location['sitekey'])
|
||||||
|
);
|
||||||
|
if($r)
|
||||||
|
hubloc_change_primary($r[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get rid of any hubs we have for this channel which weren't reported.
|
// get rid of any hubs we have for this channel which weren't reported.
|
||||||
|
Reference in New Issue
Block a user