]> git.mxchange.org Git - friendica.git/blobdiff - mod/pubsubhubbub.php
Ops, one more left ...
[friendica.git] / mod / pubsubhubbub.php
index 1abf3fbe2b0da7fceb8daebaeae139df9d82b6f4..8f9478d8aa51d0a322e6299156cca5968b9751b3 100644 (file)
@@ -3,8 +3,8 @@
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
-use Friendica\Database\DBM;
-use Friendica\Util\DateTimeFormat;
+use Friendica\Database\DBA;
+use Friendica\Model\PushSubscriber;
 use Friendica\Util\Network;
 
 function post_var($name) {
@@ -63,8 +63,8 @@ function pubsubhubbub_init(App $a) {
 
                // fetch user from database given the nickname
                $condition = ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false];
-               $owner = dba::selectFirst('user', ['uid', 'hidewall'], $condition);
-               if (!DBM::is_result($owner)) {
+               $owner = DBA::selectFirst('user', ['uid', 'hidewall'], $condition);
+               if (!DBA::isResult($owner)) {
                        logger('Local account not found: ' . $nick . ' - topic: ' . $hub_topic . ' - callback: ' . $hub_callback);
                        System::httpExit(404);
                }
@@ -78,8 +78,8 @@ function pubsubhubbub_init(App $a) {
                // get corresponding row from contact table
                $condition = ['uid' => $owner['uid'], 'blocked' => false,
                        'pending' => false, 'self' => true];
-               $contact = dba::selectFirst('contact', ['poll'], $condition);
-               if (!DBM::is_result($contact)) {
+               $contact = DBA::selectFirst('contact', ['poll'], $condition);
+               if (!DBA::isResult($contact)) {
                        logger('Self contact for user ' . $owner['uid'] . ' not found.');
                        System::httpExit(404);
                }
@@ -120,35 +120,8 @@ function pubsubhubbub_init(App $a) {
                        System::httpExit(404);
                }
 
-               // fetch the old subscription if it exists
-               $subscriber = dba::selectFirst('push_subscriber', ['last_update', 'push'], ['callback_url' => $hub_callback]);
+               PushSubscriber::renew($owner['uid'], $nick, $subscribe, $hub_callback, $hub_topic, $hub_secret);
 
-               // delete old subscription if it exists
-               dba::delete('push_subscriber', ['callback_url' => $hub_callback]);
-
-               if ($subscribe) {
-                       $last_update = DateTimeFormat::utcNow();
-                       $push_flag = 0;
-
-                       // if we are just updating an old subscription, keep the
-                       // old values for last_update but reset the push
-                       if (DBM::is_result($subscriber)) {
-                               $last_update = $subscriber['last_update'];
-                               $push_flag = min($subscriber['push'], 1);
-                       }
-
-                       // subscribe means adding the row to the table
-                       $fields = ['uid' => $owner['uid'], 'callback_url' => $hub_callback,
-                               'topic' => $hub_topic, 'nickname' => $nick, 'push' => $push_flag,
-                               'last_update' => $last_update, 'renewed' => DateTimeFormat::utcNow(),
-                               'secret' => $hub_secret];
-                       dba::insert('push_subscriber', $fields);
-
-                       logger("Successfully subscribed [$hub_callback].");
-               } else {
-                       logger("Successfully unsubscribed [$hub_callback].");
-                       // we do nothing here, since the row was already deleted
-               }
                System::httpExit(202);
        }
        killme();