]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/DirectMessage/DirectMessagePlugin.php
Merge branch 'master' into social-master
[quix0rs-gnu-social.git] / plugins / DirectMessage / DirectMessagePlugin.php
index 1e717833adb53856fb77ccfe6e07fb83881278c3..34533ba9e82cf5406c960aeb484168ca60d91c2e 100644 (file)
@@ -55,6 +55,66 @@ class DirectMessagePlugin extends Plugin
         return true;
     }
 
+    public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
+    {
+        // Messages _from_ the user
+        $msgMap = Message::listGet('from_profile', array($uas->getUser()->id));
+        $messages = $msgMap[$uas->getUser()->id];
+        if (!empty($uas->after)) {
+            $messages = array_filter($messages, array($uas, 'createdAfter'));
+        }
+        foreach ($messages as $message) {
+            $objs[] = clone($message);
+        }
+
+        // Messages _to_ the user
+        $msgMap = Message::listGet('to_profile', array($uas->getUser()->id));
+        $messages = $msgMap[$uas->getUser()->id];
+        if (!empty($uas->after)) {
+            $messages = array_filter($messages, array($uas, 'createdAfter'));
+        }
+        foreach ($messages as $message) {
+            $objs[] = clone($message);
+        }
+
+        return true;
+    }
+
+    /**
+     * Are we allowed to perform a certain command over the API?
+     */
+    public function onCommandSupportedAPI(Command $cmd, &$supported)
+    {
+        $supported = $supported || $cmd instanceof MessageCommand;
+        return true;
+    }
+
+    /**
+     * EndInterpretCommand will handle the 'd' and 'dm' commands.
+     *
+     * @param string  $cmd     Command being run
+     * @param string  $arg     Rest of the message (including address)
+     * @param User    $user    User sending the message
+     * @param Command &$result The resulting command object to be run.
+     *
+     * @return boolean hook value
+     */
+    public function onStartInterpretCommand($cmd, $arg, $user, &$result)
+    {
+        $dm_cmds = array('d', 'dm');
+
+        if ($result === false && in_array($cmd, $dm_cmds)) {
+            if (!empty($arg)) {
+                list($other, $extra) = CommandInterpreter::split_arg($arg);
+                if (!empty($extra)) {
+                    $result = new MessageCommand($user, $other, $extra);
+                }
+            }
+            return false;
+        }
+        return true;
+    }
+
     public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
     {
         if ($scoped instanceof Profile && $scoped->id == $target->id
@@ -89,7 +149,7 @@ class DirectMessagePlugin extends Plugin
         return true;
     }
 
-    public function onProfileDeleteRelated(Profile $profile, &$related)
+    public function onProfileDeleteRelated(Profile $profile, array &$related)
     {
         $msg = new Message();
         $msg->from_profile = $profile->id;