Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions app/Console/Commands/SendTestEmail.php

This file was deleted.

22 changes: 22 additions & 0 deletions app/Listeners/SuppressMailNotificationListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Listeners;

use App\Models\User;
use Illuminate\Notifications\Events\NotificationSending;

class SuppressMailNotificationListener
{
public function handle(NotificationSending $event): bool
{
if ($event->channel !== 'mail') {
return true;
}

if (! $event->notifiable instanceof User) {
return true;
}

return $event->notifiable->receives_notification_emails;
}
}
20 changes: 20 additions & 0 deletions app/Livewire/Customer/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
use Illuminate\Support\Facades\Hash;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Attributes\Url;
use Livewire\Component;

#[Layout('components.layouts.dashboard')]
#[Title('Settings')]
class Settings extends Component
{
#[Url]
public string $tab = 'account';

public string $name = '';

public string $currentPassword = '';
Expand All @@ -22,9 +26,25 @@ class Settings extends Component

public string $deleteConfirmPassword = '';

public bool $receivesNotificationEmails = true;

public bool $receivesNewPluginNotifications = true;

public function mount(): void
{
$this->name = auth()->user()->name ?? '';
$this->receivesNotificationEmails = auth()->user()->receives_notification_emails;
$this->receivesNewPluginNotifications = auth()->user()->receives_new_plugin_notifications;
}

public function updatedReceivesNotificationEmails(bool $value): void
{
auth()->user()->update(['receives_notification_emails' => $value]);
}

public function updatedReceivesNewPluginNotifications(bool $value): void
{
auth()->user()->update(['receives_new_plugin_notifications' => $value]);
}

public function updateName(): void
Expand Down
12 changes: 12 additions & 0 deletions app/Models/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Enums\PluginTier;
use App\Enums\PluginType;
use App\Enums\PriceTier;
use App\Notifications\NewPluginAvailable;
use App\Notifications\PluginApproved;
use App\Notifications\PluginRejected;
use App\Services\PluginSyncService;
Expand All @@ -20,6 +21,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Facades\Notification;

class Plugin extends Model
{
Expand Down Expand Up @@ -497,6 +499,7 @@ public function getRepositoryOwnerAndName(): ?array
public function approve(int $approvedById): void
{
$previousStatus = $this->status;
$isFirstApproval = $this->approved_at === null;

$this->update([
'status' => PluginStatus::Approved,
Expand All @@ -515,6 +518,15 @@ public function approve(int $approvedById): void

$this->user->notify(new PluginApproved($this));

if ($isFirstApproval) {
$recipients = User::query()
->where('receives_new_plugin_notifications', true)
->where('id', '!=', $this->user_id)
->get();

Notification::send($recipients, new NewPluginAvailable($this));
}

resolve(PluginSyncService::class)->sync($this);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ protected function casts(): array
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'receives_notification_emails' => 'boolean',
'receives_new_plugin_notifications' => 'boolean',
'mobile_repo_access_granted_at' => 'datetime',
'claude_plugins_repo_access_granted_at' => 'datetime',
'discord_role_granted_at' => 'datetime',
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/BundleGranted.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
Expand All @@ -53,6 +53,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => "You've been granted the {$this->bundle->name} bundle!",
'body' => "You now have access to {$this->grantedPlugins->count()} plugins in the {$this->bundle->name} bundle.",
'bundle_id' => $this->bundle->id,
'bundle_name' => $this->bundle->name,
'granted_plugin_ids' => $this->grantedPlugins->pluck('id')->toArray(),
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/BundlePluginAdded.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
Expand All @@ -48,6 +48,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => "New plugin added to your {$this->bundle->name} bundle!",
'body' => "{$this->plugin->name} has been added to your bundle — it's yours for free.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
'bundle_id' => $this->bundle->id,
Expand Down
15 changes: 14 additions & 1 deletion app/Notifications/LegacyLicenseThankYou.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ public function __construct(

public function via($notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

/**
* @return array<string, mixed>
*/
public function toArray($notifiable): array
{
return [
'title' => 'Thank You for Making NativePHP Mobile Free',
'body' => 'NativePHP for Mobile is now free for everyone — thanks to early supporters like you.',
'license_id' => $this->license->id,
'license_key' => $this->license->key,
];
}

public function toMail($notifiable): MailMessage
Expand Down
16 changes: 15 additions & 1 deletion app/Notifications/LicenseExpiryWarning.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct(

public function via($notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail($notifiable): MailMessage
Expand All @@ -43,6 +43,20 @@ public function toMail($notifiable): MailMessage
->salutation("Best regards,\nThe NativePHP Team");
}

/**
* @return array<string, mixed>
*/
public function toArray($notifiable): array
{
return [
'title' => $this->getSubject(),
'body' => $this->getMainMessage(),
'license_id' => $this->license->id,
'license_key' => $this->license->key,
'days_until_expiry' => $this->daysUntilExpiry,
];
}

private function getSubject(): string
{
return match ($this->daysUntilExpiry) {
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/LicenseKeyGenerated.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
Expand Down Expand Up @@ -58,6 +58,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => 'Your NativePHP License Key',
'body' => 'Your license key has been generated and is ready to use.',
'license_key' => $this->licenseKey,
'firstName' => $this->firstName,
];
Expand Down
53 changes: 53 additions & 0 deletions app/Notifications/NewPluginAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App\Notifications;

use App\Models\Plugin;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class NewPluginAvailable extends Notification implements ShouldQueue
{
use Queueable;

public function __construct(
public Plugin $plugin
) {}

/**
* @return array<int, string>
*/
public function via(object $notifiable): array
{
if (! $notifiable->receives_new_plugin_notifications) {
return [];
}

return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject("New Plugin: {$this->plugin->name}")
->greeting('A new plugin is available!')
->line("**{$this->plugin->name}** has just been added to the NativePHP Plugin Marketplace.")
->action('View Plugin', url('/plugins'))
->line('You can manage your notification preferences in your account settings.');
}

/**
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'title' => "New Plugin: {$this->plugin->name}",
'body' => "{$this->plugin->name} has just been added to the NativePHP Plugin Marketplace.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
];
}
}
8 changes: 5 additions & 3 deletions app/Notifications/PluginApproved.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

/**
Expand All @@ -34,8 +34,8 @@ public function toMail(object $notifiable): MailMessage
return (new MailMessage)
->subject('Your Plugin Has Been Approved!')
->greeting('Great news!')
->line("Your plugin **{$this->plugin->name}** has been approved and is now listed in the NativePHP Plugin Directory.")
->action('View Plugin Directory', url('/plugins'))
->line("Your plugin **{$this->plugin->name}** has been approved and is now listed in the NativePHP Plugin Marketplace.")
->action('View Plugin Marketplace', url('/plugins'))
->line('Thank you for contributing to the NativePHP ecosystem!');
}

Expand All @@ -47,6 +47,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => 'Your Plugin Has Been Approved!',
'body' => "{$this->plugin->name} is now listed in the NativePHP Plugin Marketplace.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
];
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/PluginGranted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
Expand All @@ -46,6 +46,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => "You've been granted access to {$this->plugin->name}!",
'body' => "You now have access to the {$this->plugin->name} plugin.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
];
Expand Down
6 changes: 4 additions & 2 deletions app/Notifications/PluginRejected.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

/**
Expand All @@ -34,7 +34,7 @@ public function toMail(object $notifiable): MailMessage
return (new MailMessage)
->subject('Plugin Submission Update')
->greeting('Hello,')
->line("Unfortunately, your plugin **{$this->plugin->name}** was not approved for the NativePHP Plugin Directory.")
->line("Unfortunately, your plugin **{$this->plugin->name}** was not approved for the NativePHP Plugin Marketplace.")
->line('**Reason:**')
->line($this->plugin->rejection_reason)
->action('View Your Plugins', route('customer.plugins.index'))
Expand All @@ -49,6 +49,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => 'Plugin Submission Update',
'body' => "Your plugin {$this->plugin->name} was not approved for the NativePHP Plugin Marketplace.",
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
'rejection_reason' => $this->plugin->rejection_reason,
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/PluginReviewChecksIncomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(public Plugin $plugin) {}
*/
public function via(object $notifiable): array
{
return ['mail'];
return ['mail', 'database'];
}

public function toMail(object $notifiable): MailMessage
Expand Down Expand Up @@ -113,6 +113,8 @@ public function toMail(object $notifiable): MailMessage
public function toArray(object $notifiable): array
{
return [
'title' => "Action Required: {$this->plugin->name} — Review Checks",
'body' => 'Some automated checks need your attention before we can approve your plugin.',
'plugin_id' => $this->plugin->id,
'plugin_name' => $this->plugin->name,
];
Expand Down
Loading
Loading