From: Hannes Mannerheim Date: Mon, 20 Oct 2014 14:17:40 +0000 (+0200) Subject: do favorites from default like in API X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e3bb5e1df955fe5d8e1e559620cbcb8329fc3a60;p=quix0rs-gnu-social.git do favorites from default like in API not quite sure about this, but the deleted code in this commit created activity notices that we couldn't turn off in config. --- diff --git a/plugins/Favorite/actions/favor.php b/plugins/Favorite/actions/favor.php index 5b73ae20bf..37668c989c 100644 --- a/plugins/Favorite/actions/favor.php +++ b/plugins/Favorite/actions/favor.php @@ -74,28 +74,13 @@ class FavorAction extends FormAction throw new AlreadyFulfilledException(_('You have already favorited this!')); } - $now = common_sql_now(); + $fave = Fave::addNew($this->scoped, $this->target); - $act = new Activity(); - $act->id = Fave::newUri($this->scoped, $this->target, $now); - $act->type = Fave::getObjectType(); - $act->actor = $this->scoped->asActivityObject(); - $act->target = $this->target->asActivityObject(); - $act->objects = array(clone($act->target)); - $act->verb = ActivityVerb::FAVORITE; - $act->title = ActivityUtils::verbToTitle($act->verb); - $act->time = strtotime($now); - // TRANS: Notification given when a user marks a notice as favorite. - // TRANS: %1$s is a user name or full name, %2$s is a notice URI, %3$s the link to the user's profile. - $act->content = sprintf(_('%1$s marked notice %2$s as a favorite.'), - htmlspecialchars($this->scoped->getBestName()), - htmlspecialchars($this->target->getUrl()), - htmlspecialchars($this->scoped->getUrl())); - - - $stored = Notice::saveActivity($act, $this->scoped, - array('uri'=>$act->id)); + if (empty($fave)) { + $this->serverError(_('Could not create favorite.')); + } + $this->notify($fave, $this->target, $this->scoped); Fave::blowCacheForProfileId($this->scoped->id); return _('Favorited the notice'); @@ -108,4 +93,25 @@ class FavorAction extends FormAction $disfavor->show(); } } + + /** + * Notify the author of the favorite that the user likes their notice + * + * @param Favorite $fave the favorite in question + * @param Notice $notice the notice that's been faved + * @param User $user the user doing the favoriting + * + * @return void + */ + function notify($fave, $notice, $user) + { + $other = User::getKV('id', $notice->profile_id); + if ($other && $other->id != $user->id && !empty($other->email)) { + require_once INSTALLDIR.'/lib/mail.php'; + + mail_notify_fave($other, $user->getProfile(), $notice); + // XXX: notify by IM + // XXX: notify by SMS + } + } }