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) {
// 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);
}
// 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);
}
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();