2021-11-16 02:33:52 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Profile;
|
2024-11-19 11:03:08 +00:00
|
|
|
use Cache;
|
|
|
|
use Purify;
|
2021-11-16 02:33:52 +00:00
|
|
|
|
|
|
|
class AutolinkService
|
|
|
|
{
|
2024-11-19 11:03:08 +00:00
|
|
|
const CACHE_KEY = 'pf:services:autolink:mue:';
|
2021-11-16 02:33:52 +00:00
|
|
|
|
2024-11-19 11:03:08 +00:00
|
|
|
public static function mentionedUsernameExists($username)
|
|
|
|
{
|
|
|
|
if (str_starts_with($username, '@')) {
|
|
|
|
if (substr_count($username, '@') === 1) {
|
|
|
|
$username = substr($username, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$name = Purify::clean(strtolower($username));
|
2021-11-16 02:33:52 +00:00
|
|
|
|
2024-11-19 11:03:08 +00:00
|
|
|
return Cache::remember(self::CACHE_KEY.base64_encode($name), 7200, function () use ($name) {
|
|
|
|
return Profile::where('username', $name)->exists();
|
|
|
|
});
|
|
|
|
}
|
2021-11-16 02:33:52 +00:00
|
|
|
}
|