From b0a75a2ab24673452674a8f296ca4dbb110bed6b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 19 Feb 2010 08:31:20 -0500 Subject: replace calls to subs_(un)subscribe_user with Subscription methods --- lib/command.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'lib/command.php') diff --git a/lib/command.php b/lib/command.php index 2a51fd687..ea7b60372 100644 --- a/lib/command.php +++ b/lib/command.php @@ -548,12 +548,19 @@ class SubCommand extends Command return; } - $result = subs_subscribe_user($this->user, $this->other); + $otherUser = User::staticGet('nickname', $this->other); - if ($result == 'true') { + if (empty($otherUser)) { + $channel->error($this->user, _('No such user')); + return; + } + + try { + Subscription::start($this->user->getProfile(), + $otherUser->getProfile()); $channel->output($this->user, sprintf(_('Subscribed to %s'), $this->other)); - } else { - $channel->error($this->user, $result); + } catch (Exception $e) { + $channel->error($this->user, $e->getMessage()); } } } @@ -576,12 +583,18 @@ class UnsubCommand extends Command return; } - $result=subs_unsubscribe_user($this->user, $this->other); + $otherUser = User::staticGet('nickname', $this->other); - if ($result) { + if (empty($otherUser)) { + $channel->error($this->user, _('No such user')); + } + + try { + Subscription::cancel($this->user->getProfile(), + $otherUser->getProfile()); $channel->output($this->user, sprintf(_('Unsubscribed from %s'), $this->other)); - } else { - $channel->error($this->user, $result); + } catch (Exception $e) { + $channel->error($this->user, $e->getMessage()); } } } -- cgit v1.2.3-54-g00ecf From f0d1d07b94fbd2fe0ecd1c2f18d831a177d11c5c Mon Sep 17 00:00:00 2001 From: Craig Andrews Date: Mon, 22 Feb 2010 22:57:16 -0500 Subject: Add lose command to the command interpreter --- lib/command.php | 29 +++++++++++++++++++++++++++++ lib/commandinterpreter.php | 11 +++++++++++ lib/subs.php | 45 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) (limited to 'lib/command.php') diff --git a/lib/command.php b/lib/command.php index ea7b60372..db8e80030 100644 --- a/lib/command.php +++ b/lib/command.php @@ -668,6 +668,34 @@ class LoginCommand extends Command } } +class LoseCommand extends Command +{ + + var $other = null; + + function __construct($user, $other) + { + parent::__construct($user); + $this->other = $other; + } + + function execute($channel) + { + if(!$this->other) { + $channel->error($this->user, _('Specify the name of the user to unsubscribe from')); + return; + } + + $result=subs_unsubscribe_from($this->user, $this->other); + + if ($result) { + $channel->output($this->user, sprintf(_('Unsubscribed %s'), $this->other)); + } else { + $channel->error($this->user, $result); + } + } +} + class SubscriptionsCommand extends Command { function execute($channel) @@ -750,6 +778,7 @@ class HelpCommand extends Command "d - direct message to user\n". "get - get last notice from user\n". "whois - get profile info on user\n". + "lose - force user to stop following you\n". "fav - add user's last notice as a 'fave'\n". "fav # - add notice with the given id as a 'fave'\n". "repeat # - repeat a notice with a given id\n". diff --git a/lib/commandinterpreter.php b/lib/commandinterpreter.php index c2add7299..fbc6174bb 100644 --- a/lib/commandinterpreter.php +++ b/lib/commandinterpreter.php @@ -47,6 +47,17 @@ class CommandInterpreter } else { return new LoginCommand($user); } + case 'lose': + if ($arg) { + list($other, $extra) = $this->split_arg($arg); + if ($extra) { + return null; + } else { + return new LoseCommand($user, $other); + } + } else { + return null; + } case 'subscribers': if ($arg) { return null; diff --git a/lib/subs.php b/lib/subs.php index 1c240c475..e2ce0667e 100644 --- a/lib/subs.php +++ b/lib/subs.php @@ -42,4 +42,47 @@ function subs_unsubscribe_to($user, $other) } catch (Exception $e) { return $e->getMessage(); } -} \ No newline at end of file +} + +function subs_unsubscribe_from($user, $other){ + $local = User::staticGet("nickname",$other); + if($local){ + return subs_unsubscribe_to($local,$user); + } else { + try { + $remote = Profile::staticGet("nickname",$other); + if(is_string($remote)){ + return $remote; + } + if (Event::handle('StartUnsubscribe', array($remote,$user))) { + + $sub = DB_DataObject::factory('subscription'); + + $sub->subscriber = $remote->id; + $sub->subscribed = $user->id; + + $sub->find(true); + + // note we checked for existence above + + if (!$sub->delete()) + return _('Couldn\'t delete subscription.'); + + $cache = common_memcache(); + + if ($cache) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $remote->id)); + } + + + $user->blowSubscribersCount(); + $remote->blowSubscribersCount(); + + Event::handle('EndUnsubscribe', array($remote, $user)); + } + } catch (Exception $e) { + return $e->getMessage(); + } + } +} + -- cgit v1.2.3-54-g00ecf