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