3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Worker;
24 use Friendica\Core\Logger;
25 use Friendica\Core\Protocol;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Contact;
29 use Friendica\Model\Item;
30 use Friendica\Model\User;
31 use Friendica\Protocol\Activity;
32 use Friendica\Protocol\ActivityPub;
33 use Friendica\Protocol\Email;
34 use Friendica\Protocol\Feed;
35 use Friendica\Protocol\PortableContact;
36 use Friendica\Util\DateTimeFormat;
37 use Friendica\Util\Network;
38 use Friendica\Util\Strings;
39 use Friendica\Util\XML;
43 public static function execute($contact_id = 0, $command = '')
45 Logger::log('Start for contact ' . $contact_id);
49 if ($command == "force") {
54 Logger::log('no contact');
59 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
60 if (!DBA::isResult($contact)) {
61 Logger::log('Contact not found or cannot be used.');
65 if (($contact['network'] != Protocol::MAIL) || $force) {
66 Contact::updateFromProbe($contact_id, '', $force);
69 // Special treatment for wrongly detected local contacts
70 if (!$force && ($contact['network'] != Protocol::DFRN) && Contact::isLocalById($contact_id)) {
71 Contact::updateFromProbe($contact_id, Protocol::DFRN, true);
72 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
75 if (($contact['network'] == Protocol::DFRN) && !Contact::isLegacyDFRNContact($contact)) {
76 $protocol = Protocol::ACTIVITYPUB;
78 $protocol = $contact['network'];
81 $importer_uid = $contact['uid'];
83 $updated = DateTimeFormat::utcNow();
85 if ($importer_uid == 0) {
86 Logger::log('Ignore public contacts');
88 // set the last-update so we don't keep polling
89 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
93 // Possibly switch the remote contact to AP
94 if ($protocol === Protocol::OSTATUS) {
95 ActivityPub\Receiver::switchContact($contact['id'], $importer_uid, $contact['url']);
96 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
99 // load current friends if possible.
100 if (!empty($contact['poco']) && ($contact['success_update'] > $contact['failure_update'])) {
101 if (!DBA::exists('glink', ["`cid` = ? AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY", $contact['id']])) {
102 PortableContact::loadWorker($contact['id'], $importer_uid, 0, $contact['poco']);
106 // Don't poll if polling is deactivated (But we poll feeds and mails anyway)
107 if (!in_array($protocol, [Protocol::FEED, Protocol::MAIL]) && DI::config()->get('system', 'disable_polling')) {
108 Logger::log('Polling is disabled');
110 // set the last-update so we don't keep polling
111 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
115 // We don't poll AP contacts by now
116 if ($protocol === Protocol::ACTIVITYPUB) {
117 Logger::log("Don't poll AP contact");
119 // set the last-update so we don't keep polling
120 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
124 $importer = User::getOwnerDataById($importer_uid);
126 if (empty($importer)) {
127 Logger::log('No self contact for user '.$importer_uid);
129 // set the last-update so we don't keep polling
130 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
137 if ($contact['subhub']) {
138 $poll_interval = DI::config()->get('system', 'pushpoll_frequency', 3);
139 $contact['priority'] = intval($poll_interval);
142 if (DateTimeFormat::utcNow() > DateTimeFormat::utc($contact['last-update'] . " + 1 day")) {
149 Logger::log("poll: ({$protocol}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");
153 if ($protocol === Protocol::DFRN) {
154 $xml = self::pollDFRN($contact, $updated);
155 } elseif (($protocol === Protocol::OSTATUS)
156 || ($protocol === Protocol::DIASPORA)
157 || ($protocol === Protocol::FEED)) {
158 $xml = self::pollFeed($contact, $protocol, $updated);
159 } elseif ($protocol === Protocol::MAIL) {
160 self::pollMail($contact, $importer_uid, $updated);
164 Logger::log('received xml : ' . $xml, Logger::DATA);
165 if (!strstr($xml, '<')) {
166 Logger::log('post_handshake: response from ' . $url . ' did not contain XML.');
168 $fields = ['last-update' => $updated, 'failure_update' => $updated];
169 self::updateContact($contact, $fields);
170 Contact::markForArchival($contact);
175 Logger::log("Consume feed of contact ".$contact['id']);
177 Feed::consume($xml, $importer, $contact, $hub);
179 // do it a second time for DFRN so that any children find their parents.
180 if ($protocol === Protocol::DFRN) {
181 Feed::consume($xml, $importer, $contact, $hub);
184 $hubmode = 'subscribe';
185 if ($protocol === Protocol::DFRN || $contact['blocked']) {
186 $hubmode = 'unsubscribe';
189 if (($protocol === Protocol::OSTATUS || $protocol == Protocol::FEED) && (! $contact['hub-verify'])) {
197 Logger::log("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$protocol." Relation: ".$contact['rel']." Update: ".$hub_update);
199 if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $protocol == Protocol::FEED)) {
200 Logger::log('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
201 $hubs = explode(',', $hub);
204 foreach ($hubs as $h) {
211 self::subscribeToHub($h, $importer, $contact, $hubmode);
216 self::updateContact($contact, ['last-update' => $updated, 'success_update' => $updated]);
217 Contact::unmarkForArchival($contact);
218 } elseif (in_array($contact["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::FEED])) {
219 self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
220 Contact::markForArchival($contact);
222 self::updateContact($contact, ['last-update' => $updated]);
229 private static function RemoveReply($subject)
231 while (in_array(strtolower(substr($subject, 0, 3)), ["re:", "aw:"])) {
232 $subject = trim(substr($subject, 4));
239 * Updates a personal contact entry and the public contact entry
241 * @param array $contact The personal contact entry
242 * @param array $fields The fields that are updated
245 private static function updateContact(array $contact, array $fields)
247 DBA::update('contact', $fields, ['id' => $contact['id']]);
248 DBA::update('contact', $fields, ['uid' => 0, 'nurl' => $contact['nurl']]);
254 * @param array $contact The personal contact entry
255 * @param string $updated The updated date
256 * @return string polled XML
259 private static function pollDFRN(array $contact, $updated)
261 $idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
262 if (intval($contact['duplex']) && $contact['dfrn-id']) {
263 $idtosend = '0:' . $orig_id;
265 if (intval($contact['duplex']) && $contact['issued-id']) {
266 $idtosend = '1:' . $orig_id;
269 // they have permission to write to us. We already filtered this in the contact query.
272 // But this may be our first communication, so set the writable flag if it isn't set already.
273 if (!intval($contact['writable'])) {
274 $fields = ['writable' => true];
275 DBA::update('contact', $fields, ['id' => $contact['id']]);
278 $last_update = (($contact['last-update'] <= DBA::NULL_DATETIME)
279 ? DateTimeFormat::utc('now - 7 days', DateTimeFormat::ATOM)
280 : DateTimeFormat::utc($contact['last-update'], DateTimeFormat::ATOM)
283 $url = $contact['poll'] . '?dfrn_id=' . $idtosend
284 . '&dfrn_version=' . DFRN_PROTOCOL_VERSION
285 . '&type=data&last_update=' . $last_update
288 $curlResult = Network::curl($url);
290 if (!$curlResult->isSuccess() && ($curlResult->getErrorNumber() == CURLE_OPERATION_TIMEDOUT)) {
291 // set the last-update so we don't keep polling
292 self::updateContact($contact, ['last-update' => $updated]);
293 Contact::markForArchival($contact);
294 Logger::log('Contact archived');
298 $handshake_xml = $curlResult->getBody();
299 $html_code = $curlResult->getReturnCode();
301 Logger::log('handshake with url ' . $url . ' returns xml: ' . $handshake_xml, Logger::DATA);
303 if (!strlen($handshake_xml) || ($html_code >= 400) || !$html_code) {
304 // dead connection - might be a transient event, or this might
305 // mean the software was uninstalled or the domain expired.
306 // Will keep trying for one month.
307 Logger::log("$url appears to be dead - marking for death ");
309 // set the last-update so we don't keep polling
310 $fields = ['last-update' => $updated, 'failure_update' => $updated];
311 self::updateContact($contact, $fields);
312 Contact::markForArchival($contact);
316 if (!strstr($handshake_xml, '<')) {
317 Logger::log('response from ' . $url . ' did not contain XML.');
319 $fields = ['last-update' => $updated, 'failure_update' => $updated];
320 self::updateContact($contact, $fields);
321 Contact::markForArchival($contact);
325 $res = XML::parseString($handshake_xml);
327 if (!is_object($res)) {
328 Logger::info('Unparseable response', ['url' => $url]);
330 $fields = ['last-update' => $updated, 'failure_update' => $updated];
331 self::updateContact($contact, $fields);
332 Contact::markForArchival($contact);
336 if (intval($res->status) == 1) {
337 // we may not be friends anymore. Will keep trying for one month.
338 Logger::log("$url replied status 1 - marking for death ");
340 // set the last-update so we don't keep polling
341 $fields = ['last-update' => $updated, 'failure_update' => $updated];
342 self::updateContact($contact, $fields);
343 Contact::markForArchival($contact);
344 } elseif ($contact['term-date'] > DBA::NULL_DATETIME) {
345 Contact::unmarkForArchival($contact);
348 if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
349 // set the last-update so we don't keep polling
350 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
351 Logger::log('Contact status is ' . $res->status);
355 if (((float)$res->dfrn_version > 2.21) && ($contact['poco'] == '')) {
356 $fields = ['poco' => str_replace('/profile/', '/poco/', $contact['url'])];
357 DBA::update('contact', $fields, ['id' => $contact['id']]);
362 $sent_dfrn_id = hex2bin((string) $res->dfrn_id);
363 $challenge = hex2bin((string) $res->challenge);
367 if ($contact['duplex'] && strlen($contact['prvkey'])) {
368 openssl_private_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['prvkey']);
369 openssl_private_decrypt($challenge, $postvars['challenge'], $contact['prvkey']);
371 openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']);
372 openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']);
375 $final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
377 if (strpos($final_dfrn_id, ':') == 1) {
378 $final_dfrn_id = substr($final_dfrn_id, 2);
381 // There are issues with the legacy DFRN transport layer.
382 // Since we mostly don't use it anyway, we won't dig into it deeper, but simply ignore it.
383 if (empty($final_dfrn_id) || empty($orig_id)) {
384 Logger::log('Contact has got no ID - quitting');
388 if ($final_dfrn_id != $orig_id) {
389 // did not decode properly - cannot trust this site
390 Logger::log('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
392 // set the last-update so we don't keep polling
393 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
394 Contact::markForArchival($contact);
398 $postvars['dfrn_id'] = $idtosend;
399 $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
400 $postvars['perm'] = 'rw';
402 return Network::post($contact['poll'], $postvars)->getBody();
406 * Poll Feed/OStatus contacts
408 * @param array $contact The personal contact entry
409 * @param string $protocol The used protocol of the contact
410 * @param string $updated The updated date
411 * @return string polled XML
414 private static function pollFeed(array $contact, $protocol, $updated)
416 // Upgrading DB fields from an older Friendica version
417 // Will only do this once per notify-enabled OStatus contact
418 // or if relationship changes
420 $stat_writeable = ((($contact['notify']) && ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND)) ? 1 : 0);
422 // Contacts from OStatus are always writable
423 if ($protocol === Protocol::OSTATUS) {
427 if ($stat_writeable != $contact['writable']) {
428 $fields = ['writable' => $stat_writeable];
429 DBA::update('contact', $fields, ['id' => $contact['id']]);
432 // Are we allowed to import from this person?
433 if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
434 // set the last-update so we don't keep polling
435 DBA::update('contact', ['last-update' => $updated], ['id' => $contact['id']]);
436 Logger::log('Contact is blocked or only a follower');
440 $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-');
441 $curlResult = Network::curl($contact['poll'], false, ['cookiejar' => $cookiejar]);
444 if ($curlResult->isTimeout()) {
445 // set the last-update so we don't keep polling
446 self::updateContact($contact, ['last-update' => $updated]);
447 Contact::markForArchival($contact);
448 Logger::log('Contact archived');
452 return $curlResult->getBody();
458 * @param array $contact The personal contact entry
459 * @param integer $importer_uid The UID of the importer
460 * @param string $updated The updated date
463 private static function pollMail(array $contact, $importer_uid, $updated)
465 Logger::log("Mail: Fetching for ".$contact['addr'], Logger::DEBUG);
467 $mail_disabled = ((function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) ? 0 : 1);
468 if ($mail_disabled) {
469 // set the last-update so we don't keep polling
470 self::updateContact($contact, ['last-update' => $updated]);
471 Contact::markForArchival($contact);
472 Logger::log('Contact archived');
476 Logger::log("Mail: Enabled", Logger::DEBUG);
479 $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $importer_uid]);
481 $condition = ["`server` != '' AND `uid` = ?", $importer_uid];
482 $mailconf = DBA::selectFirst('mailacct', [], $condition);
483 if (DBA::isResult($user) && DBA::isResult($mailconf)) {
484 $mailbox = Email::constructMailboxName($mailconf);
486 openssl_private_decrypt(hex2bin($mailconf['pass']), $password, $user['prvkey']);
487 $mbox = Email::connect($mailbox, $mailconf['user'], $password);
489 Logger::log("Mail: Connect to " . $mailconf['user']);
491 $fields = ['last_check' => $updated];
492 DBA::update('mailacct', $fields, ['id' => $mailconf['id']]);
493 Logger::log("Mail: Connected to " . $mailconf['user']);
495 Logger::log("Mail: Connection error ".$mailconf['user']." ".print_r(imap_errors(), true));
503 $msgs = Email::poll($mbox, $contact['addr']);
506 Logger::log("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], Logger::DEBUG);
508 $metas = Email::messageMeta($mbox, implode(',', $msgs));
510 if (count($metas) != count($msgs)) {
511 Logger::log("for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", Logger::DEBUG);
513 $msgs = array_combine($msgs, $metas);
515 foreach ($msgs as $msg_uid => $meta) {
516 Logger::log("Mail: Parsing mail ".$msg_uid, Logger::DATA);
519 $datarray['uid'] = $importer_uid;
520 $datarray['contact-id'] = $contact['id'];
521 $datarray['verb'] = Activity::POST;
522 $datarray['object-type'] = Activity\ObjectType::NOTE;
523 $datarray['network'] = Protocol::MAIL;
524 // $meta = Email::messageMeta($mbox, $msg_uid);
526 $datarray['uri'] = Email::msgid2iri(trim($meta->message_id, '<>'));
528 // Have we seen it before?
529 $fields = ['deleted', 'id'];
530 $condition = ['uid' => $importer_uid, 'uri' => $datarray['uri']];
531 $item = Item::selectFirst($fields, $condition);
532 if (DBA::isResult($item)) {
533 Logger::log("Mail: Seen before ".$msg_uid." for ".$mailconf['user']." UID: ".$importer_uid." URI: ".$datarray['uri'],Logger::DEBUG);
535 // Only delete when mails aren't automatically moved or deleted
536 if (($mailconf['action'] != 1) && ($mailconf['action'] != 3))
537 if ($meta->deleted && ! $item['deleted']) {
538 $fields = ['deleted' => true, 'changed' => $updated];
539 Item::update($fields, ['id' => $item['id']]);
542 switch ($mailconf['action']) {
544 Logger::log("Mail: Seen before ".$msg_uid." for ".$mailconf['user'].". Doing nothing.", Logger::DEBUG);
547 Logger::log("Mail: Deleting ".$msg_uid." for ".$mailconf['user']);
548 imap_delete($mbox, $msg_uid, FT_UID);
551 Logger::log("Mail: Mark as seen ".$msg_uid." for ".$mailconf['user']);
552 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
555 Logger::log("Mail: Moving ".$msg_uid." to ".$mailconf['movetofolder']." for ".$mailconf['user']);
556 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
557 if ($mailconf['movetofolder'] != "") {
558 imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
565 // look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally.
566 $raw_refs = (property_exists($meta, 'references') ? str_replace("\t", '', $meta->references) : '');
567 if (!trim($raw_refs)) {
568 $raw_refs = (property_exists($meta, 'in_reply_to') ? str_replace("\t", '', $meta->in_reply_to) : '');
570 $raw_refs = trim($raw_refs); // Don't allow a blank reference in $refs_arr
573 $refs_arr = explode(' ', $raw_refs);
574 if (count($refs_arr)) {
575 for ($x = 0; $x < count($refs_arr); $x ++) {
576 $refs_arr[$x] = Email::msgid2iri(str_replace(['<', '>', ' '],['', '', ''], $refs_arr[$x]));
579 $condition = ['uri' => $refs_arr, 'uid' => $importer_uid];
580 $parent = Item::selectFirst(['parent-uri'], $condition);
581 if (DBA::isResult($parent)) {
582 $datarray['parent-uri'] = $parent['parent-uri']; // Set the parent as the top-level item
586 // Decoding the header
587 $subject = imap_mime_header_decode($meta->subject ?? '');
588 $datarray['title'] = "";
589 foreach ($subject as $subpart) {
590 if ($subpart->charset != "default") {
591 $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text);
593 $datarray['title'] .= $subpart->text;
596 $datarray['title'] = Strings::escapeTags(trim($datarray['title']));
598 //$datarray['title'] = Strings::escapeTags(trim($meta->subject));
599 $datarray['created'] = DateTimeFormat::utc($meta->date);
602 $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") ||
603 (substr(strtolower($datarray['title']), 0, 3) == "re-") ||
606 // Remove Reply-signs in the subject
607 $datarray['title'] = self::RemoveReply($datarray['title']);
609 // If it seems to be a reply but a header couldn't be found take the last message with matching subject
610 if (empty($datarray['parent-uri']) && $reply) {
611 $condition = ['title' => $datarray['title'], 'uid' => $importer_uid, 'network' => Protocol::MAIL];
612 $params = ['order' => ['created' => true]];
613 $parent = Item::selectFirst(['parent-uri'], $condition, $params);
614 if (DBA::isResult($parent)) {
615 $datarray['parent-uri'] = $parent['parent-uri'];
619 if (empty($datarray['parent-uri'])) {
620 $datarray['parent-uri'] = $datarray['uri'];
623 $headers = imap_headerinfo($mbox, $meta->msgno);
627 if (!empty($headers->from)) {
628 $object['from'] = $headers->from;
631 if (!empty($headers->to)) {
632 $object['to'] = $headers->to;
635 if (!empty($headers->reply_to)) {
636 $object['reply_to'] = $headers->reply_to;
639 if (!empty($headers->sender)) {
640 $object['sender'] = $headers->sender;
643 if (!empty($object)) {
644 $datarray['object'] = json_encode($object);
647 $fromname = $frommail = $headers->from[0]->mailbox . '@' . $headers->from[0]->host;
648 if (!empty($headers->from[0]->personal)) {
649 $fromname = $headers->from[0]->personal;
652 $datarray['author-name'] = $fromname;
653 $datarray['author-link'] = "mailto:".$frommail;
654 $datarray['author-avatar'] = $contact['photo'];
656 $datarray['owner-name'] = $contact['name'];
657 $datarray['owner-link'] = "mailto:".$contact['addr'];
658 $datarray['owner-avatar'] = $contact['photo'];
660 if ($datarray['parent-uri'] === $datarray['uri']) {
661 $datarray['private'] = Item::PRIVATE;
664 if (!DI::pConfig()->get($importer_uid, 'system', 'allow_public_email_replies')) {
665 $datarray['private'] = Item::PRIVATE;
666 $datarray['allow_cid'] = '<' . $contact['id'] . '>';
669 $datarray = Email::getMessage($mbox, $msg_uid, $reply, $datarray);
670 if (empty($datarray['body'])) {
671 Logger::log("Mail: can't fetch msg ".$msg_uid." for ".$mailconf['user']);
675 Logger::log("Mail: Importing ".$msg_uid." for ".$mailconf['user']);
677 Item::insert($datarray);
679 switch ($mailconf['action']) {
681 Logger::log("Mail: Seen before ".$msg_uid." for ".$mailconf['user'].". Doing nothing.", Logger::DEBUG);
684 Logger::log("Mail: Deleting ".$msg_uid." for ".$mailconf['user']);
685 imap_delete($mbox, $msg_uid, FT_UID);
688 Logger::log("Mail: Mark as seen ".$msg_uid." for ".$mailconf['user']);
689 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
692 Logger::log("Mail: Moving ".$msg_uid." to ".$mailconf['movetofolder']." for ".$mailconf['user']);
693 imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
694 if ($mailconf['movetofolder'] != "") {
695 imap_mail_move($mbox, $msg_uid, $mailconf['movetofolder'], FT_UID);
702 Logger::log("Mail: no mails for ".$mailconf['user']);
705 Logger::log("Mail: closing connection for ".$mailconf['user']);
712 * @param array $importer
713 * @param array $contact
714 * @param string $hubmode
715 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
717 private static function subscribeToHub(string $url, array $importer, array $contact, $hubmode = 'subscribe')
720 * Diaspora has different message-ids in feeds than they do
721 * through the direct Diaspora protocol. If we try and use
722 * the feed, we'll get duplicates. So don't.
724 if ($contact['network'] === Protocol::DIASPORA) {
728 // Without an importer we don't have a user id - so we quit
729 if (empty($importer)) {
733 $user = DBA::selectFirst('user', ['nickname'], ['uid' => $importer['uid']]);
735 // No user, no nickname, we quit
736 if (!DBA::isResult($user)) {
740 $push_url = DI::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
742 // Use a single verify token, even if multiple hubs
743 $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
745 $params = 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
747 Logger::log('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
749 if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
750 DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
753 $postResult = Network::post($url, $params);
755 Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);