]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added a new "reply" command
authorCraig Andrews <candrews@integralblue.com>
Wed, 28 Oct 2009 02:30:21 +0000 (22:30 -0400)
committerCraig Andrews <candrews@integralblue.com>
Wed, 28 Oct 2009 02:30:21 +0000 (22:30 -0400)
lib/command.php
lib/commandinterpreter.php

index 6ece01b9670383f8c88d13d0a46e48b00d4f2827..d7ae11361105faad5cd3d9ce7bac6121e9931a87 100644 (file)
@@ -125,7 +125,7 @@ class FavCommand extends Command
     function execute($channel)
     {
         if(substr($this->other,0,1)=='#'){
-            //replying to a specific notice_id
+            //favoriting a specific notice_id
 
             $notice = Notice::staticGet(substr($this->other,1));
             if (!$notice) {
@@ -134,7 +134,7 @@ class FavCommand extends Command
             }
             $recipient = $notice->getProfile();
         }else{
-            //replying to a given user's last notice
+            //favoriting a given user's last notice
 
             $recipient =
               common_relative_profile($this->user, common_canonical_nickname($this->other));
@@ -359,6 +359,71 @@ class MessageCommand extends Command
     }
 }
 
+class ReplyCommand extends Command
+{
+    var $other = null;
+    var $text = null;
+    function __construct($user, $other, $text)
+    {
+        parent::__construct($user);
+        $this->other = $other;
+        $this->text = $text;
+    }
+
+    function execute($channel)
+    {
+        if(substr($this->other,0,1)=='#'){
+            //replying to a specific notice_id
+
+            $notice = Notice::staticGet(substr($this->other,1));
+            if (!$notice) {
+                $channel->error($this->user, _('Notice with that id does not exist'));
+                return;
+            }
+            $recipient = $notice->getProfile();
+        }else{
+            //replying to a given user's last notice
+
+            $recipient =
+              common_relative_profile($this->user, common_canonical_nickname($this->other));
+
+            if (!$recipient) {
+                $channel->error($this->user, _('No such user.'));
+                return;
+            }
+            $notice = $recipient->getCurrentNotice();
+            if (!$notice) {
+                $channel->error($this->user, _('User has no last notice'));
+                return;
+            }
+        }
+
+        $len = mb_strlen($this->text);
+
+        if ($len == 0) {
+            $channel->error($this->user, _('No content!'));
+            return;
+        }
+
+        $this->text = common_shorten_links($this->text);
+
+        if (Notice::contentTooLong($this->text)) {
+            $channel->error($this->user, sprintf(_('Notice too long - maximum is %d characters, you sent %d'),
+                                                 Notice::maxContent(), mb_strlen($this->text)));
+            return;
+        }
+
+        $notice = Notice::saveNew($this->user->id, $this->text, $channel->source(), 1,
+                                  $notice->id);
+        if ($notice) {
+            $channel->output($this->user, sprintf(_('Reply to %s sent'), $recipient->nickname));
+        } else {
+            $channel->error($this->user, _('Error saving notice.'));
+        }
+        common_broadcast_notice($notice);
+    }
+}
+
 class GetCommand extends Command
 {
 
@@ -510,6 +575,8 @@ class HelpCommand extends Command
                            "whois <nickname> - get profile info on user\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".
+                           "reply #<notice_id> - reply to notice with a given id\n".
+                           "reply <nickname> - reply to the last notice from user\n".
                            "join <group> - join group\n".
                            "drop <group> - leave group\n".
                            "stats - get your stats\n".
index 60fc4c3c44802755af6e8bc1c6a5e4ea54bd92f1..b921a17cc25cedec84860fbd19cdd83f50defe1b 100644 (file)
@@ -134,6 +134,17 @@ class CommandInterpreter
             } else {
                 return new MessageCommand($user, $other, $extra);
             }
+         case 'r':
+         case 'reply':
+            if (!$arg) {
+                return null;
+            }
+            list($other, $extra) = $this->split_arg($arg);
+            if (!$extra) {
+                return null;
+            } else {
+                return new ReplyCommand($user, $other, $extra);
+            }
          case 'whois':
             if (!$arg) {
                 return null;