From c48871cf1b382d392b2b1759e70be23c305654f8 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 7 Jan 2016 23:24:15 +0100 Subject: [PATCH] Notice from web now saves context->attention too! ;) --- actions/newnotice.php | 27 ++++++++++------------- classes/Attention.php | 23 +++++++++++-------- plugins/NoticeTitle/NoticeTitlePlugin.php | 4 ++-- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/actions/newnotice.php b/actions/newnotice.php index 4a864b25c3..f874e6f9cb 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -145,8 +145,6 @@ class NewnoticeAction extends FormAction // simply no attached media to the new notice } - $content = $this->scoped->shortenLinks($content); - // Reject notice if it is too long (without the HTML) // This is done after MediaFile::fromUpload etc. just to act the same as the ApiStatusesUpdateAction if (Notice::contentTooLong($content)) { @@ -158,13 +156,6 @@ class NewnoticeAction extends FormAction Notice::maxContent())); } - $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 +182,21 @@ class NewnoticeAction extends FormAction $act->context->location = Location::fromOptions($locOptions); } - $author_id = $this->scoped->id; - $text = $content; + $content = $this->scoped->shortenLinks($content); + + // 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))) { - // Does the heavy-lifting for getting "To:" information + // 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_find_attentions($content, $this->scoped, $parent); - ToSelector::fillOptions($this, $options); + $actobj = new ActivityObject(); + $actobj->type = ActivityObject::NOTE; + $actobj->content = common_render_content($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))) { + // Finally add the activity object to our activity + $act->objects[] = $actobj; $this->stored = Notice::saveActivity($act, $this->scoped, $options); diff --git a/classes/Attention.php b/classes/Attention.php index c15a118e12..5299a095ae 100644 --- a/classes/Attention.php +++ b/classes/Attention.php @@ -49,18 +49,23 @@ class Attention extends Managed_DataObject ); } - public static function saveNew(Notice $notice, Profile $profile, $reason=null) + public static function saveNew(Notice $notice, Profile $target, $reason=null) { - $att = new Attention(); + try { + $att = Attention::getByKeys(['notice_id'=>$notice->getID(), 'profile_id'=>$target->getID()]); + throw new AlreadyFulfilledException('Attention already exists with reason: '.var_export($att->reason,true)); + } catch (NoResultException $e) { + $att = new Attention(); - $att->notice_id = $notice->getID(); - $att->profile_id = $profile->getID(); - $att->reason = $reason; - $att->created = common_sql_now(); - $result = $att->insert(); + $att->notice_id = $notice->getID(); + $att->profile_id = $target->getID(); + $att->reason = $reason; + $att->created = common_sql_now(); + $result = $att->insert(); - if ($result === false) { - throw new Exception('Could not saveNew in Attention'); + if ($result === false) { + throw new Exception('Failed Attention::saveNew for notice id=='.$notice->getID().' target id=='.$target->getID().', reason=="'.$reason.'"'); + } } return $att; } diff --git a/plugins/NoticeTitle/NoticeTitlePlugin.php b/plugins/NoticeTitle/NoticeTitlePlugin.php index 960cb935f7..22528d0b50 100644 --- a/plugins/NoticeTitle/NoticeTitlePlugin.php +++ b/plugins/NoticeTitle/NoticeTitlePlugin.php @@ -124,13 +124,13 @@ class NoticeTitlePlugin extends Plugin * Validate notice title before saving * * @param Action $action NewNoticeAction being executed - * @param integer &$authorId Author ID + * @param Profile $author Profile object for the author of the notice being saved * @param string &$text Text of the notice * @param array &$options Options array * * @return boolean hook value */ - function onStartNoticeSaveWeb($action, &$authorId, &$text, &$options) + function onStartNoticeSaveWeb(Action $action, Profile $author, &$content, &$options) { $title = $action->trimmed('notice_title'); if (!empty($title) && $this->isAllowedRichEdit()) { -- 2.39.5