]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/DirectMessage/DirectMessagePlugin.php
UAS protected property user solved with getUser()
[quix0rs-gnu-social.git] / plugins / DirectMessage / DirectMessagePlugin.php
index 1e717833adb53856fb77ccfe6e07fb83881278c3..6be9fb508312caf4f8a5e37527013c042acc239b 100644 (file)
@@ -55,6 +55,62 @@ 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'));
+        }
+        $objs[] = $messages;
+
+        // 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'));
+        }
+        $objs[] = $messages;
+
+        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