]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/invite.php
DocAction now extends ManagedAction
[quix0rs-gnu-social.git] / actions / invite.php
index 1bfc9f76d31b5da30a3b20b0969443ee473e1768..89b7e83bf6d19a32899e05db5fe2b32ac1439cb3 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 // @todo XXX: Add documentation.
-class InviteAction extends CurrentUserDesignAction
+class InviteAction extends Action
 {
     var $mode = null;
     var $error = null;
@@ -111,15 +111,22 @@ class InviteAction extends CurrentUserDesignAction
 
             foreach ($addresses as $email) {
                 $email = common_canonical_email($email);
-                $other = User::staticGet('email', $email);
-                if ($other) {
+                try {
+                    // If this user is already registered, subscribe to it!
+                    $other = Profile::getByEmail($email);
                     if ($user->isSubscribed($other)) {
                         $this->already[] = $other;
                     } else {
-                        subs_subscribe_to($user, $other);
-                        $this->subbed[] = $other;
+                        try {
+                            Subscription::ensureStart($profile, $other);
+                            $this->subbed[] = $other;
+                        } catch (Exception $e) {
+                            // subscription failed, but keep working
+                            common_debug('Invitation-based subscription failed: '.$e->getMessage());
+                        }
                     }
-                } else {
+                } catch (NoSuchUserException $e) {
+                    // If email was not known, let's send an invite!
                     $this->sent[] = $email;
                     $this->sendInvitation($email, $user, $personal);
                 }