You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2020/12/28 15:05:44 UTC

[openmeetings] branch master updated: [OPENMEETINGS-2542] notifications in FF are improved

This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new 77293cb  [OPENMEETINGS-2542] notifications in FF are improved
77293cb is described below

commit 77293cbfcc6541ae24e49afc7adac6e446a36749
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Mon Dec 28 22:05:28 2020 +0700

    [OPENMEETINGS-2542] notifications in FF are improved
---
 openmeetings-web/src/main/front/chat/src/chat.js   | 24 ++++++---------
 .../src/main/front/main/src/omutils.js             | 36 ++++++++++++++++++----
 .../src/main/front/room/src/activities.js          | 15 ++-------
 3 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/openmeetings-web/src/main/front/chat/src/chat.js b/openmeetings-web/src/main/front/chat/src/chat.js
index 74c9d33..99ea213 100644
--- a/openmeetings-web/src/main/front/chat/src/chat.js
+++ b/openmeetings-web/src/main/front/chat/src/chat.js
@@ -322,20 +322,7 @@ function _addMessage(m) {
 		if (notify) {
 			ctrlBlk.addClass('bg-warning');
 			if (p.is(':visible') && !muted) {
-				if (window === window.parent) {
-					function _newMessage() {
-						OmUtil.notify(newMsgNotification, 'new_chat_msg');
-					}
-					if (Notification.permission === 'granted') {
-						_newMessage();
-					} else if (Notification.permission !== 'denied') {
-						Notification.requestPermission().then(permission => {
-							if (permission === 'granted') {
-								_newMessage();
-							}
-						});
-					}
-				} else {
+				OmUtil.notify(newMsgNotification, 'new_chat_msg', () => {
 					// impossible to use Notification API from iFrame
 					audio.play()
 						.then(function() {
@@ -343,7 +330,7 @@ function _addMessage(m) {
 						}).catch(function() {
 							// Automatic playback failed.
 						});
-				}
+				});
 			}
 		}
 		CSSEmoticon.animate();
@@ -521,6 +508,13 @@ $(function() {
 			//no-op
 		}
 	});
+	function _cancelAskNotification() {
+		$(document).off('click', _askNotification)
+	}
+	function _askNotification() {
+		OmUtil.requestNotifyPermission(_cancelAskNotification, _cancelAskNotification);
+	}
+	$(document).on('click', _askNotification);
 });
 
 module.exports = {
diff --git a/openmeetings-web/src/main/front/main/src/omutils.js b/openmeetings-web/src/main/front/main/src/omutils.js
index eebc3df..d70d9b7 100644
--- a/openmeetings-web/src/main/front/main/src/omutils.js
+++ b/openmeetings-web/src/main/front/main/src/omutils.js
@@ -47,6 +47,34 @@ function _sendMessage(_m, _base) {
 		, msg = JSON.stringify($.extend({}, base, m));
 	Wicket.WebSocket.send(msg);
 }
+function _requestNotifyPermission(callback, elseCallback) {
+	if (Notification.permission !== 'granted' && Notification.permission !== 'denied') {
+		Notification.requestPermission().then(permission => {
+			if (permission === 'granted') {
+				callback();
+			}
+		});
+	} else if (typeof(elseCallback) === 'function') {
+		elseCallback();
+	}
+}
+function _notify(msg, tag, elseCallback) {
+	if (window === window.parent) {
+		function _newMessage() {
+			const opts = {
+					tag: tag
+				};
+			new Notification(msg, opts);
+		}
+		if (Notification.permission === 'granted') {
+			_newMessage();
+		} else {
+			_requestNotifyPermission(() => _newMessage());
+		}
+	} else if (typeof(elseCallback) === 'function') {
+		elseCallback();
+	}
+}
 
 module.exports = {
 	init: _init
@@ -74,10 +102,6 @@ module.exports = {
 	, ping: function() {
 		setTimeout(() => _sendMessage({type: 'ping'}), 30000);
 	}
-	, notify: function(msg, tag) {
-		const opts = {
-				tag: tag
-			};
-		new Notification(msg, opts);
-	}
+	, notify: _notify
+	, requestNotifyPermission: _requestNotifyPermission
 };
diff --git a/openmeetings-web/src/main/front/room/src/activities.js b/openmeetings-web/src/main/front/room/src/activities.js
index c7b26a3..4c26d40 100644
--- a/openmeetings-web/src/main/front/room/src/activities.js
+++ b/openmeetings-web/src/main/front/room/src/activities.js
@@ -79,19 +79,8 @@ function _hightlight(notify) {
 	}
 	if (isClosed()) {
 		$('.control.block', activities).addClass('bg-warning');
-		if (window === window.parent && notify) {
-			function _newMessage() {
-				OmUtil.notify(newActNotification, 'new_aa_item');
-			}
-			if (Notification.permission === 'granted') {
-				_newMessage();
-			} else if (Notification.permission !== 'denied') {
-				Notification.requestPermission().then(permission => {
-					if (permission === 'granted') {
-						_newMessage();
-					}
-				});
-			}
+		if (notify) {
+			OmUtil.notify(newActNotification, 'new_aa_item');
 		}
 	}
 }