From 83ce8fd78e56bc31d1b038bb8b35dcfa7bbeca47 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 22 Jul 2024 01:13:59 -0600 Subject: [PATCH] Add Push Notifications --- app/User.php | 10 ++- composer.json | 1 + composer.lock | 66 ++++++++++++++++++- config/services.php | 3 + ...2_065800_add_expo_token_to_users_table.php | 36 ++++++++++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php diff --git a/app/User.php b/app/User.php index a39f650be..6ec31e969 100644 --- a/app/User.php +++ b/app/User.php @@ -8,10 +8,13 @@ use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Util\RateLimit\User as UserRateLimit; use App\Services\AvatarService; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use NotificationChannels\WebPush\HasPushSubscriptions; +use NotificationChannels\Expo\ExpoPushToken; class User extends Authenticatable { - use Notifiable, SoftDeletes, HasApiTokens, UserRateLimit; + use Notifiable, SoftDeletes, HasApiTokens, UserRateLimit, HasFactory, HasPushSubscriptions; /** * The attributes that should be mutated to dates. @@ -23,6 +26,7 @@ class User extends Authenticatable 'email_verified_at' => 'datetime', '2fa_setup_at' => 'datetime', 'last_active_at' => 'datetime', + 'expo_token' => ExpoPushToken::class ]; /** @@ -115,4 +119,8 @@ class User extends Authenticatable return AvatarService::get($this->profile_id); } + public function routeNotificationForExpo(): ?ExpoPushToken + { + return $this->expo_token; + } } diff --git a/composer.json b/composer.json index 24112cbf9..dbe6a62e7 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "doctrine/dbal": "^3.0", "intervention/image": "^2.4", "jenssegers/agent": "^2.6", + "laravel-notification-channels/expo": "^2.0", "laravel-notification-channels/webpush": "^8.0", "laravel/framework": "^11.0", "laravel/helpers": "^1.1", diff --git a/composer.lock b/composer.lock index 12fde064d..882eb34d8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "55dc6d48024fd1d158f8777eda3ea624", + "content-hash": "53a815fd998a7264135d59184253d0de", "packages": [ { "name": "aws/aws-crt-php", @@ -2247,6 +2247,70 @@ ], "time": "2020-06-13T08:05:20+00:00" }, + { + "name": "laravel-notification-channels/expo", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/laravel-notification-channels/expo.git", + "reference": "29d038b6409077ac4c671cc5587a4dc7986260b0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel-notification-channels/expo/zipball/29d038b6409077ac4c671cc5587a4dc7986260b0", + "reference": "29d038b6409077ac4c671cc5587a4dc7986260b0", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/guzzle": "^7.1", + "illuminate/contracts": "^11.0", + "illuminate/notifications": "^11.0", + "illuminate/support": "^11.0", + "php": "~8.3" + }, + "require-dev": { + "larastan/larastan": "^2.0", + "laravel/pint": "^1.0", + "orchestra/testbench": "^9.0", + "phpunit/phpunit": "^11.0" + }, + "suggest": { + "ext-zlib": "Required for compressing payloads exceeding 1 KiB in size." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "NotificationChannels\\Expo\\ExpoServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "NotificationChannels\\Expo\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Muhammed Sari", + "email": "muhammed@dive.be", + "homepage": "https://dive.be", + "role": "Developer" + } + ], + "description": "Expo Notifications Channel for Laravel", + "homepage": "https://github.com/laravel-notification-channels/expo", + "support": { + "issues": "https://github.com/laravel-notification-channels/expo/issues", + "source": "https://github.com/laravel-notification-channels/expo/tree/v2.0.0" + }, + "time": "2024-03-18T07:49:28+00:00" + }, { "name": "laravel-notification-channels/webpush", "version": "8.0.0", diff --git a/config/services.php b/config/services.php index 58db77fe5..8f00697b5 100644 --- a/config/services.php +++ b/config/services.php @@ -35,4 +35,7 @@ return [ 'secret' => env('STRIPE_SECRET'), ], + 'expo' => [ + 'access_token' => env('EXPO_ACCESS_TOKEN'), + ], ]; diff --git a/database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php b/database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php new file mode 100644 index 000000000..4f7c4688d --- /dev/null +++ b/database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php @@ -0,0 +1,36 @@ +string('expo_token')->nullable(); + $table->boolean('notify_like')->default(true); + $table->boolean('notify_follow')->default(true); + $table->boolean('notify_mention')->default(true); + $table->boolean('notify_comment')->default(true); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('expo_token'); + $table->dropColumn('notify_like'); + $table->dropColumn('notify_follow'); + $table->dropColumn('notify_mention'); + $table->dropColumn('notify_comment'); + }); + } +};