]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
add autosubscribe
authorEvan Prodromou <evan@prodromou.name>
Sun, 20 Jul 2008 20:16:20 +0000 (16:16 -0400)
committerEvan Prodromou <evan@prodromou.name>
Sun, 20 Jul 2008 20:16:20 +0000 (16:16 -0400)
darcs-hash:20080720201620-84dde-f782e01bdf7f267b3b02e20e851aa7b643ed8590.gz

actions/subscribe.php
classes/User.php

index 45dffa62bc6e00612e71c5ba280aa448ebc4f6d4..f37095c1c649b98a9b587b4a88aaf6ef6a5214a2 100644 (file)
@@ -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)));
        }
index 36111ac0c33036475ed117e12831b3b38796e508..1866025620bededead0adf2084e948b067617fff 100644 (file)
@@ -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;
+       }
 }