-
Notifications
You must be signed in to change notification settings - Fork 204
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
1 parent
04ce7a1
commit eb6376e
Showing
8 changed files
with
246 additions
and
8 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
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,53 @@ | ||
// Any other custom service worker logic can go here. | ||
|
||
self.addEventListener("push", async function (event) { | ||
if (event.data) { | ||
const data = event.data.json(); | ||
const notificationOptions = { | ||
body: data.body || "Sample Body", | ||
tag: data.external_id || "default-tag", | ||
}; | ||
|
||
event.waitUntil( | ||
self.registration.showNotification("OpenELIS Test Message Received", notificationOptions) | ||
); | ||
} | ||
}); | ||
|
||
// This allows the web app to trigger skipWaiting via | ||
// registration.waiting.postMessage({type: 'SKIP_WAITING'}) | ||
self.addEventListener("message", (event) => { | ||
if (event.data && event.data.type === "SKIP_WAITING") { | ||
self.skipWaiting(); | ||
} | ||
}); | ||
|
||
|
||
// self.addEventListener('push', (e) => { | ||
// const data = e.data?.json(); | ||
// if (data) { | ||
// self.registration.showNotification(data.title, { | ||
// body: data.body, | ||
// }); | ||
// } | ||
// }); | ||
|
||
// self.addEventListener('notificationclick', (e) => { | ||
// e.notification.close(); | ||
// e.waitUntil(focusOrOpenWindow()); | ||
// }); | ||
|
||
// async function focusOrOpenWindow() { | ||
// const url = new URL('/', self.location.origin).href; | ||
|
||
// const allWindows = await self.clients.matchAll({ | ||
// type: 'window', | ||
// }); | ||
// const appWindow = allWindows.find((w) => w.url === url); | ||
|
||
// if (appWindow) { | ||
// return appWindow.focus(); | ||
// } else { | ||
// return self.clients.openWindow(url); | ||
// } | ||
// } |
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,28 @@ | ||
// Function to register the service worker | ||
export function registerServiceWorker() { | ||
if ('serviceWorker' in navigator) { | ||
window.addEventListener('load', () => { | ||
const swUrl = `./service-worker.js`; | ||
|
||
navigator.serviceWorker | ||
.register(swUrl) | ||
.then((registration) => { | ||
console.log('Service Worker registered with scope:', registration.scope); | ||
}) | ||
.catch((error) => { | ||
console.error('Service Worker registration failed:', error); | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
// Function to unregister the service worker | ||
export function unregisterServiceWorker() { | ||
if ('serviceWorker' in navigator) { | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.unregister().then((boolean) => { | ||
console.log('Service Worker unregistered:', boolean); | ||
}); | ||
}); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/org/openelisglobal/notifications/entity/NotificationSubscription.java
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,78 @@ | ||
package org.openelisglobal.notifications.entity; | ||
|
||
import javax.persistence.*; | ||
import org.openelisglobal.systemuser.valueholder.SystemUser; | ||
|
||
@Entity | ||
@Table(name = "notification_subscriptions") | ||
public class NotificationSubscription { | ||
|
||
@Id | ||
@Column(name = "user_id") | ||
private Long userId; | ||
|
||
@Column(name = "pf_endpoint", nullable = false) | ||
private String pfEndpoint; | ||
|
||
@Column(name = "pf_p256dh", nullable = false) | ||
private String pfP256dh; | ||
|
||
@Column(name = "pf_auth", nullable = false) | ||
private String pfAuth; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@MapsId | ||
@JoinColumn(name = "user_id", nullable = false) | ||
private SystemUser user; | ||
|
||
public Long getUserId() { | ||
return userId; | ||
} | ||
|
||
public void setUserId(Long userId) { | ||
this.userId = userId; | ||
} | ||
|
||
public String getPfEndpoint() { | ||
return pfEndpoint; | ||
} | ||
|
||
public void setPfEndpoint(String pfEndpoint) { | ||
this.pfEndpoint = pfEndpoint; | ||
} | ||
|
||
public String getPfP256dh() { | ||
return pfP256dh; | ||
} | ||
|
||
public void setPfP256dh(String pfP256dh) { | ||
this.pfP256dh = pfP256dh; | ||
} | ||
|
||
public String getPfAuth() { | ||
return pfAuth; | ||
} | ||
|
||
public void setPfAuth(String pfAuth) { | ||
this.pfAuth = pfAuth; | ||
} | ||
|
||
public SystemUser getUser() { | ||
return user; | ||
} | ||
|
||
public void setUser(SystemUser user) { | ||
this.user = user; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "NotificationSubscription{" + | ||
"userId=" + userId + | ||
", pfEndpoint='" + pfEndpoint + '\'' + | ||
", pfP256dh='" + pfP256dh + '\'' + | ||
", pfAuth='" + pfAuth + '\'' + | ||
", user=" + (user != null ? user.toString() : "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
29 changes: 29 additions & 0 deletions
29
src/main/resources/liquibase/2.8.x.x/notificationsubsriptions.xml
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,29 @@ | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> | ||
|
||
<changeSet id="create_notification_subscriptions_table" author="clinlims"> | ||
<createTable tableName="notification_subscriptions"> | ||
<column name="user_id" type="NUMERIC(10,0)"> | ||
<constraints primaryKey="true" nullable="false"/> | ||
</column> | ||
<column name="pf_endpoint" type="VARCHAR(255)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="pf_p256dh" type="VARCHAR(255)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
<column name="pf_auth" type="VARCHAR(255)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</createTable> | ||
|
||
<addForeignKeyConstraint baseTableName="notification_subscriptions" | ||
baseColumnNames="user_id" | ||
referencedTableName="system_user" | ||
referencedColumnNames="id" | ||
constraintName="fk_notification_subscriptions_user_id"/> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |