Skip to content

Commit

Permalink
0.1.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
the-turk committed Mar 4, 2020
1 parent 74cce32 commit 7b04349
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ As i promised in @Kylo#121339, this is a preparation for next version of my [Dif

It raises new events for developers, called `PostWasRevisedQuietly` & `PostWasRevisedLoudly`

**! Attention: Diff for Flarum & Edit Notifications extensions are incompatible with this right now and they're planned to be compatible on their next releases.**

![Settings](https://i.ibb.co/nsX8nrX/shsh.png)

## Requirements
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"source": "https://github.com/the-turk/flarum-quiet-edits"
},
"require": {
"flarum/core": ">=0.1.0-beta.10 <0.1.0-beta.12",
"jfcherng/php-diff": "^6.4.7"
"flarum/core": ">=0.1.0-beta.10 <0.1.0-beta.13",
"jfcherng/php-diff": "^6.5.1"
},
"autoload": {
"psr-4": {
Expand Down
31 changes: 24 additions & 7 deletions src/Listeners/PostActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
use Flarum\Post\Event\Revised as PostRevised;
use Flarum\Post\Event\Saving as PostSaving;
use Jfcherng\Diff\DiffHelper;
use Illuminate\Events\Dispatcher;
use Illuminate\Contracts\Events\Dispatcher;
use Flarum\Settings\SettingsRepositoryInterface;
use TheTurk\QuietEdits\Events\PostWasRevisedQuietly;
use TheTurk\QuietEdits\Events\PostWasRevisedLoudly;
use Carbon\Carbon;

class PostActions
{
/**
* @var Dispatcher
*/
protected $events;

/**
* @var SettingsRepositoryInterface
*/
Expand All @@ -23,10 +28,15 @@ class PostActions
private $oldPost = [];

/**
* @param SettingsRepositoryInterface $settings,
* @param Dispatcher $events
* @param SettingsRepositoryInterface $settings
*/
public function __construct(SettingsRepositoryInterface $settings)
public function __construct(
Dispatcher $events,
SettingsRepositoryInterface $settings
)
{
$this->events = $events;
$this->settings = $settings;
}

Expand Down Expand Up @@ -75,9 +85,12 @@ public function whenPostRevised(PostRevised $event)
$diff = json_decode($differ, true);

$gracePeriod = $this->settings->get('the-turk-quiet-edits.gracePeriod', '120');
$creationTime = new Carbon($post->created_at);
$creationTime = ($this->oldPost['edited_at'] !== null
? new Carbon($this->oldPost['edited_at'])
: new Carbon($post->created_at)
);

if ($creationTime->diffInSeconds(Carbon::now()) <= $gracePeriod || empty($diff)) {
if ($creationTime->diffInSeconds(Carbon::now()) < $gracePeriod || empty($diff)) {
if ($this->oldPost['edited_at'] === null) {
$post->edited_at = null;
} else {
Expand All @@ -92,9 +105,13 @@ public function whenPostRevised(PostRevised $event)

$post->save();

$post->raise(new PostWasRevisedQuietly($post, $actor));
$this->events->dispatch(
new PostWasRevisedQuietly($post, $actor)
);
} else {
$post->raise(new PostWasRevisedLoudly($post, $actor));
$this->events->dispatch(
new PostWasRevisedLoudly($post, $actor)
);
}
}
}

0 comments on commit 7b04349

Please sign in to comment.