]> git.mxchange.org Git - friendica.git/commitdiff
Move subscribe_to_hub function to Worker/OnePoll from include/items
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Jun 2020 08:52:23 +0000 (04:52 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 17 Jun 2020 17:24:44 +0000 (13:24 -0400)
- It was its only usage

include/items.php
src/Worker/OnePoll.php

index b1d1646240ed3d59ac41d31bb9e3f45c987a947b..c299d2cd396448f230c1c5ab5d4bad745c644f8a 100644 (file)
@@ -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;
-
-}
index 959d28237468f86a9cda755758e6f68305942533..fbe92215d1d30646d93f782ced55a731b772df2e 100644 (file)
@@ -207,7 +207,7 @@ class OnePoll
                                                        continue;
                                                }
 
-                                               subscribe_to_hub($h, $importer, $contact, $hubmode);
+                                               self::subscribeToHub($h, $importer, $contact, $hubmode);
                                        }
                                }
                        }
@@ -704,4 +704,56 @@ class OnePoll
                Logger::log("Mail: closing connection for ".$mailconf['user']);
                imap_close($mbox);
        }
+
+
+       /**
+        * @param string $url
+        * @param array  $importer
+        * @param array  $contact
+        * @param string $hubmode
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        */
+       private static function subscribeToHub(string $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;
+
+       }
 }