Allow @localuser@mysite.example to be looked up as a mention

This commit is contained in:
Mikael Nordfeldth 2016-01-29 16:06:16 +01:00
parent 36f099958c
commit 689e277c62
3 changed files with 52 additions and 34 deletions

View File

@ -293,12 +293,26 @@ 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()) {
if (!$oprofile instanceof Ostatus_profile || !$oprofile->isPerson()) {
continue;
}
$profile = $oprofile->localProfile();
$text = !empty($profile->nickname) && mb_strlen($profile->nickname) < mb_strlen($target) ?
$profile->nickname : $target;
} 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();
@ -310,10 +324,6 @@ class OStatusPlugin extends Plugin
'length' => mb_strlen($target),
'url' => $url);
}
} catch (Exception $e) {
$this->log(LOG_ERR, "Webfinger check failed: " . $e->getMessage());
}
}
}
// Profile matches: @example.com/mublog/user

View File

@ -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);
}
}

View File

@ -0,0 +1,28 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* @package OStatusPlugin
* @maintainer Mikael Nordfeldth <mmn@hethane.se>
*/
/**
* 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);
}
}