mirror of
https://github.com/liamcottle/reticulum-meshchat.git
synced 2026-04-28 00:20:48 +00:00
clean up notification code
This commit is contained in:
parent
870fc72f09
commit
4a92d44991
3 changed files with 31 additions and 16 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
27
src/frontend/js/NotificationUtils.js
Normal file
27
src/frontend/js/NotificationUtils.js
Normal 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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue