clean up notification code

This commit is contained in:
liamcottle 2024-08-06 01:06:25 +12:00
commit 4a92d44991
3 changed files with 31 additions and 16 deletions

View file

@ -257,6 +257,7 @@ import WebSocketConnection from "../js/WebSocketConnection";
import GlobalState from "../js/GlobalState";
import Utils from "../js/Utils";
import GlobalEmitter from "../js/GlobalEmitter";
import NotificationUtils from "../js/NotificationUtils";
export default {
name: 'App',
@ -312,14 +313,7 @@ export default {
break;
}
case 'incoming_audio_call': {
Notification.requestPermission().then((result) => {
if(result === "granted"){
new window.Notification("Incoming Call", {
body: "Someone is calling you.",
tag: "new_audio_call", // only ever show one notification at a time
});
}
});
NotificationUtils.showIncomingCallNotification();
break;
}
}

View file

@ -342,6 +342,7 @@
<script>
import Utils from "../../js/Utils";
import DialogUtils from "../../js/DialogUtils";
import NotificationUtils from "../../js/NotificationUtils";
export default {
name: 'ConversationViewer',
@ -422,14 +423,7 @@ export default {
// show notification for new messages if window is not focussed
if(!document.hasFocus()){
Notification.requestPermission().then((result) => {
if(result === "granted"){
new window.Notification("New Message", {
body: "Someone sent you a message.",
tag: "new_message", // only ever show one notification at a time
});
}
});
NotificationUtils.showNewMessageNotification();
}
// auto scroll to bottom if we want to

View file

@ -0,0 +1,27 @@
class NotificationUtils {
static showIncomingCallNotification() {
Notification.requestPermission().then((result) => {
if(result === "granted"){
new window.Notification("Incoming Call", {
body: "Someone is calling you.",
tag: "new_audio_call", // only ever show one incoming call notification at a time
});
}
});
}
static showNewMessageNotification() {
Notification.requestPermission().then((result) => {
if(result === "granted"){
new window.Notification("New Message", {
body: "Someone sent you a message.",
tag: "new_message", // only ever show one new message notification at a time
});
}
});
}
}
export default NotificationUtils;