Merge branch '419-push-notifications' into 'dev'
Show new message browser notification when chat message tab is not active. See merge request keanuapp/keanuapp-weblite!203
This commit is contained in:
commit
37c254f8e1
2 changed files with 46 additions and 2 deletions
45
src/App.vue
45
src/App.vue
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import stickers from "./plugins/stickers";
|
import stickers from "./plugins/stickers";
|
||||||
|
import logoMixin from "./components/logoMixin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
|
|
@ -41,6 +42,7 @@ export default {
|
||||||
availableJsonTranslation: null
|
availableJsonTranslation: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
mixins: [logoMixin],
|
||||||
beforeMount() {
|
beforeMount() {
|
||||||
this.setDefaultLanguage();
|
this.setDefaultLanguage();
|
||||||
},
|
},
|
||||||
|
|
@ -111,9 +113,43 @@ export default {
|
||||||
|
|
||||||
// Set language
|
// Set language
|
||||||
this.$i18n.locale = this.$store.state.language || "en";
|
this.$i18n.locale = this.$store.state.language || "en";
|
||||||
|
},
|
||||||
|
showNotification() {
|
||||||
|
if(document.visibilityState === "visible") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const title = this.$t('notification.title');
|
||||||
|
const notification = new Notification(title, {icon: this.logotype});
|
||||||
|
notification.onclick = () => {
|
||||||
|
notification.close();
|
||||||
|
window.parent.focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
requestAndShowPermission(notificationCount) {
|
||||||
|
Notification.requestPermission(function (permission) {
|
||||||
|
if(notificationCount > 0 && permission === "granted") {
|
||||||
|
this.showNotification();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
requestNotificationPermission(notificationCount) {
|
||||||
|
if ('Notification' in window) {
|
||||||
|
Notification.requestPermission().then((permission) => {
|
||||||
|
if(notificationCount > 0 && permission === 'granted') {
|
||||||
|
this.showNotification();
|
||||||
|
} else if(permission === "default") {
|
||||||
|
this.requestAndShowPermission(notificationCount);
|
||||||
|
} else {
|
||||||
|
this.requestAndShowPermission(notificationCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
notificationCount() {
|
||||||
|
return this.$matrix.notificationCount
|
||||||
|
},
|
||||||
currentUser() {
|
currentUser() {
|
||||||
return this.$store.state.auth.user;
|
return this.$store.state.auth.user;
|
||||||
},
|
},
|
||||||
|
|
@ -126,8 +162,8 @@ export default {
|
||||||
},
|
},
|
||||||
title() {
|
title() {
|
||||||
var title = this.appName;
|
var title = this.appName;
|
||||||
if (this.$matrix.notificationCount > 0) {
|
if (this.notificationCount > 0) {
|
||||||
title += " [" + this.$matrix.notificationCount + "]";
|
title += " [" + this.notificationCount + "]";
|
||||||
}
|
}
|
||||||
if (this.$route.meta.title) {
|
if (this.$route.meta.title) {
|
||||||
title += " - " + this.$route.meta.title;
|
title += " - " + this.$route.meta.title;
|
||||||
|
|
@ -182,6 +218,11 @@ export default {
|
||||||
},
|
},
|
||||||
immediate: true,
|
immediate: true,
|
||||||
},
|
},
|
||||||
|
notificationCount: {
|
||||||
|
handler(nCount) {
|
||||||
|
this.requestNotificationPermission(nCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -344,6 +344,9 @@
|
||||||
"processed_n_of_total_events": "Processed media for {count} of {total} events",
|
"processed_n_of_total_events": "Processed media for {count} of {total} events",
|
||||||
"export_filename": "Exported chat {date}"
|
"export_filename": "Exported chat {date}"
|
||||||
},
|
},
|
||||||
|
"notification": {
|
||||||
|
"title": "New message received"
|
||||||
|
},
|
||||||
"emoji": {
|
"emoji": {
|
||||||
"search": "Search...",
|
"search": "Search...",
|
||||||
"categories": {
|
"categories": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue