]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Let users join and drop group membership from xmpp
authorCarlos Perilla <deepspawn@valkertown.org>
Wed, 12 Aug 2009 00:09:51 +0000 (19:09 -0500)
committerCraig Andrews <candrews@integralblue.com>
Tue, 1 Sep 2009 21:52:08 +0000 (17:52 -0400)
lib/command.php
lib/commandinterpreter.php

index 91a20b81092922abc8769df91b274ff95271dc3f..01b14f83e7a367cbe2a9ab8544a690e7a111f783 100644 (file)
@@ -114,7 +114,6 @@ class StatsCommand extends Command
 
 class FavCommand extends Command
 {
-
     var $other = null;
 
     function __construct($user, $other)
@@ -158,6 +157,108 @@ class FavCommand extends Command
 
         $channel->output($this->user, _('Notice marked as fave.'));
     }
+
+}
+class JoinCommand extends Command
+{
+    var $other = null;
+
+    function __construct($user, $other)
+    {
+        parent::__construct($user);
+        $this->other = $other;
+    }
+
+    function execute($channel)
+    {
+
+        $nickname = common_canonical_nickname($this->other);
+        $group    = User_group::staticGet('nickname', $nickname);
+        $cur      = $this->user;
+
+        if (!$group) {
+            $channel->error($cur, _('No such group.'));
+            return;
+        }
+
+        if ($cur->isMember($group)) {
+            $channel->error($cur, _('You are already a member of that group'));
+            return;
+        }
+        if (Group_block::isBlocked($group, $cur->getProfile())) {
+          $channel->error($cur, _('You have been blocked from that group by the admin.'));
+            return;
+        }
+
+        $member = new Group_member();
+
+        $member->group_id   = $group->id;
+        $member->profile_id = $cur->id;
+        $member->created    = common_sql_now();
+
+        $result = $member->insert();
+        if (!$result) {
+          common_log_db_error($member, 'INSERT', __FILE__);
+          $channel->error($cur, sprintf(_('Could not join user %s to group %s'),
+                                       $cur->nickname, $group->nickname));
+          return;
+        }
+
+        $channel->output($cur, sprintf(_('%s joined group %s'),
+                                              $cur->nickname,
+                                              $group->nickname));
+    }
+
+}
+class DropCommand extends Command
+{
+    var $other = null;
+
+    function __construct($user, $other)
+    {
+        parent::__construct($user);
+        $this->other = $other;
+    }
+
+    function execute($channel)
+    {
+
+        $nickname = common_canonical_nickname($this->other);
+        $group    = User_group::staticGet('nickname', $nickname);
+        $cur      = $this->user;
+
+        if (!$group) {
+            $channel->error($cur, _('No such group.'));
+            return;
+        }
+
+        if (!$cur->isMember($group)) {
+            $channel->error($cur, _('You are not a member of that group.'));
+            return;
+        }
+
+        $member = new Group_member();
+
+        $member->group_id   = $group->id;
+        $member->profile_id = $cur->id;
+
+        if (!$member->find(true)) {
+          $channel->error($cur,_('Could not find membership record.'));
+          return;
+        }
+        $result = $member->delete();
+        if (!$result) {
+          common_log_db_error($member, 'INSERT', __FILE__);
+          $channel->error($cur, sprintf(_('Could not remove user %s to group %s'),
+                                       $cur->nickname, $group->nickname));
+          return;
+        }
+
+        $channel->output($cur, sprintf(_('%s left group %s'),
+                                              $cur->nickname,
+                                              $group->nickname));
+    }
+
 }
 
 class WhoisCommand extends Command
@@ -392,6 +493,8 @@ class HelpCommand extends Command
                            "get <nickname> - get last notice from user\n".
                            "whois <nickname> - get profile info on user\n".
                            "fav <nickname> - add user's last notice as a 'fave'\n".
+                           "join <group> - join group\n".
+                           "drop <group> - leave group\n".
                            "stats - get your stats\n".
                            "stop - same as 'off'\n".
                            "quit - same as 'off'\n".
index ac6bf73c8e6a0a816f363415fa8d24b1e1c7a16e..6e4340e5dcac05529218c6246b2aff02e35a62fa 100644 (file)
@@ -70,6 +70,26 @@ class CommandInterpreter
             } else {
                 return new OffCommand($user);
             }
+         case 'join':
+             if (!$arg) {
+                return null;
+            }
+            list($other, $extra) = explode(' ', $arg, 2);
+            if ($extra) {
+                return null;
+            } else {
+                return new JoinCommand($user, $other);
+            }
+         case 'drop':
+            if (!$arg) {
+                return null;
+            }
+            list($other, $extra) = explode(' ', $arg, 2);
+            if ($extra) {
+                return null;
+            } else {
+                return new DropCommand($user, $other);
+            }
          case 'follow':
          case 'sub':
             if (!$arg) {