Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
luceos committed Aug 7, 2024
1 parent cda2f71 commit 9af211c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
namespace Blomstra\FlagDuplicates;

use Blomstra\FlagDuplicates\Post\DiscussionFlaggedAsDuplicatePost;
use Flarum\Api\Controller\ListDiscussionsController;
use Flarum\Api\Controller\ShowDiscussionController;
use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Extend;
use Flarum\Flags\Event\Created as FlagCreated;
use Flarum\Flags\Event\Deleting as FlagDeleting;
Expand All @@ -38,4 +40,7 @@

(new Extend\ApiController(ShowDiscussionController::class))
->addInclude('firstPost'),

(new Extend\ApiSerializer(DiscussionSerializer::class))
->attribute('canFlagDuplicate', Api\AddCanFlagDuplicateAttribute::class),
];
2 changes: 1 addition & 1 deletion js/dist/forum.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/forum.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src/forum/extendFlagModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default function extendFlagModal() {

extend(DiscussionControls, 'userControls', function (items: ItemList<Mithril.Children>, discussion: Discussion) {
const post = discussion.firstPost();
if (!post || post.isHidden() || post.contentType() !== 'comment' || !post.canFlag()) return;
if (!post || post.isHidden() || post.contentType() !== 'comment' || !discussion.canFlagDuplicate()) return;

items.add(
'flag-dupe',
Expand Down
4 changes: 4 additions & 0 deletions js/src/forum/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import app from 'flarum/forum/app';
import DiscussionFlaggedDuplicatePost from './components/DiscussionFlaggedDuplicatePost';
import extendFlagModal from './extendFlagModal';
import Extend from 'flarum/common/extenders';
import Discussion from 'flarum/common/models/Discussion';

app.initializers.add('blomstra/flag-duplicates', () => {
new Extend.Model(Discussion).attribute<boolean>('canFlagDuplicate');

app.postComponents.discussionFlaggedDuplicate = DiscussionFlaggedDuplicatePost;
extendFlagModal();
});
27 changes: 27 additions & 0 deletions src/Api/AddCanFlagDuplicateAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Blomstra\FlagDuplicates\Api;

use Flarum\Api\Serializer\DiscussionSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Discussion\Discussion;
use Flarum\Flags\AddCanFlagAttribute;
use Flarum\Settings\SettingsRepositoryInterface;

class AddCanFlagDuplicateAttribute
{
public function __construct(
protected SettingsRepositoryInterface $settings,
protected PostSerializer $postSerializer,
protected AddCanFlagAttribute $gate
) {}

public function __invoke(DiscussionSerializer $serializer, Discussion $discussion): bool
{
$this->postSerializer->setRequest($serializer->getRequest());

$gate = $this->gate;

return $gate($this->postSerializer, $discussion->firstPost);
}
}

0 comments on commit 9af211c

Please sign in to comment.