Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Do not send the same MissingRefreshTokenNotification twice between 4hrs
Browse files Browse the repository at this point in the history
  • Loading branch information
herpaderpaldent committed Mar 28, 2019
1 parent c75a255 commit baaf354
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace Herpaderpaldent\Seat\SeatGroups\Notifications\MissingRefreshToken;

use Herpaderpaldent\Seat\SeatNotifications\Notifications\AbstractNotification;
use Illuminate\Support\Facades\Cache;
use Seat\Web\Models\User;

abstract class AbstractMissingRefreshTokenNotification extends AbstractNotification
Expand Down Expand Up @@ -126,4 +127,28 @@ public static function getPermission(): string
* @return mixed
*/
abstract public function via($notifiable);

/**
* @param $notifiable
*
* @return bool
* @throws \Exception
*/
public function dontSend($notifiable) :bool
{
$value = collect([
'recipient' => $notifiable->driver_id,
'notification' => get_called_class(),
'content' => get_object_vars($this)
])->toJson();

$key = md5($value);

if (empty(cache($key))) {
cache([$key => $value], now()->addHours(4));
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static function hasPersonalNotification() : bool
*/
public function via($notifiable)
{
if($this->dontSend($notifiable))
return [];

array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name);

return [DiscordChannel::class];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static function hasPersonalNotification() : bool
*/
public function via($notifiable)
{
if($this->dontSend($notifiable))
return [];

array_push($this->tags, is_null($notifiable->group_id) ? 'to channel' : 'private to: ' . $this->getMainCharacter(Group::find($notifiable->group_id))->name);

return [SlackChannel::class];
Expand Down

0 comments on commit baaf354

Please sign in to comment.