|
@@ -18,6 +18,8 @@
|
|
|
import Receiver = threema.Receiver;
|
|
|
export class NotificationService implements threema.NotificationService {
|
|
|
|
|
|
+ private logTag: string = '[NotificationService]';
|
|
|
+
|
|
|
private $log: ng.ILogService;
|
|
|
private $window: ng.IWindowService;
|
|
|
private $state: ng.ui.IStateService;
|
|
@@ -45,17 +47,21 @@ export class NotificationService implements threema.NotificationService {
|
|
|
public requestNotificationPermission(): void {
|
|
|
if (!('Notification' in this.$window)) {
|
|
|
// API not available
|
|
|
+ this.$log.warn(this.logTag, 'Notification API not available');
|
|
|
this.mayNotify = null;
|
|
|
} else {
|
|
|
const Notification = this.$window.Notification;
|
|
|
if (Notification.permission === 'granted') {
|
|
|
// Already granted
|
|
|
+ this.$log.debug(this.logTag, 'Notification permission granted');
|
|
|
this.mayNotify = true;
|
|
|
} else if (Notification.permission === 'denied') {
|
|
|
// Not granted
|
|
|
+ this.$log.warn(this.logTag, 'Notification permission denied');
|
|
|
this.mayNotify = false;
|
|
|
} else {
|
|
|
// Ask user
|
|
|
+ this.$log.debug(this.logTag, 'Requesting notification permission');
|
|
|
Notification.requestPermission((result) => {
|
|
|
if (result === 'granted') {
|
|
|
this.mayNotify = true;
|
|
@@ -91,6 +97,7 @@ export class NotificationService implements threema.NotificationService {
|
|
|
}
|
|
|
|
|
|
// Show notification
|
|
|
+ this.$log.debug(this.logTag, 'Showing notification', tag);
|
|
|
const notification = new this.$window.Notification(title, {
|
|
|
icon: avatar,
|
|
|
body: body.trim(),
|
|
@@ -105,6 +112,7 @@ export class NotificationService implements threema.NotificationService {
|
|
|
if (clickCallback !== undefined) {
|
|
|
clickCallback();
|
|
|
}
|
|
|
+ this.$log.debug(this.logTag, 'Hiding notification', tag, 'on click');
|
|
|
notification.close();
|
|
|
this.clearCache(tag);
|
|
|
};
|
|
@@ -115,6 +123,23 @@ export class NotificationService implements threema.NotificationService {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Hide the notification with the specified tag.
|
|
|
+ *
|
|
|
+ * Return whether the notification was hidden.
|
|
|
+ */
|
|
|
+ public hideNotification(tag: string): boolean {
|
|
|
+ const notification = this.notificationCache[tag];
|
|
|
+ if (notification !== undefined) {
|
|
|
+ this.$log.debug(this.logTag, 'Hiding notification', tag);
|
|
|
+ notification.close();
|
|
|
+ this.clearCache(tag);
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Clear the notification cache for the specified tag.
|
|
|
*/
|