-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: send push notification on PWA Notification log insertion
- Loading branch information
1 parent
7e5f298
commit 876a29f
Showing
1 changed file
with
17 additions
and
0 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 |
---|---|---|
@@ -1,10 +1,27 @@ | ||
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors | ||
# For license information, please see license.txt | ||
import frappe | ||
from frappe.model.document import Document | ||
from frappe.push_notification import PushNotification | ||
|
||
import hrms | ||
|
||
|
||
class PWANotification(Document): | ||
def on_update(self): | ||
hrms.refetch_resource("hrms:notifications", self.to_user) | ||
|
||
def after_insert(self): | ||
self.send_push_notification() | ||
|
||
def send_push_notification(self): | ||
try: | ||
url = frappe.utils.get_url() | ||
|
||
push_notification = PushNotification("hrms") | ||
if push_notification.is_enabled(): | ||
push_notification.send_notification_to_user( | ||
self.to_user, self.reference_document_type, self.message, link=url, truncate_body=True | ||
) | ||
except Exception: | ||
self.log_error(f"Error sending push notification: {self.name}") |