mirror of
https://github.com/flarum/core.git
synced 2025-08-15 21:04:30 +02:00
Update for composer branch
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions;
|
||||
|
||||
use Flarum\Support\Extension as BaseExtension;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
||||
class Extension extends BaseExtension
|
||||
{
|
||||
public function listen(Dispatcher $events)
|
||||
{
|
||||
$events->subscribe('Flarum\Mentions\Listeners\AddClientAssets');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\AddModelRelationships');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\AddApiRelationships');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\AddUserMentionsFormatter');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\AddPostMentionsFormatter');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\UpdateUserMentionsMetadata');
|
||||
$events->subscribe('Flarum\Mentions\Listeners\UpdatePostMentionsMetadata');
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__.'/../views', 'mentions');
|
||||
}
|
||||
}
|
40
extensions/mentions/src/Listener/AddClientAssets.php
Executable file
40
extensions/mentions/src/Listener/AddClientAssets.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Event\ConfigureClientView;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureClientView $event
|
||||
*/
|
||||
public function addAssets(ConfigureClientView $event)
|
||||
{
|
||||
if ($event->isForum()) {
|
||||
$event->addAssets([
|
||||
__DIR__.'/../../js/forum/dist/extension.js',
|
||||
__DIR__.'/../../less/forum/extension.less'
|
||||
]);
|
||||
$event->addBootstrapper('flarum/mentions/main');
|
||||
$event->addTranslations('flarum-mentions.forum');
|
||||
}
|
||||
}
|
||||
}
|
104
extensions/mentions/src/Listener/AddPostMentionedByRelationship.php
Executable file
104
extensions/mentions/src/Listener/AddPostMentionedByRelationship.php
Executable file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Api\Controller\CreatePostController;
|
||||
use Flarum\Api\Controller\ListPostsController;
|
||||
use Flarum\Api\Controller\ShowDiscussionController;
|
||||
use Flarum\Api\Controller\ShowPostController;
|
||||
use Flarum\Api\Serializer\PostBasicSerializer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Event\ConfigureApiController;
|
||||
use Flarum\Event\GetApiRelationship;
|
||||
use Flarum\Event\GetModelRelationship;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddPostMentionedByRelationship
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(GetModelRelationship::class, [$this, 'getModelRelationship']);
|
||||
$events->listen(GetApiRelationship::class, [$this, 'getApiRelationship']);
|
||||
$events->listen(ConfigureApiController::class, [$this, 'includeRelationships']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetModelRelationship $event
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany|null
|
||||
*/
|
||||
public function getModelRelationship(GetModelRelationship $event)
|
||||
{
|
||||
if ($event->isRelationship(Post::class, 'mentionedBy')) {
|
||||
return $event->model->belongsToMany(Post::class, 'mentions_posts', 'mentions_id', 'post_id', 'mentionedBy');
|
||||
}
|
||||
|
||||
if ($event->isRelationship(Post::class, 'mentionsPosts')) {
|
||||
return $event->model->belongsToMany(Post::class, 'mentions_posts', 'post_id', 'mentions_id', 'mentionsPosts');
|
||||
}
|
||||
|
||||
if ($event->isRelationship(Post::class, 'mentionsUsers')) {
|
||||
return $event->model->belongsToMany(User::class, 'mentions_users', 'post_id', 'mentions_id', 'mentionsUsers');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param GetApiRelationship $event
|
||||
* @return \Flarum\Api\Relationship\HasManyBuilder|null
|
||||
*/
|
||||
public function getApiRelationship(GetApiRelationship $event)
|
||||
{
|
||||
if ($event->isRelationship(PostBasicSerializer::class, 'mentionedBy')) {
|
||||
return $event->serializer->hasMany(PostBasicSerializer::class, 'mentionedBy');
|
||||
}
|
||||
|
||||
if ($event->isRelationship(PostBasicSerializer::class, 'mentionsPosts')) {
|
||||
return $event->serializer->hasMany(PostBasicSerializer::class, 'mentionsPosts');
|
||||
}
|
||||
|
||||
if ($event->isRelationship(PostBasicSerializer::class, 'mentionsUsers')) {
|
||||
return $event->serializer->hasMany(PostBasicSerializer::class, 'mentionsUsers');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigureApiController $event
|
||||
*/
|
||||
public function includeRelationships(ConfigureApiController $event)
|
||||
{
|
||||
if ($event->isController(ShowDiscussionController::class)) {
|
||||
$event->addInclude([
|
||||
'posts.mentionedBy',
|
||||
'posts.mentionedBy.user',
|
||||
'posts.mentionedBy.discussion'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($event->isController(ShowPostController::class)
|
||||
|| $event->isController(ListPostsController::class)) {
|
||||
$event->addInclude([
|
||||
'mentionedBy',
|
||||
'mentionedBy.user',
|
||||
'mentionedBy.discussion'
|
||||
]);
|
||||
}
|
||||
|
||||
if ($event->isController(CreatePostController::class)) {
|
||||
$event->addInclude([
|
||||
'mentionsPosts',
|
||||
'mentionsPosts.mentionedBy'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,19 +8,26 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Events\FormatterConfigurator;
|
||||
use Flarum\Core\Posts\CommentPost;
|
||||
use Flarum\Core\Post\CommentPost;
|
||||
use Flarum\Event\ConfigureFormatter;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddPostMentionsFormatter
|
||||
class FormatPostMentions
|
||||
{
|
||||
public function subscribe($events)
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(FormatterConfigurator::class, [$this, 'configure']);
|
||||
$events->listen(ConfigureFormatter::class, [$this, 'configure']);
|
||||
}
|
||||
|
||||
public function configure(FormatterConfigurator $event)
|
||||
/**
|
||||
* @param ConfigureFormatter $event
|
||||
*/
|
||||
public function configure(ConfigureFormatter $event)
|
||||
{
|
||||
$configurator = $event->configurator;
|
||||
|
||||
@@ -44,6 +51,10 @@ class AddPostMentionsFormatter
|
||||
$configurator->Preg->match('/\B@(?<username>[a-z0-9_-]+)#(?<id>\d+)/i', $tagName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tag
|
||||
* @return bool
|
||||
*/
|
||||
public static function addId($tag)
|
||||
{
|
||||
$post = CommentPost::find($tag->getAttribute('id'));
|
@@ -8,30 +8,43 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Events\FormatterConfigurator;
|
||||
use Flarum\Events\FormatterRenderer;
|
||||
use Flarum\Events\FormatterParser;
|
||||
use Flarum\Core\Users\UserRepository;
|
||||
use Flarum\Core\Repository\UserRepository;
|
||||
use Flarum\Event\ConfigureFormatter;
|
||||
use Flarum\Event\ConfigureFormatterParser;
|
||||
use Flarum\Event\ConfigureFormatterRenderer;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddUserMentionsFormatter
|
||||
class FormatUserMentions
|
||||
{
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @param UserRepository $users
|
||||
*/
|
||||
public function __construct(UserRepository $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
}
|
||||
|
||||
public function subscribe($events)
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(FormatterConfigurator::class, [$this, 'configure']);
|
||||
$events->listen(FormatterParser::class, [$this, 'parse']);
|
||||
$events->listen(FormatterRenderer::class, [$this, 'render']);
|
||||
$events->listen(ConfigureFormatter::class, [$this, 'configure']);
|
||||
$events->listen(ConfigureFormatterParser::class, [$this, 'parse']);
|
||||
$events->listen(ConfigureFormatterRenderer::class, [$this, 'render']);
|
||||
}
|
||||
|
||||
public function configure(FormatterConfigurator $event)
|
||||
/**
|
||||
* @param ConfigureFormatter $event
|
||||
*/
|
||||
public function configure(ConfigureFormatter $event)
|
||||
{
|
||||
$configurator = $event->configurator;
|
||||
|
||||
@@ -50,17 +63,28 @@ class AddUserMentionsFormatter
|
||||
$configurator->Preg->match('/\B@(?<username>[a-z0-9_-]+)(?!#)/i', $tagName);
|
||||
}
|
||||
|
||||
public function parse(FormatterParser $event)
|
||||
/**
|
||||
* @param ConfigureFormatterParser $event
|
||||
*/
|
||||
public function parse(ConfigureFormatterParser $event)
|
||||
{
|
||||
$event->parser->registeredVars['userRepository'] = $this->users;
|
||||
}
|
||||
|
||||
public function render(FormatterRenderer $event)
|
||||
/**
|
||||
* @param ConfigureFormatterRenderer $event
|
||||
*/
|
||||
public function render(ConfigureFormatterRenderer $event)
|
||||
{
|
||||
// TODO: use URL generator
|
||||
$event->renderer->setParameter('PROFILE_URL', '/u/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tag
|
||||
* @param UserRepository $users
|
||||
* @return bool
|
||||
*/
|
||||
public static function addId($tag, UserRepository $users)
|
||||
{
|
||||
if ($id = $users->getIdForUsername($tag->getAttribute('username'))) {
|
@@ -8,33 +8,42 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Mentions\Notifications\PostMentionedBlueprint;
|
||||
use Flarum\Core\Notifications\NotificationSyncer;
|
||||
use Flarum\Events\RegisterNotificationTypes;
|
||||
use Flarum\Events\PostWasPosted;
|
||||
use Flarum\Events\PostWasRevised;
|
||||
use Flarum\Events\PostWasHidden;
|
||||
use Flarum\Events\PostWasRestored;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Api\Serializer\PostBasicSerializer;
|
||||
use Flarum\Core\Notification\NotificationSyncer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Event\ConfigureNotificationTypes;
|
||||
use Flarum\Event\PostWasDeleted;
|
||||
use Flarum\Event\PostWasHidden;
|
||||
use Flarum\Event\PostWasPosted;
|
||||
use Flarum\Event\PostWasRestored;
|
||||
use Flarum\Event\PostWasRevised;
|
||||
use Flarum\Mentions\Notification\PostMentionedBlueprint;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use s9e\TextFormatter\Utils;
|
||||
|
||||
class UpdatePostMentionsMetadata
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterNotificationTypes::class, [$this, 'registerNotificationType']);
|
||||
|
||||
$events->listen(ConfigureNotificationTypes::class, [$this, 'addNotificationType']);
|
||||
$events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']);
|
||||
$events->listen(PostWasRevised::class, [$this, 'whenPostWasRevised']);
|
||||
$events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']);
|
||||
@@ -42,40 +51,57 @@ class UpdatePostMentionsMetadata
|
||||
$events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
|
||||
}
|
||||
|
||||
public function registerNotificationType(RegisterNotificationTypes $event)
|
||||
/**
|
||||
* @param ConfigureNotificationTypes $event
|
||||
*/
|
||||
public function addNotificationType(ConfigureNotificationTypes $event)
|
||||
{
|
||||
$event->register(
|
||||
PostMentionedBlueprint::class,
|
||||
'Flarum\Api\Serializers\PostBasicSerializer',
|
||||
['alert']
|
||||
);
|
||||
$event->add(PostMentionedBlueprint::class, PostBasicSerializer::class, ['alert']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasPosted $event
|
||||
*/
|
||||
public function whenPostWasPosted(PostWasPosted $event)
|
||||
{
|
||||
$this->replyBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasRevised $event
|
||||
*/
|
||||
public function whenPostWasRevised(PostWasRevised $event)
|
||||
{
|
||||
$this->replyBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasHidden $event
|
||||
*/
|
||||
public function whenPostWasHidden(PostWasHidden $event)
|
||||
{
|
||||
$this->replyBecameInvisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasRestored $event
|
||||
*/
|
||||
public function whenPostWasRestored(PostWasRestored $event)
|
||||
{
|
||||
$this->replyBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasDeleted $event
|
||||
*/
|
||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||
{
|
||||
$this->replyBecameInvisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $reply
|
||||
*/
|
||||
protected function replyBecameVisible(Post $reply)
|
||||
{
|
||||
$mentioned = Utils::getAttributeValues($reply->parsedContent, 'POSTMENTION', 'id');
|
||||
@@ -83,11 +109,18 @@ class UpdatePostMentionsMetadata
|
||||
$this->sync($reply, $mentioned);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $reply
|
||||
*/
|
||||
protected function replyBecameInvisible(Post $reply)
|
||||
{
|
||||
$this->sync($reply, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $reply
|
||||
* @param array $mentioned
|
||||
*/
|
||||
protected function sync(Post $reply, array $mentioned)
|
||||
{
|
||||
$reply->mentionsPosts()->sync($mentioned);
|
@@ -8,34 +8,42 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
namespace Flarum\Mentions\Listener;
|
||||
|
||||
use Flarum\Mentions\Notifications\UserMentionedBlueprint;
|
||||
use Flarum\Core\Notifications\NotificationSyncer;
|
||||
use Flarum\Events\RegisterNotificationTypes;
|
||||
use Flarum\Events\PostWasPosted;
|
||||
use Flarum\Events\PostWasRevised;
|
||||
use Flarum\Events\PostWasHidden;
|
||||
use Flarum\Events\PostWasRestored;
|
||||
use Flarum\Events\PostWasDeleted;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Notification\NotificationSyncer;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\User;
|
||||
use Flarum\Event\ConfigureNotificationTypes;
|
||||
use Flarum\Event\PostWasDeleted;
|
||||
use Flarum\Event\PostWasHidden;
|
||||
use Flarum\Event\PostWasPosted;
|
||||
use Flarum\Event\PostWasRestored;
|
||||
use Flarum\Event\PostWasRevised;
|
||||
use Flarum\Mentions\Notification\UserMentionedBlueprint;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use s9e\TextFormatter\Utils;
|
||||
|
||||
class UpdateUserMentionsMetadata
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterNotificationTypes::class, [$this, 'registerNotificationType']);
|
||||
|
||||
$events->listen(ConfigureNotificationTypes::class, [$this, 'addNotificationType']);
|
||||
$events->listen(PostWasPosted::class, [$this, 'whenPostWasPosted']);
|
||||
$events->listen(PostWasRevised::class, [$this, 'whenPostWasRevised']);
|
||||
$events->listen(PostWasHidden::class, [$this, 'whenPostWasHidden']);
|
||||
@@ -43,40 +51,61 @@ class UpdateUserMentionsMetadata
|
||||
$events->listen(PostWasDeleted::class, [$this, 'whenPostWasDeleted']);
|
||||
}
|
||||
|
||||
public function registerNotificationType(RegisterNotificationTypes $event)
|
||||
/**
|
||||
* @param ConfigureNotificationTypes $event
|
||||
*/
|
||||
public function addNotificationType(ConfigureNotificationTypes $event)
|
||||
{
|
||||
$event->register(
|
||||
$event->add(
|
||||
UserMentionedBlueprint::class,
|
||||
'Flarum\Api\Serializers\PostBasicSerializer',
|
||||
['alert']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasPosted $event
|
||||
*/
|
||||
public function whenPostWasPosted(PostWasPosted $event)
|
||||
{
|
||||
$this->postBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasRevised $event
|
||||
*/
|
||||
public function whenPostWasRevised(PostWasRevised $event)
|
||||
{
|
||||
$this->postBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasHidden $event
|
||||
*/
|
||||
public function whenPostWasHidden(PostWasHidden $event)
|
||||
{
|
||||
$this->postBecameInvisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasRestored $event
|
||||
*/
|
||||
public function whenPostWasRestored(PostWasRestored $event)
|
||||
{
|
||||
$this->postBecameVisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PostWasDeleted $event
|
||||
*/
|
||||
public function whenPostWasDeleted(PostWasDeleted $event)
|
||||
{
|
||||
$this->postBecameInvisible($event->post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
protected function postBecameVisible(Post $post)
|
||||
{
|
||||
$mentioned = Utils::getAttributeValues($post->parsedContent, 'USERMENTION', 'id');
|
||||
@@ -84,11 +113,18 @@ class UpdateUserMentionsMetadata
|
||||
$this->sync($post, $mentioned);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
protected function postBecameInvisible(Post $post)
|
||||
{
|
||||
$this->sync($post, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param array $mentioned
|
||||
*/
|
||||
protected function sync(Post $post, array $mentioned)
|
||||
{
|
||||
$post->mentionsUsers()->sync($mentioned);
|
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
|
||||
use Flarum\Events\ApiRelationship;
|
||||
use Flarum\Events\BuildApiAction;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Flarum\Api\Serializers\PostBasicSerializer;
|
||||
use Flarum\Api\Actions\Discussions;
|
||||
use Flarum\Api\Actions\Posts;
|
||||
|
||||
class AddApiRelationships
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(ApiRelationship::class, [$this, 'addRelationships']);
|
||||
$events->listen(BuildApiAction::class, [$this, 'includeRelationships']);
|
||||
}
|
||||
|
||||
public function addRelationships(ApiRelationship $event)
|
||||
{
|
||||
if ($event->serializer instanceof PostBasicSerializer) {
|
||||
if ($event->relationship === 'mentionedBy') {
|
||||
return $event->serializer->hasMany('Flarum\Api\Serializers\PostBasicSerializer', 'mentionedBy');
|
||||
}
|
||||
|
||||
if ($event->relationship === 'mentionsPosts') {
|
||||
return $event->serializer->hasMany('Flarum\Api\Serializers\PostBasicSerializer', 'mentionsPosts');
|
||||
}
|
||||
|
||||
if ($event->relationship === 'mentionsUsers') {
|
||||
return $event->serializer->hasMany('Flarum\Api\Serializers\PostBasicSerializer', 'mentionsUsers');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function includeRelationships(BuildApiAction $event)
|
||||
{
|
||||
if ($event->action instanceof Discussions\ShowAction) {
|
||||
$event->addInclude('posts.mentionedBy');
|
||||
$event->addInclude('posts.mentionedBy.user');
|
||||
$event->addInclude('posts.mentionedBy.discussion');
|
||||
}
|
||||
|
||||
if ($event->action instanceof Posts\ShowAction ||
|
||||
$event->action instanceof Posts\IndexAction) {
|
||||
$event->addInclude('mentionedBy');
|
||||
$event->addInclude('mentionedBy.user');
|
||||
$event->addInclude('mentionedBy.discussion');
|
||||
}
|
||||
|
||||
if ($event->action instanceof Posts\CreateAction) {
|
||||
$event->addInclude('mentionsPosts');
|
||||
$event->addInclude('mentionsPosts.mentionedBy');
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
|
||||
use Flarum\Events\RegisterLocales;
|
||||
use Flarum\Events\BuildClientView;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class AddClientAssets
|
||||
{
|
||||
public function subscribe(Dispatcher $events)
|
||||
{
|
||||
$events->listen(RegisterLocales::class, [$this, 'addLocale']);
|
||||
$events->listen(BuildClientView::class, [$this, 'addAssets']);
|
||||
}
|
||||
|
||||
public function addLocale(RegisterLocales $event)
|
||||
{
|
||||
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
|
||||
}
|
||||
|
||||
public function addAssets(BuildClientView $event)
|
||||
{
|
||||
$event->forumAssets([
|
||||
__DIR__.'/../../js/forum/dist/extension.js',
|
||||
__DIR__.'/../../less/forum/extension.less'
|
||||
]);
|
||||
|
||||
$event->forumBootstrapper('mentions/main');
|
||||
|
||||
$event->forumTranslations([
|
||||
'mentions.reply_to_post',
|
||||
'mentions.post_mentioned_notification',
|
||||
'mentions.others',
|
||||
'mentions.user_mentioned_notification',
|
||||
'mentions.post_mentioned_by',
|
||||
'mentions.you',
|
||||
'mentions.reply_link',
|
||||
'mentions.notify_post_mentioned',
|
||||
'mentions.notify_user_mentioned'
|
||||
]);
|
||||
}
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Listeners;
|
||||
|
||||
use Flarum\Events\ModelRelationship;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Users\User;
|
||||
|
||||
class AddModelRelationships
|
||||
{
|
||||
public function subscribe($events)
|
||||
{
|
||||
$events->listen(ModelRelationship::class, [$this, 'addRelationships']);
|
||||
}
|
||||
|
||||
public function addRelationships(ModelRelationship $event)
|
||||
{
|
||||
if ($event->model instanceof Post) {
|
||||
if ($event->relationship === 'mentionedBy') {
|
||||
return $event->model->belongsToMany(Post::class, 'mentions_posts', 'mentions_id', 'post_id', 'mentionedBy');
|
||||
}
|
||||
|
||||
if ($event->relationship === 'mentionsPosts') {
|
||||
return $event->model->belongsToMany(Post::class, 'mentions_posts', 'post_id', 'mentions_id', 'mentionsPosts');
|
||||
}
|
||||
|
||||
if ($event->relationship === 'mentionsUsers') {
|
||||
return $event->model->belongsToMany(User::class, 'mentions_users', 'post_id', 'mentions_id', 'mentionsUsers');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,54 +8,85 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Notifications;
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Notifications\Blueprint;
|
||||
use Flarum\Core\Notifications\MailableBlueprint;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\Notification\BlueprintInterface;
|
||||
use Flarum\Core\Notification\MailableInterface;
|
||||
|
||||
class PostMentionedBlueprint implements Blueprint, MailableBlueprint
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSender()
|
||||
{
|
||||
return $this->reply->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return ['replyNumber' => (int) $this->reply->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
{
|
||||
return ['text' => 'mentions::emails.postMentioned'];
|
||||
return ['text' => 'flarum-mentions::emails.postMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject()
|
||||
{
|
||||
return "{$this->reply->user->username} replied to your post in {$this->post->discussion->title}";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
{
|
||||
return 'postMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
{
|
||||
return Post::class;
|
@@ -8,52 +8,78 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Mentions\Notifications;
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Core\Users\User;
|
||||
use Flarum\Core\Posts\Post;
|
||||
use Flarum\Core\Notifications\Blueprint;
|
||||
use Flarum\Core\Notifications\MailableBlueprint;
|
||||
use Flarum\Core\Post;
|
||||
use Flarum\Core\Notification\BlueprintInterface;
|
||||
use Flarum\Core\Notification\MailableInterface;
|
||||
|
||||
class UserMentionedBlueprint implements Blueprint, MailableBlueprint
|
||||
class UserMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSender()
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
{
|
||||
return ['text' => 'mentions::emails.userMentioned'];
|
||||
return ['text' => 'flarum-mentions::emails.userMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject()
|
||||
{
|
||||
return "{$this->post->user->username} mentioned you in {$this->post->discussion->title}";
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
{
|
||||
return 'userMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
{
|
||||
return Post::class;
|
Reference in New Issue
Block a user