From 689e277c62ce72c28c9c069a14f2ff0f68c133a6 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Fri, 29 Jan 2016 16:06:16 +0100 Subject: [PATCH] Allow @localuser@mysite.example to be looked up as a mention --- plugins/OStatus/OStatusPlugin.php | 38 ++++++++++++------- plugins/OStatus/classes/Ostatus_profile.php | 20 ---------- .../OStatus/lib/ostatusshadowexception.php | 28 ++++++++++++++ 3 files changed, 52 insertions(+), 34 deletions(-) create mode 100644 plugins/OStatus/lib/ostatusshadowexception.php diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 06aaa54ce6..6f6a22bf4d 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -293,26 +293,36 @@ class OStatusPlugin extends Plugin foreach ($wmatches[1] as $wmatch) { list($target, $pos) = $wmatch; $this->log(LOG_INFO, "Checking webfinger '$target'"); + $profile = null; try { $oprofile = Ostatus_profile::ensureWebfinger($target); - if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) { - $profile = $oprofile->localProfile(); - $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) ? - $profile->nickname : $target; - $url = $profile->getUri(); - if (!common_valid_http_url($url)) { - $url = $profile->getUrl(); - } - $matches[$pos] = array('mentioned' => array($profile), - 'type' => 'mention', - 'text' => $text, - 'position' => $pos, - 'length' => mb_strlen($target), - 'url' => $url); + if (!$oprofile instanceof Ostatus_profile || !$oprofile->isPerson()) { + continue; } + $profile = $oprofile->localProfile(); + } catch (OStatusShadowException $e) { + // This means we got a local user in the webfinger lookup + $profile = $e->profile; } catch (Exception $e) { $this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage()); + continue; + } + + assert($profile instanceof Profile); + + $text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) + ? $profile->getNickname() // TODO: we could do getFancyName() or getFullname() here + : $target; + $url = $profile->getUri(); + if (!common_valid_http_url($url)) { + $url = $profile->getUrl(); } + $matches[$pos] = array('mentioned' => array($profile), + 'type' => 'mention', + 'text' => $text, + 'position' => $pos, + 'length' => mb_strlen($target), + 'url' => $url); } } diff --git a/plugins/OStatus/classes/Ostatus_profile.php b/plugins/OStatus/classes/Ostatus_profile.php index d08f913309..6b62c6f47f 100644 --- a/plugins/OStatus/classes/Ostatus_profile.php +++ b/plugins/OStatus/classes/Ostatus_profile.php @@ -1859,23 +1859,3 @@ class Ostatus_profile extends Managed_DataObject $this->subscribe(); } } - -/** - * Exception indicating we've got a remote reference to a local user, - * not a remote user! - * - * If we can ue a local profile after all, it's available as $e->profile. - */ -class OStatusShadowException extends Exception -{ - public $profile; - - /** - * @param Profile $profile - * @param string $message - */ - function __construct($profile, $message) { - $this->profile = $profile; - parent::__construct($message); - } -} diff --git a/plugins/OStatus/lib/ostatusshadowexception.php b/plugins/OStatus/lib/ostatusshadowexception.php new file mode 100644 index 0000000000..1748f2ea23 --- /dev/null +++ b/plugins/OStatus/lib/ostatusshadowexception.php @@ -0,0 +1,28 @@ + + */ + +/** + * Exception indicating we've got a remote reference to a local user, + * not a remote user! + * + * If we can ue a local profile after all, it's available as $e->profile. + */ +class OStatusShadowException extends Exception +{ + public $profile; + + /** + * @param Profile $profile + * @param string $message + */ + function __construct(Profile $profile, $message) { + $this->profile = $profile; + parent::__construct($message); + } +} -- 2.39.5