浏览代码

Add Push Notifications

Daniel Supernault 11 月之前
父节点
当前提交
83ce8fd78e
共有 5 个文件被更改,包括 114 次插入2 次删除
  1. 9 1
      app/User.php
  2. 1 0
      composer.json
  3. 65 1
      composer.lock
  4. 3 0
      config/services.php
  5. 36 0
      database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php

+ 9 - 1
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;
+    }
 }

+ 1 - 0
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",

+ 65 - 1
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",

+ 3 - 0
config/services.php

@@ -35,4 +35,7 @@ return [
         'secret' => env('STRIPE_SECRET'),
     ],
 
+    'expo' => [
+        'access_token' => env('EXPO_ACCESS_TOKEN'),
+    ],
 ];

+ 36 - 0
database/migrations/2024_07_22_065800_add_expo_token_to_users_table.php

@@ -0,0 +1,36 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('users', function (Blueprint $table) {
+            $table->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');
+        });
+    }
+};