X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FOStatus%2Factions%2Fpeopletagsalmon.php;h=46f4b0bdd848417af8c3db1eb2775bf6e1d1fbe9;hb=1e89540c3f52f95e9224d781c01b2c927d3c3f09;hp=19e56cb216a947b8a10eb4d7e6710200059e91c9;hpb=0dbdcf2936a00282114f1368ead2f5edebc6ae61;p=quix0rs-gnu-social.git diff --git a/plugins/OStatus/actions/peopletagsalmon.php b/plugins/OStatus/actions/peopletagsalmon.php index 19e56cb216..46f4b0bdd8 100644 --- a/plugins/OStatus/actions/peopletagsalmon.php +++ b/plugins/OStatus/actions/peopletagsalmon.php @@ -21,15 +21,13 @@ * @package OStatusPlugin */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } class PeopletagsalmonAction extends SalmonAction { var $peopletag = null; - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -40,16 +38,18 @@ class PeopletagsalmonAction extends SalmonAction $this->clientError(_m('No ID.')); } - $this->peopletag = Profile_list::staticGet('id', $id); + $this->peopletag = Profile_list::getKV('id', $id); - if (empty($this->peopletag)) { + if (!$this->peopletag instanceof Profile_list) { // TRANS: Client error displayed when referring to a non-existing list. $this->clientError(_m('No such list.')); } - $oprofile = Ostatus_profile::staticGet('peopletag_id', $id); + $this->target = $this->peopletag; + + $remote_list = Ostatus_profile::getKV('peopletag_id', $id); - if (!empty($oprofile)) { + if ($remote_list instanceof Ostatus_profile) { // TRANS: Client error displayed when trying to send a message to a remote list. $this->clientError(_m('Cannot accept remote posts for a remote list.')); } @@ -86,20 +86,13 @@ class PeopletagsalmonAction extends SalmonAction */ function handleSubscribe() { - $oprofile = $this->ensureProfile(); - if (!$oprofile) { - // TRANS: Client error displayed when referring to a non-existing remote list. - $this->clientError(_m('Cannot read profile to set up list subscription.')); - } - if ($oprofile->isGroup()) { + if ($this->oprofile->isGroup()) { // TRANS: Client error displayed when trying to subscribe a group to a list. $this->clientError(_m('Groups cannot subscribe to lists.')); } - common_log(LOG_INFO, "Remote profile {$oprofile->uri} subscribing to local peopletag ".$this->peopletag->getBestName()); - $profile = $oprofile->localProfile(); - - if ($this->peopletag->hasSubscriber($profile)) { + common_log(LOG_INFO, sprintf('Remote profile %s subscribing to local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName())); + if ($this->peopletag->hasSubscriber($this->actor)) { // Already a member; we'll take it silently to aid in resolving // inconsistencies on the other side. return true; @@ -109,42 +102,36 @@ class PeopletagsalmonAction extends SalmonAction // his own updates? try { - Profile_tag_subscription::add($this->peopletag, $profile); + Profile_tag_subscription::add($this->peopletag, $this->actor); } catch (Exception $e) { // TRANS: Server error displayed when subscribing a remote user to a list fails. // TRANS: %1$s is a profile URI, %2$s is a list name. $this->serverError(sprintf(_m('Could not subscribe remote user %1$s to list %2$s.'), - $oprofile->uri, $this->peopletag->getBestName())); + $this->oprofile->getUri(), $this->peopletag->getBestName())); } } /** * A remote user unsubscribed from our list. + * + * @return void + * @throws Exception through clientError and serverError */ function handleUnsubscribe() { - $oprofile = $this->ensureProfile(); - if (!$oprofile) { - // TRANS: Client error displayed when trying to unsubscribe from non-existing list. - $this->clientError(_m('Cannot read profile to cancel list subscription.')); - } - if ($oprofile->isGroup()) { + if ($this->oprofile->isGroup()) { // TRANS: Client error displayed when trying to unsubscribe a group from a list. $this->clientError(_m('Groups cannot subscribe to lists.')); } - common_log(LOG_INFO, "Remote profile {$oprofile->uri} unsubscribing from local peopletag ".$this->peopletag->getBestName()); - $profile = $oprofile->localProfile(); - + common_log(LOG_INFO, sprintf('Remote profile %s unsubscribing from local peopletag %s', $this->oprofile->getUri(), $this->peopletag->getBestName())); try { - Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $profile->id); - + Profile_tag_subscription::remove($this->peopletag->tagger, $this->peopletag->tag, $this->actor->id); } catch (Exception $e) { // TRANS: Client error displayed when trying to unsubscribe a remote user from a list fails. // TRANS: %1$s is a profile URL, %2$s is a list name. $this->serverError(sprintf(_m('Could not unsubscribe remote user %1$s from list %2$s.'), - $oprofile->uri, $this->peopletag->getBestName())); - return; + $this->oprofile->getUri(), $this->peopletag->getBestName())); } } }