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

Commit

Permalink
Merge pull request #9 from herpaderpaldent/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
herpaderpaldent authored Jan 1, 2019
2 parents 2ad7039 + b036330 commit c84e915
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
56 changes: 22 additions & 34 deletions src/Notifications/RefreshTokenDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Herpaderpaldent\Seat\SeatNotifications\Channels\Discord\DiscordMessage;
use Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackChannel;
use Herpaderpaldent\Seat\SeatNotifications\Channels\Slack\SlackMessage;
use Illuminate\Support\Facades\Redis;
use Seat\Eveapi\Models\Corporation\CorporationInfo;
use Seat\Eveapi\Models\RefreshToken;

Expand Down Expand Up @@ -49,39 +48,28 @@ public function __construct(RefreshToken $refresh_token)
*/
public function via($notifiable)
{
Redis::funnel('seatnotification:channel_id' . $notifiable->channel_id)->limit(1)->then(function () use ($notifiable) {
switch($notifiable->via) {
case 'discord':
$this->tags = [
'refresh_token',
'discord',
$notifiable->type === 'private' ? $notifiable->recipient() : 'channel',
];

return [DiscordChannel::class];
break;
case 'slack':
$this->tags = [
'refresh_token',
'slack',
$notifiable->type === 'private' ? $notifiable->recipient() : 'channel',
];

return [SlackChannel::class];
break;
default:
return [''];
}
}, function () use ($notifiable) {

logger()->warning(' A notification on ' . $notifiable->via .
' for channel ' . $notifiable->channel_id .
' has already been dispateched. Removing the job from the queue');

$this->delete();
});

return [''];
switch($notifiable->via) {
case 'discord':
$this->tags = [
'refresh_token',
'discord',
$notifiable->type === 'private' ? $notifiable->recipient() : 'channel',
];

return [DiscordChannel::class];
break;
case 'slack':
$this->tags = [
'refresh_token',
'slack',
$notifiable->type === 'private' ? $notifiable->recipient() : 'channel',
];

return [SlackChannel::class];
break;
default:
return [''];
}
}

public function toDiscord($notifiable)
Expand Down
22 changes: 14 additions & 8 deletions src/Observers/RefreshTokenObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

use Herpaderpaldent\Seat\SeatNotifications\Models\RefreshTokenNotification;
use Herpaderpaldent\Seat\SeatNotifications\Notifications\RefreshTokenDeletedNotification;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Redis;
use Seat\Eveapi\Models\RefreshToken;
Expand All @@ -20,7 +19,7 @@ class RefreshTokenObserver
public function deleting(RefreshToken $refresh_token)
{
Redis::funnel('soft_delete:refresh_token_' . $refresh_token->user->name)->limit(1)->then(function () use ($refresh_token) {
Log::info('SoftDelete detected of ' . $refresh_token->user->name);
logger()->info('SoftDelete detected of ' . $refresh_token->user->name);

$receipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
Expand All @@ -29,20 +28,27 @@ public function deleting(RefreshToken $refresh_token)

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));
}, function () use ($refresh_token) {
Log::info('A Soft-Delete job is already running for ' . $refresh_token->user->name);
logger()->info('A Soft-Delete job is already running for ' . $refresh_token->user->name);
});
}

public function test()
{
$receipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
return $recepient->shouldReceive();
});

$refresh_token = RefreshToken::find(95725047);

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));
Redis::funnel('soft_delete:refresh_token_' . $refresh_token->user->name)->limit(1)->then(function () use ($refresh_token) {
logger()->info('SoftDelete detected of ' . $refresh_token->user->name);

$receipients = RefreshTokenNotification::all()
->filter(function ($recepient) {
return $recepient->shouldReceive();
});

Notification::send($receipients, (new RefreshTokenDeletedNotification($refresh_token)));
}, function () use ($refresh_token) {
logger()->info('A Soft-Delete job is already running for ' . $refresh_token->user->name);
});

}
}
2 changes: 1 addition & 1 deletion src/config/seatnotifications.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* Time: 10:24.
*/
return [
'version' => '1.0.2',
'version' => '1.0.3',
];

0 comments on commit c84e915

Please sign in to comment.