mirror of
https://github.com/flarum/core.git
synced 2025-08-18 06:11:23 +02:00
chore: update codebase to php8.1 (#3827)
* chore: set minimum php version to 8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: update codebase to php8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: update workflow php version Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: more caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: phpstan caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: introduce `Flarum\Locale\TranslatorInterface` Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: remove mixin Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: one last error Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -80,8 +80,8 @@ return [
|
||||
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user',
|
||||
'posts.mentionsGroups'
|
||||
])
|
||||
->loadWhere('posts.mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('posts.mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\ApiController(Controller\ListDiscussionsController::class))
|
||||
->load([
|
||||
@@ -93,14 +93,14 @@ return [
|
||||
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
||||
// We wouldn't normally need to eager load on a single model,
|
||||
// but we do so here for visibility scoping.
|
||||
->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\ApiController(Controller\ListPostsController::class))
|
||||
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
||||
->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsGroups'])
|
||||
->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\Settings)
|
||||
->serializeToForum('allowUsernameMentionFormat', 'flarum-mentions.allow_username_format', 'boolval'),
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Flarum\Mentions\Api;
|
||||
|
||||
use Flarum\Api\Controller\AbstractSerializeController;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Post\Post;
|
||||
@@ -22,13 +23,13 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
*/
|
||||
class LoadMentionedByRelationship
|
||||
{
|
||||
public static $maxMentionedBy = 4;
|
||||
public static int $maxMentionedBy = 4;
|
||||
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request)
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): void
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
||||
return $query
|
||||
$query
|
||||
->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsUsers'])
|
||||
->whereVisibleTo($actor)
|
||||
->oldest()
|
||||
@@ -41,13 +42,15 @@ class LoadMentionedByRelationship
|
||||
/**
|
||||
* Called using the @see ApiController::prepareDataForSerialization extender.
|
||||
*/
|
||||
public static function countRelation($controller, $data, ServerRequestInterface $request): void
|
||||
public static function countRelation(AbstractSerializeController $controller, mixed $data, ServerRequestInterface $request): array
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$loadable = null;
|
||||
|
||||
if ($data instanceof Discussion) {
|
||||
$loadable = $data->newCollection($data->posts)->filter(function ($post) {
|
||||
// We do this because the ShowDiscussionController manipulates the posts
|
||||
// in a way that some of them are just ids.
|
||||
$loadable = $data->posts->filter(function ($post) {
|
||||
return $post instanceof Post;
|
||||
});
|
||||
} elseif ($data instanceof Collection) {
|
||||
@@ -63,5 +66,7 @@ class LoadMentionedByRelationship
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@@ -30,23 +30,13 @@ class ConfigureMentions
|
||||
public const GROUP_MENTION_WITH_NAME_REGEX = '/\B@["“](?<groupname>((?!"#[a-z]{0,3}[0-9]+).)+)["|”]#g(?<id>[0-9]+)\b/';
|
||||
public const TAG_MENTION_WITH_SLUG_REGEX = '/(?:[^“"]|^)\B#(?<slug>[-_\p{L}\p{N}\p{M}]+)\b/ui';
|
||||
|
||||
/**
|
||||
* @var UrlGenerator
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(UrlGenerator $url, ExtensionManager $extensions)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->extensions = $extensions;
|
||||
public function __construct(
|
||||
protected UrlGenerator $url,
|
||||
protected ExtensionManager $extensions
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Configurator $config)
|
||||
public function __invoke(Configurator $config): void
|
||||
{
|
||||
$this->configureUserMentions($config);
|
||||
$this->configurePostMentions($config);
|
||||
|
@@ -22,7 +22,7 @@ class MentionedFilter implements FilterInterface
|
||||
return 'mentioned';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$mentionedId = $this->asInt($filterValue);
|
||||
|
||||
|
@@ -19,7 +19,7 @@ class MentionedPostFilter implements FilterInterface
|
||||
return 'mentionedPost';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, string $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$mentionedId = trim($filterValue, '"');
|
||||
|
||||
|
@@ -20,38 +20,15 @@ use s9e\TextFormatter\Parser;
|
||||
|
||||
class EagerLoadMentionedModels
|
||||
{
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
protected $posts;
|
||||
|
||||
/**
|
||||
* @var GroupRepository
|
||||
*/
|
||||
protected $groups;
|
||||
|
||||
/**
|
||||
* @var TagRepository
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
public function __construct(ExtensionManager $extensions, PostRepository $posts, GroupRepository $groups, TagRepository $tags)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
$this->posts = $posts;
|
||||
$this->groups = $groups;
|
||||
$this->tags = $tags;
|
||||
public function __construct(
|
||||
protected ExtensionManager $extensions,
|
||||
protected PostRepository $posts,
|
||||
protected GroupRepository $groups,
|
||||
protected TagRepository $tags
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|\Flarum\Post\CommentPost|null $context
|
||||
*/
|
||||
public function __invoke(Parser $parser, $context, string $text, ?User $actor): string
|
||||
public function __invoke(Parser $parser, mixed $context, string $text, ?User $actor): string
|
||||
{
|
||||
$callables = $this->getEagerLoaders();
|
||||
|
||||
|
@@ -10,32 +10,19 @@
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatGroupMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for group mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string $xml
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, string $xml): string
|
||||
public function __invoke(Renderer $renderer, mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'GROUPMENTION', function ($attributes) use ($context) {
|
||||
$group = (($context && isset($context->getRelations()['mentionsGroups'])) || $context instanceof Post)
|
||||
|
@@ -9,33 +9,19 @@
|
||||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatPostMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for post mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string|null $xml
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, $xml, Request $request = null)
|
||||
public function __invoke(Renderer $renderer, mixed $context, ?string $xml, Request $request = null): string
|
||||
{
|
||||
$post = $context;
|
||||
|
||||
|
@@ -17,7 +17,7 @@ use s9e\TextFormatter\Utils;
|
||||
|
||||
class FormatTagMentions
|
||||
{
|
||||
public function __invoke(Renderer $renderer, $context, ?string $xml, Request $request = null): string
|
||||
public function __invoke(Renderer $renderer, mixed $context, ?string $xml, Request $request = null): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'TAGMENTION', function ($attributes) use ($context) {
|
||||
/** @var Tag|null $tag */
|
||||
|
@@ -10,39 +10,21 @@
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Http\SlugManager;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatUserMentions
|
||||
{
|
||||
/**
|
||||
* @var SlugManager
|
||||
*/
|
||||
private $slugManager;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(SlugManager $slugManager, TranslatorInterface $translator)
|
||||
{
|
||||
$this->slugManager = $slugManager;
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly SlugManager $slugManager
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string $xml
|
||||
* @return string $xml to be rendered
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, string $xml)
|
||||
public function __invoke(Renderer $renderer, mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (($context && isset($context->getRelations()['mentionsUsers'])) || $context instanceof Post)
|
||||
|
@@ -9,42 +9,25 @@
|
||||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UnparsePostMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updatePostMentionTags($context, $xml);
|
||||
$xml = $this->unparsePostMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparsePostMentionTags(
|
||||
$this->updatePostMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML post mention tags before unparsing so that unparsing uses new display names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updatePostMentionTags($context, string $xml): string
|
||||
{
|
||||
@@ -74,9 +57,6 @@ class UnparsePostMentions
|
||||
|
||||
/**
|
||||
* Transforms post mention tags from XML to raw unparsed content with updated format and display name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparsePostMentionTags(string $xml): string
|
||||
{
|
||||
|
@@ -15,29 +15,17 @@ use s9e\TextFormatter\Utils;
|
||||
|
||||
class UnparseTagMentions
|
||||
{
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updateTagMentionTags($context, $xml);
|
||||
$xml = $this->unparseTagMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparseTagMentionTags(
|
||||
$this->updateTagMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML user mention tags before unparsing so that unparsing uses new tag names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updateTagMentionTags($context, string $xml): string
|
||||
protected function updateTagMentionTags(mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'TAGMENTION', function (array $attributes) use ($context) {
|
||||
/** @var Tag|null $tag */
|
||||
@@ -56,9 +44,6 @@ class UnparseTagMentions
|
||||
|
||||
/**
|
||||
* Transforms tag mention tags from XML to raw unparsed content with updated name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparseTagMentionTags(string $xml): string
|
||||
{
|
||||
|
@@ -9,46 +9,29 @@
|
||||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UnparseUserMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updateUserMentionTags($context, $xml);
|
||||
$xml = $this->unparseUserMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparseUserMentionTags(
|
||||
$this->updateUserMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML user mention tags before unparsing so that unparsing uses new display names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updateUserMentionTags($context, string $xml): string
|
||||
protected function updateUserMentionTags(mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (($context && isset($context->getRelations()['mentionsUsers'])) || $context instanceof Post)
|
||||
@@ -71,9 +54,6 @@ class UnparseUserMentions
|
||||
|
||||
/**
|
||||
* Transforms user mention tags from XML to raw unparsed content with updated format and display name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparseUserMentionTags(string $xml): string
|
||||
{
|
||||
|
@@ -20,37 +20,14 @@ use Flarum\User\User;
|
||||
|
||||
class SendMentionsNotificationsJob extends AbstractJob
|
||||
{
|
||||
/**
|
||||
* @var CommentPost
|
||||
*/
|
||||
protected $post;
|
||||
private NotificationSyncer $notifications;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $userMentions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $postMentions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $groupMentions;
|
||||
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
private $notifications;
|
||||
|
||||
public function __construct(CommentPost $post, array $userMentions, array $postMentions, array $groupMentions)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->userMentions = $userMentions;
|
||||
$this->postMentions = $postMentions;
|
||||
$this->groupMentions = $groupMentions;
|
||||
public function __construct(
|
||||
protected CommentPost $post,
|
||||
protected array $userMentions,
|
||||
protected array $postMentions,
|
||||
protected array $groupMentions
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(NotificationSyncer $notifications): void
|
||||
@@ -62,7 +39,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
||||
$this->notifyAboutGroupMentions($this->post, $this->groupMentions);
|
||||
}
|
||||
|
||||
protected function notifyAboutUserMentions(Post $post, array $mentioned)
|
||||
protected function notifyAboutUserMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$users = User::whereIn('id', $mentioned)
|
||||
->with('groups')
|
||||
@@ -75,7 +52,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
||||
$this->notifications->sync(new UserMentionedBlueprint($post), $users);
|
||||
}
|
||||
|
||||
protected function notifyAboutPostMentions(Post $reply, array $mentioned)
|
||||
protected function notifyAboutPostMentions(Post $reply, array $mentioned): void
|
||||
{
|
||||
$posts = Post::with('user')
|
||||
->whereIn('id', $mentioned)
|
||||
@@ -91,7 +68,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyAboutGroupMentions(Post $post, array $mentioned)
|
||||
protected function notifyAboutGroupMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$users = User::whereHas('groups', function ($query) use ($mentioned) {
|
||||
$query->whereIn('groups.id', $mentioned);
|
||||
|
@@ -17,26 +17,13 @@ use Flarum\Post\Event\Hidden;
|
||||
|
||||
class UpdateMentionsMetadataWhenInvisible
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications, ExtensionManager $extensions)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
$this->extensions = $extensions;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications,
|
||||
protected ExtensionManager $extensions
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Deleted|Hidden $event
|
||||
*/
|
||||
public function handle($event)
|
||||
public function handle(Deleted|Hidden $event): void
|
||||
{
|
||||
// Remove user mentions
|
||||
$event->post->mentionsUsers()->sync([]);
|
||||
|
@@ -22,26 +22,13 @@ use s9e\TextFormatter\Utils;
|
||||
|
||||
class UpdateMentionsMetadataWhenVisible
|
||||
{
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var Queue
|
||||
*/
|
||||
protected $queue;
|
||||
|
||||
public function __construct(ExtensionManager $extensions, Queue $queue)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
$this->queue = $queue;
|
||||
public function __construct(
|
||||
protected ExtensionManager $extensions,
|
||||
protected Queue $queue
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Posted|Restored|Revised|PostWasApproved $event
|
||||
*/
|
||||
public function handle($event)
|
||||
public function handle(Restored|Revised|Posted|PostWasApproved $event): void
|
||||
{
|
||||
if (! $event->post instanceof CommentPost) {
|
||||
return;
|
||||
@@ -74,25 +61,25 @@ class UpdateMentionsMetadataWhenVisible
|
||||
$this->queue->push(new SendMentionsNotificationsJob($event->post, $userMentions, $postMentions, $groupMentions));
|
||||
}
|
||||
|
||||
protected function syncUserMentions(Post $post, array $mentioned)
|
||||
protected function syncUserMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsUsers()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsUsers');
|
||||
}
|
||||
|
||||
protected function syncPostMentions(Post $reply, array $mentioned)
|
||||
protected function syncPostMentions(Post $reply, array $mentioned): void
|
||||
{
|
||||
$reply->mentionsPosts()->sync($mentioned);
|
||||
$reply->unsetRelation('mentionsPosts');
|
||||
}
|
||||
|
||||
protected function syncGroupMentions(Post $post, array $mentioned)
|
||||
protected function syncGroupMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsGroups()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsGroups');
|
||||
}
|
||||
|
||||
protected function syncTagMentions(Post $post, array $mentioned)
|
||||
protected function syncTagMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsTags()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsTags');
|
||||
|
@@ -9,61 +9,41 @@
|
||||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class GroupMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
public Post $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.groupMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.group_mentioned.subject', [
|
||||
'{mentioner_display_name}' => $this->post->user->display_name,
|
||||
@@ -71,18 +51,12 @@ class GroupMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'groupMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
@@ -9,69 +9,42 @@
|
||||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $reply;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param Post $reply
|
||||
*/
|
||||
public function __construct(Post $post, Post $reply)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->reply = $reply;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public Post $reply
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->reply->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): array
|
||||
{
|
||||
return ['replyNumber' => (int) $this->reply->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.postMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.post_mentioned.subject', [
|
||||
'{replier_display_name}' => $this->reply->user->display_name,
|
||||
@@ -79,18 +52,12 @@ class PostMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'postMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
@@ -9,61 +9,41 @@
|
||||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class UserMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
public Post $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.userMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.user_mentioned.subject', [
|
||||
'{mentioner_display_name}' => $this->post->user->display_name,
|
||||
@@ -71,18 +51,12 @@ class UserMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'userMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
Reference in New Issue
Block a user