]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newnotice.php
Merge branch 'fix-author-fallback' into 'nightly'
[quix0rs-gnu-social.git] / actions / newnotice.php
index c4b6bfa554a9c604af56c04cc10f66c469165cd9..6ee209206110ccbfcca611837a08e2e2f82aee1b 100644 (file)
@@ -95,13 +95,28 @@ class NewnoticeAction extends FormAction
     {
         assert($this->scoped instanceof Profile); // XXX: maybe an error instead...
         $user = $this->scoped->getUser();
-        $content = $this->trimmed('status_textarea');
+        $content = $this->formOpts['content'];
         $options = array('source' => 'web');
         Event::handle('StartSaveNewNoticeWeb', array($this, $user, &$content, &$options));
 
-        if (empty($content)) {
-            // TRANS: Client error displayed trying to send a notice without content.
-            $this->clientError(_('No content!'));
+        $upload = null;
+        try {
+            // throws exception on failure
+            $upload = MediaFile::fromUpload('attach', $this->scoped);
+            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
+                $content .= ($content==='' ? '' : ' ') . $upload->shortUrl();
+            }
+            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
+
+            // We could check content length here if the URL was added, but I'll just let it slide for now...
+
+            $act->enclosures[] = $upload->getEnclosure();
+        } catch (NoUploadedMediaException $e) {
+            // simply no attached media to the new notice
+            if (empty($content)) {
+                // TRANS: Client error displayed trying to send a notice without content.
+                $this->clientError(_('No content!'));
+            }
         }
 
         $inter = new CommandInterpreter();
@@ -129,10 +144,8 @@ class NewnoticeAction extends FormAction
         $act->time = time();
         $act->actor = $this->scoped->asActivityObject();
 
-        $content = $this->scoped->shortenLinks($content);
-
         // Reject notice if it is too long (without the HTML)
-        // Should we do this before or after the upload attachment link? I think before...
+        // This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction
         if (Notice::contentTooLong($content)) {
             // TRANS: Client error displayed when the parameter "status" is missing.
             // TRANS: %d is the maximum number of character for a notice.
@@ -142,29 +155,6 @@ class NewnoticeAction extends FormAction
                                               Notice::maxContent()));
         }
 
-        $upload = null;
-        try {
-            // throws exception on failure
-            $upload = MediaFile::fromUpload('attach', $this->scoped);
-            if (Event::handle('StartSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options))) {
-                $content .= ' ' . $upload->shortUrl();
-            }
-            Event::handle('EndSaveNewNoticeAppendAttachment', array($this, $upload, &$content, &$options));
-
-            // We could check content length here if the URL was added, but I'll just let it slide for now...
-
-            $act->enclosures[] = $upload->getEnclosure();
-        } catch (NoUploadedMediaException $e) {
-            // simply no attached media to the new notice
-        }
-
-        $actobj = new ActivityObject();
-        $actobj->type = ActivityObject::NOTE;
-        $actobj->content = common_render_content($content, $this->scoped, $parent);
-
-        $act->objects[] = $actobj;
-
-
         $act->context = new ActivityContext();
 
         if ($parent instanceof Notice) {
@@ -191,15 +181,24 @@ class NewnoticeAction extends FormAction
             $act->context->location = Location::fromOptions($locOptions);
         }
 
-        $author_id = $this->scoped->id;
-        $text      = $content;
+        $content = $this->scoped->shortenLinks($content);
 
-        // Does the heavy-lifting for getting "To:" information
+        // FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject!
+        if (Event::handle('StartNoticeSaveWeb', array($this, $this->scoped, &$content, &$options))) {
 
-        ToSelector::fillOptions($this, $options);
+            // FIXME: We should be able to get the attentions from common_render_content!
+            // and maybe even directly save whether they're local or not!
+            $act->context->attention = common_get_attentions($content, $this->scoped, $parent);
 
-        // FIXME: Make sure NoticeTitle plugin gets a change to add the title to our activityobject!
-        if (Event::handle('StartNoticeSaveWeb', array($this, &$author_id, &$text, &$options))) {
+            // $options gets filled with possible scoping settings
+            ToSelector::fillActivity($this, $act, $options);
+
+            $actobj = new ActivityObject();
+            $actobj->type = ActivityObject::NOTE;
+            $actobj->content = common_render_content($content, $this->scoped, $parent);
+
+            // Finally add the activity object to our activity
+            $act->objects[] = $actobj;
 
             $this->stored = Notice::saveActivity($act, $this->scoped, $options);