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 #7 from herpaderpaldent/dev
Browse files Browse the repository at this point in the history
Version 1.0.2
  • Loading branch information
herpaderpaldent authored Jan 1, 2019
2 parents 6eec8f5 + b9da56a commit 2ad7039
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
3 changes: 2 additions & 1 deletion src/Notifications/BaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Seat\Web\Models\Group;

abstract class BaseNotification extends Notification implements ShouldQueue
{
use Queueable, SerializesModels;
use Queueable, SerializesModels, InteractsWithQueue;

/**
* @var array
Expand Down
56 changes: 35 additions & 21 deletions src/Notifications/RefreshTokenDeletedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 All @@ -37,7 +38,7 @@ public function __construct(RefreshToken $refresh_token)
$this->user_name = $refresh_token->user->name;
$this->image = 'https://imageserver.eveonline.com/Character/' . $refresh_token->character_id . '_128.jpg';
$this->main_character = $this->getMainCharacter($refresh_token->user->group)->name;
$this->corporation = CorporationInfo::find($refresh_token->user->character->corporation_id)->name;
$this->corporation = optional(CorporationInfo::find($refresh_token->user->character->corporation_id))->name ?: 'NPC Corporation';
}

/**
Expand All @@ -48,26 +49,39 @@ public function __construct(RefreshToken $refresh_token)
*/
public function via($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;
}
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 [''];
}

public function toDiscord($notifiable)
Expand Down
22 changes: 13 additions & 9 deletions src/Observers/RefreshTokenObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
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;

class RefreshTokenObserver
{
public function deleting(RefreshToken $refresh_token)
{
Log::info('SoftDelete detected of ' . $refresh_token->user->name);

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

Notification::send($receipients, (new RefreshTokenDeletedNotification($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);

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

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);
});
}

public function test()
Expand Down
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' => '0.0.1',
'version' => '1.0.2',
];

0 comments on commit 2ad7039

Please sign in to comment.