-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,064 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Filament\Notifications; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
{ | ||
/* | ||
* @method static static sendToFCM(Model $user, array $data=[]) | ||
* @method static static sendToEmail(Model $user) | ||
* @method static static sendToSlack(Model $user) | ||
* @method static static sendToDiscord(Model $user) | ||
* @method static static sendToSMSMisr(Model $user) | ||
* @method static static sendToFCM(Model $user) | ||
*/ | ||
class Notification | ||
{ | ||
public function sendToFCM(Model $user, array $data=[]): static {} | ||
public function sendToEmail(Model $user): static {} | ||
public function sendToSlack(Model $user): static {} | ||
public function sendToDiscord(Model $user): static {} | ||
public function sendToSMSMisr(Model $user): static {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
database/migrations/2024_06_10_031705_notifications_sound_settings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
use Spatie\LaravelSettings\Migrations\SettingsMigration; | ||
|
||
return new class extends SettingsMigration | ||
{ | ||
public function up(): void | ||
{ | ||
$this->migrator->add('notifications.notifications_sound', null); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@if($url) | ||
<a href="{{ $url }}" target="_blank"> | ||
{!! $content !!} | ||
</a> | ||
@else | ||
{!! $content !!} | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<div> | ||
|
||
</div> | ||
<script type="module"> | ||
import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js' | ||
import {getMessaging, onMessage, getToken} from "https://www.gstatic.com/firebasejs/10.12.2/firebase-messaging.js"; | ||
const firebaseConfig = { | ||
apiKey: "{{ setting('fcm_apiKey') }}", | ||
authDomain: "{{ setting('fcm_authDomain') }}", | ||
databaseURL: "{{ setting('fcm_database_url') }}", | ||
projectId: "{{ setting('fcm_projectId') }}", | ||
storageBucket: "{{ setting('fcm_storageBucket') }}", | ||
messagingSenderId: "{{ setting('fcm_messagingSenderId') }}", | ||
appId: "{{ setting('fcm_appId') }}", | ||
measurementId: "{{ setting('fcm_measurementId') }}", | ||
}; | ||
const app = initializeApp(firebaseConfig); | ||
const messaging = getMessaging(app); | ||
Notification.requestPermission().then((permission) => { | ||
if (permission === "granted") { | ||
console.log("Notification permission granted."); | ||
if ("serviceWorker" in navigator) { | ||
navigator.serviceWorker | ||
.register("/firebase-messaging-sw.js") | ||
.then(function (registration) { | ||
console.log( | ||
"Registration successful, scope is:", | ||
registration.scope | ||
); | ||
}) | ||
.catch(function (err) { | ||
console.log( | ||
"Service worker registration failed, error:", | ||
err | ||
); | ||
}); | ||
} | ||
navigator.serviceWorker.getRegistration().then(async (reg) => { | ||
let token = await getToken(messaging, {vapidKey: "{{ setting('fcm_vapid') }}"}); | ||
console.log(token); | ||
Livewire.dispatch('fcm-token', { token: token }); | ||
onMessage(messaging, (payload) => { | ||
console.log("message: ", payload); | ||
var audio = new Audio('https://devsuez.emalleg.net/storage/sound/notifications.mp3'); | ||
audio.play(); | ||
console.log(payload); | ||
Livewire.dispatch('fcm-notification', {data: payload}) | ||
// push notification can send event.data.json() as well | ||
const options = { | ||
body: payload.data.body, | ||
icon: payload.data.image, | ||
tag: "alert", | ||
}; | ||
let notification = reg.showNotification( | ||
payload.data.title, | ||
options | ||
); | ||
// link to page on clicking the notification | ||
notification.onclick = (payload) => { | ||
window.open(payload.data.url); | ||
}; | ||
}); | ||
}); | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@livewire(\TomatoPHP\FilamentAlerts\Livewire\Firebase::class) | ||
|
||
|
Oops, something went wrong.