diff --git a/public/libs/angular-inview/angular-inview.js b/public/libs/angular-inview/angular-inview.js
index 5dadbe804..1d2cf2621 100644
--- a/public/libs/angular-inview/angular-inview.js
+++ b/public/libs/angular-inview/angular-inview.js
@@ -69,6 +69,11 @@ function inViewDirective ($parse) {
viewportEventSignal = viewportEventSignal.merge(signalFromEvent(document, 'visibilitychange'));
}
+ // Merged with the page focus/blur events
+ if (options.considerPageFocus) {
+ viewportEventSignal = viewportEventSignal.merge(signalFromEvent(window, 'focus blur'));
+ }
+
// Merge with container's events signal
if (container) {
viewportEventSignal = viewportEventSignal.merge(container.eventsSignal);
@@ -100,8 +105,9 @@ function inViewDirective ($parse) {
var elementRect = offsetRect(element[0].getBoundingClientRect(), options.offset);
var isVisible = !!(element[0].offsetWidth || element[0].offsetHeight || element[0].getClientRects().length);
var documentVisible = !options.considerPageVisibility || document.visibilityState === 'visible' || document.hidden === false;
+ var documentFocussed = !options.considerPageFocus || document.hasFocus();
var info = {
- inView: documentVisible && isVisible && intersectRect(elementRect, viewportRect),
+ inView: documentVisible && documentFocussed && isVisible && intersectRect(elementRect, viewportRect),
event: event,
element: element,
elementRect: elementRect,
diff --git a/src/partials/messenger.conversation.html b/src/partials/messenger.conversation.html
index dd3b22a0f..a58d5e4d7 100644
--- a/src/partials/messenger.conversation.html
+++ b/src/partials/messenger.conversation.html
@@ -61,7 +61,7 @@
messenger.PRIVATE_CHAT
+ in-view-options="{ considerPageFocus: true }">
diff --git a/src/services/browser.ts b/src/services/browser.ts
index 246468555..270f5d941 100644
--- a/src/services/browser.ts
+++ b/src/services/browser.ts
@@ -25,7 +25,6 @@ export class BrowserService {
private browser: BrowserInfo;
private $log: ng.ILogService;
private $window: ng.IWindowService;
- private isPageVisible = true;
private supportsExtendedLocaleCompareCache: boolean;
public static $inject = ['$log', '$window'];
@@ -33,59 +32,6 @@ export class BrowserService {
// Angular services
this.$log = $log;
this.$window = $window;
- this.initializePageVisibility();
- }
-
- private initializePageVisibility() {
- const onChange = (isVisible: any) => {
- if (this.isPageVisible !== isVisible) {
- this.isPageVisible = isVisible;
- }
- };
-
- let pageHiddenKey = 'hidden';
-
- // add default visibility change listener
- let defaultListener;
- if (pageHiddenKey in document) {
- defaultListener = 'visibilitychange';
- } else if ('mozHidden' in document) {
- pageHiddenKey = 'mozHidden';
- defaultListener = 'mozvisibilitychange';
- } else if ('webkitHidden' in document) {
- pageHiddenKey = 'webkitHidden';
- defaultListener = 'webkitvisibilitychange';
- } else if ('msHidden' in document) {
- pageHiddenKey = 'msHidden';
- defaultListener = 'msvisibilitychange';
- }
-
- document.addEventListener(defaultListener, function() {
- onChange(!this[pageHiddenKey]);
- });
-
- // configure other document and window events
- const map = {
- focus: true,
- blur: false,
- };
-
- for (const event in map) {
- if (map[event] !== undefined) {
- document.addEventListener(event, () => {
- onChange(map[event]);
- }, false);
-
- window.addEventListener(event, () => {
- onChange(map[event]);
- }, false);
- }
- }
-
- // initial visible state set
- if (document[pageHiddenKey] !== undefined ) {
- onChange(!document[pageHiddenKey]);
- }
}
public getBrowser(): BrowserInfo {
@@ -183,10 +129,6 @@ export class BrowserService {
return this.browser;
}
- public isVisible() {
- return this.isPageVisible;
- }
-
/**
* Return whether the current browser supports the WebRTC task or not.
*/
diff --git a/src/services/webclient.ts b/src/services/webclient.ts
index cc9354639..e15425f2f 100644
--- a/src/services/webclient.ts
+++ b/src/services/webclient.ts
@@ -3212,7 +3212,7 @@ export class WebClientService {
sender: threema.Receiver,
): void {
// Ignore message from active receivers (and if the browser tab is visible)
- if (this.browserService.isVisible()
+ if (document.hasFocus()
&& this.receiverService.compare(conversation, this.receiverService.getActive())) {
return;
}