]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Add lose <nickname> command to the command interpreter
authorCraig Andrews <candrews@integralblue.com>
Tue, 23 Feb 2010 03:57:16 +0000 (22:57 -0500)
committerCraig Andrews <candrews@integralblue.com>
Tue, 23 Feb 2010 04:09:14 +0000 (23:09 -0500)
lib/command.php
lib/commandinterpreter.php
lib/subs.php

index ea7b60372d96542dd134069d7a94b67b4d40756c..db8e8003041f0d2cdfc35cc10d8a259b42364e7a 100644 (file)
@@ -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 <nickname> <text> - direct message to user\n".
                            "get <nickname> - get last notice from user\n".
                            "whois <nickname> - get profile info on user\n".
+                           "lose <nickname> - force user to stop following you\n".
                            "fav <nickname> - add user's last notice as a 'fave'\n".
                            "fav #<notice_id> - add notice with the given id as a 'fave'\n".
                            "repeat #<notice_id> - repeat a notice with a given id\n".
index c2add7299e7330287303374944d912caa753dc09..fbc6174bbfab1b95a2d9573df2043e3688cf9a0f 100644 (file)
@@ -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;
index 1c240c475d40c7f71fd428de44eec07499dc3baa..e2ce0667eb19f78e3c2e9f5aed9fb0fdcc76df47 100644 (file)
@@ -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();
+    }
+   }
+}
+