From 96af1b7c45eb6fc75c45041bb18329cca5602139 Mon Sep 17 00:00:00 2001 From: Page David Date: Fri, 7 Jul 2017 08:35:30 +0800 Subject: [PATCH 1/5] add notification sending base --- fishroom/web/chat_log.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fishroom/web/chat_log.html b/fishroom/web/chat_log.html index 9b1399d..2b1bf67 100644 --- a/fishroom/web/chat_log.html +++ b/fishroom/web/chat_log.html @@ -125,6 +125,19 @@

Loading ...

msg.id = fishLogData.current_id; fishLogData.current_id++; fishLogData.msgs.push(msg); + // Notification sending... + var noti_title = msg.sender + "sent a new message"; + if (Notification.permission === "granted") { + var notification = new Notification(noti_title); + } + + else if (Notification.permission !== "denied") { + Notification.requestPermission(function (permission) { + if (permission === "granted") { + var notification = new Notification(noti_title); + } + }); + } } var fetchLog = function(limit, lastId, scrollDown) { From b185f3d73f23c6be08cd8a10e8b339af61128ed3 Mon Sep 17 00:00:00 2001 From: Page David Date: Fri, 7 Jul 2017 09:20:44 +0800 Subject: [PATCH 2/5] add compacity check and string format error --- fishroom/web/chat_log.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fishroom/web/chat_log.html b/fishroom/web/chat_log.html index 2b1bf67..e8d4319 100644 --- a/fishroom/web/chat_log.html +++ b/fishroom/web/chat_log.html @@ -126,8 +126,13 @@

Loading ...

fishLogData.current_id++; fishLogData.msgs.push(msg); // Notification sending... - var noti_title = msg.sender + "sent a new message"; - if (Notification.permission === "granted") { + var noti_title = msg.sender + " sent a new message"; + var noti_support = True; //prevent send multiple times + if (!("Notification" in window) && noti_support) { + alert("Your browser does not support Notification."); + noti_support = False; + } + else if (Notification.permission === "granted") { var notification = new Notification(noti_title); } From d8804f620d4818c45201b6b61939e289d5f9af70 Mon Sep 17 00:00:00 2001 From: Page David Date: Fri, 7 Jul 2017 09:25:08 +0800 Subject: [PATCH 3/5] True to true.. --- fishroom/web/chat_log.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fishroom/web/chat_log.html b/fishroom/web/chat_log.html index e8d4319..2288c1d 100644 --- a/fishroom/web/chat_log.html +++ b/fishroom/web/chat_log.html @@ -127,10 +127,10 @@

Loading ...

fishLogData.msgs.push(msg); // Notification sending... var noti_title = msg.sender + " sent a new message"; - var noti_support = True; //prevent send multiple times + var noti_support = true; //prevent send multiple times if (!("Notification" in window) && noti_support) { alert("Your browser does not support Notification."); - noti_support = False; + noti_support = false; } else if (Notification.permission === "granted") { var notification = new Notification(noti_title); From c6c494c99dd3508992c1c95a6c75beab39c9e1be Mon Sep 17 00:00:00 2001 From: Hui Yiqun Date: Fri, 7 Jul 2017 09:34:49 +0800 Subject: [PATCH 4/5] remove alert alert is too verbose, just ignore it. --- fishroom/web/chat_log.html | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fishroom/web/chat_log.html b/fishroom/web/chat_log.html index 2288c1d..a5399b1 100644 --- a/fishroom/web/chat_log.html +++ b/fishroom/web/chat_log.html @@ -126,22 +126,19 @@

Loading ...

fishLogData.current_id++; fishLogData.msgs.push(msg); // Notification sending... - var noti_title = msg.sender + " sent a new message"; - var noti_support = true; //prevent send multiple times - if (!("Notification" in window) && noti_support) { - alert("Your browser does not support Notification."); - noti_support = false; - } - else if (Notification.permission === "granted") { - var notification = new Notification(noti_title); - } + var notification = 'New message from ' + msg.sender; + if ('Notification' in window) { + if (Notification.permission === 'granted') { + var notification = new Notification(notification); + } - else if (Notification.permission !== "denied") { - Notification.requestPermission(function (permission) { - if (permission === "granted") { - var notification = new Notification(noti_title); - } - }); + else if (Notification.permission !== 'denied') { + Notification.requestPermission(function (permission) { + if (permission === 'granted') { + var notification = new Notification(notification); + } + }); + } } } From 6f441d1505a81e145349c3f09c201d0d8a906b8f Mon Sep 17 00:00:00 2001 From: Page-David Date: Sat, 8 Jul 2017 22:39:09 +0800 Subject: [PATCH 5/5] Solve variable conflict --- fishroom/web/chat_log.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fishroom/web/chat_log.html b/fishroom/web/chat_log.html index a5399b1..8a9c237 100644 --- a/fishroom/web/chat_log.html +++ b/fishroom/web/chat_log.html @@ -126,16 +126,16 @@

Loading ...

fishLogData.current_id++; fishLogData.msgs.push(msg); // Notification sending... - var notification = 'New message from ' + msg.sender; + var notification_title = 'New message from ' + msg.sender; if ('Notification' in window) { if (Notification.permission === 'granted') { - var notification = new Notification(notification); + var notification = new Notification(notification_title); } else if (Notification.permission !== 'denied') { Notification.requestPermission(function (permission) { if (permission === 'granted') { - var notification = new Notification(notification); + var notification = new Notification(notification_title); } }); }