[UTIL][Formatting] Make local mentions great again
This commit is contained in:
parent
91dd6e1428
commit
712d1739e4
@ -323,16 +323,17 @@ class Actor extends Entity
|
||||
{
|
||||
// Will throw exception on invalid input.
|
||||
$nickname = Nickname::normalize($nickname, check_already_used: false);
|
||||
return Cache::get(
|
||||
'relative-nickname-' . $nickname . '-' . $this->getId(),
|
||||
fn () => DB::dql(
|
||||
'select a from actor a where '
|
||||
. 'a.id in (select followed from follow f join actor a on f.followed = a.id where and f.follower = :actor_id and a.nickname = :nickname) or'
|
||||
. 'a.id in (select follower from follow f join actor a on f.follower = a.id where and f.followed = :actor_id and a.nickname = :nickname) or'
|
||||
. 'a.nickname = :nickname'
|
||||
. 'limit 1',
|
||||
['nickname' => $nickname, 'actor_id' => $this->getId()],
|
||||
),
|
||||
return Cache::get('relative-nickname-' . $nickname . '-' . $this->getId(),
|
||||
fn () => DB::dql(<<<EOF
|
||||
select a from actor a where
|
||||
a.id in (select fa.followed from follow fa join actor aa with fa.followed = aa.id where fa.follower = :actor_id and aa.nickname = :nickname) or
|
||||
a.id in (select fb.follower from follow fb join actor ab with fb.follower = ab.id where fb.followed = :actor_id and ab.nickname = :nickname) or
|
||||
a.nickname = :nickname
|
||||
EOF
|
||||
,
|
||||
['nickname' => $nickname, 'actor_id' => $this->getId()],
|
||||
['limit' => 1]
|
||||
)[0] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ abstract class Common
|
||||
|
||||
// (if false, we use '?' in 'https?' to say the 's' is optional)
|
||||
$regex = $ensure_secure ? '/^https$/' : '/^https?$/';
|
||||
return filter_var($url, \FILTER_VALIDATE_URL)
|
||||
return filter_var($url, \FILTER_VALIDATE_URL) !== false
|
||||
&& preg_match($regex, parse_url($url, \PHP_URL_SCHEME));
|
||||
}
|
||||
|
||||
|
@ -307,10 +307,11 @@ abstract class Formatting
|
||||
|
||||
$matches = self::findMentionsRaw($text, '@');
|
||||
|
||||
//dd($matches);
|
||||
foreach ($matches as $match) {
|
||||
try {
|
||||
$nickname = Nickname::normalize($match[0], check_already_used: false);
|
||||
} catch (NicknameException $e) {
|
||||
} catch (NicknameException) {
|
||||
// Bogus match? Drop it.
|
||||
continue;
|
||||
}
|
||||
@ -388,7 +389,7 @@ abstract class Formatting
|
||||
|
||||
$group_matches = self::findMentionsRaw($text, '!');
|
||||
foreach ($group_matches as $group_match) {
|
||||
$nickname = Nickname::normalize($group_match[0], check_already_used: false);
|
||||
$nickname = Nickname::normalize($group_match[0], check_already_used: false, check_is_allowed: false);
|
||||
$group = Group::getFromNickname($nickname, $actor);
|
||||
|
||||
if (!$group instanceof Group) {
|
||||
@ -410,7 +411,7 @@ abstract class Formatting
|
||||
|
||||
Event::handle('EndFindMentions', [$actor, $text, &$mentions]);
|
||||
}
|
||||
|
||||
//dd($text,$mentions);
|
||||
return $mentions;
|
||||
}
|
||||
|
||||
@ -440,6 +441,7 @@ abstract class Formatting
|
||||
$atmatches,
|
||||
\PREG_OFFSET_CAPTURE,
|
||||
);
|
||||
//dd('/' . Nickname::BEFORE_MENTIONS . preg_quote($preMention, '/') . '(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/', $atmatches);
|
||||
|
||||
return array_merge($tmatches[1], $atmatches[1]);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ class Nickname
|
||||
* FIXME: Make this so you can have multiple whitespace but not multiple
|
||||
* parenthesis or something. '(((@n_n@)))' might as well be a smiley.
|
||||
*/
|
||||
public const BEFORE_MENTIONS = '(?:^|[\s\.\,\:\;\[\(]+)';
|
||||
public const BEFORE_MENTIONS = '(?:^|[\s\.\,\:\;\[\(\>]+)';
|
||||
|
||||
public const CHECK_LOCAL_USER = 1;
|
||||
public const CHECK_LOCAL_GROUP = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user