return;
}
- $result = subs_subscribe_to($this->user, $this->other);
-
- if (is_string($result)) {
- $this->clientError($result, 403, $this->format);
- return;
+ try {
+ Subscription::start($this->user->getProfile(), $this->other);
+ } catch (Exception $e) {
+ $this->clientError($e->getMessage(), 403, $this->format);
}
$this->initDocument($this->format);
* 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 Action
foreach ($addresses as $email) {
$email = common_canonical_email($email);
- $other = User::getKV('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::start($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);
}
return;
}
- $user = common_current_user();
-
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
common_redirect(common_local_url('subscriptions',
- array('nickname' => $user->nickname)));
+ array('nickname' => $this->scoped->nickname)));
return;
}
$other = Profile::getKV('id', $other_id);
- if (!$other) {
+ if (!($other instanceof Profile)) {
// TRANS: Client error displayed when trying to unsubscribe while providing a non-existing profile ID.
$this->clientError(_('No profile with that ID.'));
return;
}
- $result = subs_unsubscribe_to($user, $other);
-
- if (is_string($result)) {
- $this->clientError($result);
- return;
+ try {
+ Subscription::cancel($this->scoped, $other);
+ } catch (Exception $e) {
+ $this->clientError($e->getMessage());
}
if ($this->boolean('ajax')) {
$this->elementEnd('html');
} else {
common_redirect(common_local_url('subscriptions',
- array('nickname' => $user->nickname)),
+ array('nickname' => $this->scoped->nickname)),
303);
}
}
return User::getKV($this->user_id);
}
+ function getProfile()
+ {
+ return Profile::getKV('id', $this->user_id);
+ }
+
// Make sure we only ever delete one record at a time
function safeDelete()
{
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ public static function getByEmail($email)
+ {
+ // in the future, profiles should have emails stored...
+ $user = User::getKV('email', $email);
+ if (!($user instanceof User)) {
+ throw new NoSuchUserException(array('email'=>$email));
+ }
+ return $user->getProfile();
+ }
+
protected $_user = -1; // Uninitialized value distinct from null
public function getUser()
if ($invites->find()) {
while ($invites->fetch()) {
- $other = User::getKV($invites->user_id);
- subs_subscribe_to($other, $this);
+ try {
+ $other = Profile::getKV('id', $invites->user_id);
+ if (!($other instanceof Profile)) { // remove when getKV throws exceptions
+ continue;
+ }
+ Subscription::start($other, $this->getProfile());
+ } catch (Exception $e) {
+ continue;
+ }
}
}
}
require_once INSTALLDIR.'/lib/util.php';
require_once INSTALLDIR.'/lib/action.php';
require_once INSTALLDIR.'/lib/mail.php';
-require_once INSTALLDIR.'/lib/subs.php';
require_once INSTALLDIR.'/lib/clientexception.php';
require_once INSTALLDIR.'/lib/serverexception.php';
+++ /dev/null
-<?php
-/*
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-/* Subscribe user $user to other user $other.
- * Note: $other must be a local user, not a remote profile.
- * Because the other way is quite a bit more complicated.
- */
-
-function subs_subscribe_to($user, $other)
-{
- if (is_a($other, 'User')) {
- $other = $other->getProfile();
- }
- try {
- Subscription::start($user->getProfile(), $other);
- return true;
- } catch (Exception $e) {
- return $e->getMessage();
- }
-}
-
-function subs_unsubscribe_to($user, $other)
-{
- if (is_a($other, 'User')) {
- $other = $other->getProfile();
- }
- try {
- Subscription::cancel($user->getProfile(), $other);
- return true;
- } catch (Exception $e) {
- return $e->getMessage();
- }
-}
return false;
}
- $user = $flink->getUser();
+ $profile = $flink->getProfile();
foreach ($friends as $friend) {
// Get associated user and subscribe her
- $friend_user = User::getKV('id', $friend_flink->user_id);
+ $friend_profile = Profile::getKV('id', $friend_flink->user_id);
- if (!empty($friend_user)) {
- $result = subs_subscribe_to($user, $friend_user);
-
- if ($result === true) {
+ if ($friend_profile instanceof Profile) {
+ try {
+ $other = Profile::getKV('id', $invites->user_id);
+ Subscription::start($profile, $friend_profile);
common_log(LOG_INFO,
$this->name() . ' - Subscribed ' .
- "$friend_user->nickname to $user->nickname.");
- } else {
+ "{$friend_profile->nickname} to {$profile->nickname}.");
+ } catch (Exception $e) {
common_debug($this->name() .
- ' - Tried subscribing ' .
- "$friend_user->nickname to $user->nickname - " .
- $result);
+ ' - Tried and failed subscribing ' .
+ "{$friend_profile->nickname} to {$profile->nickname} - " .
+ $e->getMessage());
}
}
}
$to = User::getKV('nickname', $tunic);
- if (empty($to)) {
+ if (!($to instanceof User)) {
throw new Exception("Can't find user '$tunic'.");
}
- subs_subscribe_to($from, $to);
+ Subscription::start($from->getProfile(), $to->getProfile());
$from->free();
$to->free();