summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/subscribe.php18
-rw-r--r--classes/User.php14
2 files changed, 24 insertions, 8 deletions
diff --git a/actions/subscribe.php b/actions/subscribe.php
index 45dffa62b..f37095c1c 100644
--- a/actions/subscribe.php
+++ b/actions/subscribe.php
@@ -49,19 +49,21 @@ class SubscribeAction extends Action {
return;
}
- $sub = new Subscription();
- $sub->subscriber = $user->id;
- $sub->subscribed = $other->id;
-
- $sub->created = DB_DataObject_Cast::dateTime(); # current time
-
- if (!$sub->insert()) {
- common_server_error(_('Couldn\'t create subscription.'));
+ if (!$user->subscribeTo($other)) {
+ $this->server_error(_('Could not subscribe.'));
return;
}
$this->notify($other, $user);
+ if ($other->autosubscribe && !$other->isSubscribed($user)) {
+ if (!$other->subscribeTo($user)) {
+ $this->server_error(_('Could not subscribe other to you.'));
+ return;
+ }
+ $this->notify($user, $other);
+ }
+
common_redirect(common_local_url('subscriptions', array('nickname' =>
$user->nickname)));
}
diff --git a/classes/User.php b/classes/User.php
index 36111ac0c..186602562 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -112,4 +112,18 @@ class User extends DB_DataObject
function getCarrier() {
return Sms_carrier::staticGet($this->carrier);
}
+
+ function subscribeTo($other) {
+ $sub = new Subscription();
+ $sub->subscriber = $this->id;
+ $sub->subscribed = $other->id;
+
+ $sub->created = DB_DataObject_Cast::dateTime(); # current time
+
+ if (!$sub->insert()) {
+ return false;
+ }
+
+ return $true;
+ }
}