Move subscribe_to_hub function to Worker/OnePoll from include/items
- It was its only usage
This commit is contained in:
parent
3d55ef1546
commit
e3d20b4366
2 changed files with 53 additions and 45 deletions
|
|
@ -283,47 +283,3 @@ function consume_feed($xml, array $importer, array $contact, &$hub)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'subscribe')
|
||||
{
|
||||
/*
|
||||
* Diaspora has different message-ids in feeds than they do
|
||||
* through the direct Diaspora protocol. If we try and use
|
||||
* the feed, we'll get duplicates. So don't.
|
||||
*/
|
||||
if ($contact['network'] === Protocol::DIASPORA) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Without an importer we don't have a user id - so we quit
|
||||
if (empty($importer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = DBA::selectFirst('user', ['nickname'], ['uid' => $importer['uid']]);
|
||||
|
||||
// No user, no nickname, we quit
|
||||
if (!DBA::isResult($user)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$push_url = DI::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
|
||||
|
||||
// Use a single verify token, even if multiple hubs
|
||||
$verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
|
||||
|
||||
$params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
|
||||
|
||||
Logger::log('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
|
||||
|
||||
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
|
||||
DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
|
||||
}
|
||||
|
||||
$postResult = Network::post($url, $params);
|
||||
|
||||
Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue