summaryrefslogtreecommitdiff
path: root/plugins/OStatus/actions
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-02-12 01:11:46 +0000
committerBrion Vibber <brion@pobox.com>2010-02-12 01:11:46 +0000
commitbc46621af2bea8d2f9f132f275c70c5964f880b4 (patch)
treeebba5ae7894699986afb81e00b300e9427753de0 /plugins/OStatus/actions
parent525358fa101784fa5bbbac8b214091de89ec0634 (diff)
OStatus sub setup code cleanup and partial group fixes (needs more work after the Atom updates are done)
Diffstat (limited to 'plugins/OStatus/actions')
-rw-r--r--plugins/OStatus/actions/feedsubsettings.php15
-rw-r--r--plugins/OStatus/actions/pushcallback.php27
2 files changed, 20 insertions, 22 deletions
diff --git a/plugins/OStatus/actions/feedsubsettings.php b/plugins/OStatus/actions/feedsubsettings.php
index af8bf4d25..6933c9bf2 100644
--- a/plugins/OStatus/actions/feedsubsettings.php
+++ b/plugins/OStatus/actions/feedsubsettings.php
@@ -197,6 +197,9 @@ class FeedSubSettingsAction extends ConnectSettingsAction
if ($this->validateFeed()) {
$this->preview = true;
$this->profile = Ostatus_profile::ensureProfile($this->munger);
+ if (!$this->profile) {
+ throw new ServerException("Feed profile was not saved properly.");
+ }
// If not already in use, subscribe to updates via the hub
if ($this->profile->sub_start) {
@@ -212,13 +215,10 @@ class FeedSubSettingsAction extends ConnectSettingsAction
// And subscribe the current user to the local profile
$user = common_current_user();
- $profile = $this->profile->getLocalProfile();
- if (!$profile) {
- throw new ServerException("Feed profile was not saved properly.");
- }
if ($this->profile->isGroup()) {
- if ($user->isMember($profile)) {
+ $group = $this->profile->localGroup();
+ if ($user->isMember($group)) {
$this->showForm(_m('Already a member!'));
} elseif (Group_member::join($this->profile->group_id, $user->id)) {
$this->showForm(_m('Joined remote group!'));
@@ -226,9 +226,10 @@ class FeedSubSettingsAction extends ConnectSettingsAction
$this->showForm(_m('Remote group join failed!'));
}
} else {
- if ($user->isSubscribed($profile)) {
+ $local = $this->profile->localProfile();
+ if ($user->isSubscribed($local)) {
$this->showForm(_m('Already subscribed!'));
- } elseif ($user->subscribeTo($profile)) {
+ } elseif ($user->subscribeTo($local)) {
$this->showForm(_m('Feed subscribed!'));
} else {
$this->showForm(_m('Feed subscription failed!'));
diff --git a/plugins/OStatus/actions/pushcallback.php b/plugins/OStatus/actions/pushcallback.php
index a446593ff..2601a377a 100644
--- a/plugins/OStatus/actions/pushcallback.php
+++ b/plugins/OStatus/actions/pushcallback.php
@@ -84,27 +84,24 @@ class PushCallbackAction extends Action
throw new ServerException("Bogus hub callback: unknown feed", 404);
}
- # Can't currently set the token in our sub api
- #if ($feedinfo->verify_token !== $verify_token) {
- # common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
- # throw new ServerError("Bogus hub callback: bad token", 404);
- #}
-
+ if ($profile->verify_token !== $verify_token) {
+ common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad token \"$verify_token\" for feed $topic");
+ throw new ServerError("Bogus hub callback: bad token", 404);
+ }
+
+ if ($mode != $profile->sub_state) {
+ common_log(LOG_WARNING, __METHOD__ . ": bogus hub callback with bad mode \"$mode\" for feed $topic in state \"{$profile->sub_state}\"");
+ throw new ServerException("Bogus hub callback: mode doesn't match subscription state.", 404);
+ }
+
// OK!
if ($mode == 'subscribe') {
common_log(LOG_INFO, __METHOD__ . ': sub confirmed');
- $profile->sub_start = common_sql_date(time());
- if ($lease_seconds > 0) {
- $profile->sub_end = common_sql_date(time() + $lease_seconds);
- } else {
- $profile->sub_end = null;
- }
- $profile->update();
+ $profile->confirmSubscribe($lease_seconds);
} else {
common_log(LOG_INFO, __METHOD__ . ": unsub confirmed; deleting sub record for $topic");
- $profile->delete();
+ $profile->confirmUnsubscribe();
}
-
print $challenge;
}
}