Desktop Notifications

This commit is contained in:
franzz committed 2020-09-24 00:22:31 +02:00
1 parent c1663de541
commit 36dc674ba4
5 files changed
+65 -2

No files matched your search

+2 -2
View File
@@ -7,8 +7,8 @@
class Databap extends PhpObject class Databap extends PhpObject
{ {
//Common Constants //Common Constants
const VERSION = '1.1.3'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate> const VERSION = '1.1.4'; //Versioning: <Main_Version>.<Enhancement_Package>.<Patch>-<Release_Candidate>
const VERSION_DATE = '08/12/2019'; const VERSION_DATE = '24/09/2020';
const EXPECTED_PAGE_COOKIE = 'exp_page'; const EXPECTED_PAGE_COOKIE = 'exp_page';
const MAIN_SEPARATOR = ' '; const MAIN_SEPARATOR = ' ';
const DATE_FORMAT = 'd/m/Y'; const DATE_FORMAT = 'd/m/Y';
+39
View File
@@ -0,0 +1,39 @@
/**
* @license
*
* Push v1.0.9
* =========
* A compact, cross-browser solution for the JavaScript Notifications API
*
* Credits
* -------
* Tsvetan Tsvetkov (ttsvetko)
* Alex Gibson (alexgibson)
*
* License
* -------
*
* The MIT License (MIT)
*
* Copyright (c) 2015-2017 Tyler Nickerson
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(i=i||self).Push=t()}(this,function(){"use strict";var i={errors:{incompatible:"".concat("PushError:"," Push.js is incompatible with browser."),invalid_plugin:"".concat("PushError:"," plugin class missing from plugin manifest (invalid plugin). Please check the documentation."),invalid_title:"".concat("PushError:"," title of notification must be a string"),permission_denied:"".concat("PushError:"," permission request declined"),sw_notification_error:"".concat("PushError:"," could not show a ServiceWorker notification due to the following reason: "),sw_registration_error:"".concat("PushError:"," could not register the ServiceWorker due to the following reason: "),unknown_interface:"".concat("PushError:"," unable to create notification: unknown interface")}};function t(i){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(i){return typeof i}:function(i){return i&&"function"==typeof Symbol&&i.constructor===Symbol&&i!==Symbol.prototype?"symbol":typeof i})(i)}function n(i,t){if(!(i instanceof t))throw new TypeError("Cannot call a class as a function")}function e(i,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(i,e.key,e)}}function o(i,t,n){return t&&e(i.prototype,t),n&&e(i,n),i}function r(i,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");i.prototype=Object.create(t&&t.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),t&&c(i,t)}function s(i){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(i){return i.__proto__||Object.getPrototypeOf(i)})(i)}function c(i,t){return(c=Object.setPrototypeOf||function(i,t){return i.__proto__=t,i})(i,t)}function a(i,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(i){if(void 0===i)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return i}(i):t}var u=function(){function i(t){n(this,i),this._win=t,this.GRANTED="granted",this.DEFAULT="default",this.DENIED="denied",this._permissions=[this.GRANTED,this.DEFAULT,this.DENIED]}return o(i,[{key:"request",value:function(i,t){return arguments.length>0?this._requestWithCallback.apply(this,arguments):this._requestAsPromise()}},{key:"_requestWithCallback",value:function(i,t){var n,e=this,o=this.get(),r=!1,s=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e._win.Notification.permission;r||(r=!0,void 0===n&&e._win.webkitNotifications&&(n=e._win.webkitNotifications.checkPermission()),n===e.GRANTED||0===n?i&&i():t&&t())};o!==this.DEFAULT?s(o):this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._win.webkitNotifications.requestPermission(s):this._win.Notification&&this._win.Notification.requestPermission?(n=this._win.Notification.requestPermission(s))&&n.then&&n.then(s).catch(function(){t&&t()}):i&&i()}},{key:"_requestAsPromise",value:function(){var i=this,t=this.get(),n=t!==this.DEFAULT,e=this._win.Notification&&this._win.Notification.requestPermission,o=this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission;return new Promise(function(r,s){var c,a=!1,u=function(t){a||(a=!0,!function(t){return t===i.GRANTED||0===t}(t)?s():r())};n?u(t):o?i._win.webkitNotifications.requestPermission(function(i){u(i)}):e?(c=i._win.Notification.requestPermission(u))&&c.then&&c.then(u).catch(s):r()})}},{key:"has",value:function(){return this.get()===this.GRANTED}},{key:"get",value:function(){return this._win.Notification&&this._win.Notification.permission?this._win.Notification.permission:this._win.webkitNotifications&&this._win.webkitNotifications.checkPermission?this._permissions[this._win.webkitNotifications.checkPermission()]:navigator.mozNotification?this.GRANTED:this._win.external&&this._win.external.msIsSiteMode?this._win.external.msIsSiteMode()?this.GRANTED:this.DEFAULT:this.GRANTED}}]),i}(),f=function(){function i(){n(this,i)}return o(i,null,[{key:"isUndefined",value:function(i){return void 0===i}},{key:"isNull",value:function(i){return null===obj}},{key:"isString",value:function(i){return"string"==typeof i}},{key:"isFunction",value:function(i){return i&&"[object Function]"==={}.toString.call(i)}},{key:"isObject",value:function(i){return"object"===t(i)}},{key:"objectMerge",value:function(i,t){for(var n in t)i.hasOwnProperty(n)&&this.isObject(i[n])&&this.isObject(t[n])?this.objectMerge(i[n],t[n]):i[n]=t[n]}}]),i}(),l=function i(t){n(this,i),this._win=t},h=function(i){function t(){return n(this,t),a(this,s(t).apply(this,arguments))}return r(t,l),o(t,[{key:"isSupported",value:function(){return void 0!==this._win.Notification}},{key:"create",value:function(i,t){return new this._win.Notification(i,{icon:f.isString(t.icon)||f.isUndefined(t.icon)||f.isNull(t.icon)?t.icon:t.icon.x32,body:t.body,tag:t.tag,requireLine truncated
//# sourceMappingURL=push.min.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"push.min.js","sources":["../src/push/Messages.js","../src/push/Permission.js","../src/push/Util.js","../src/agents/AbstractAgent.js","../src/agents/DesktopAgent.js","../src/agents/MobileChromeAgent.js","../src/agents/MobileFirefoxAgent.js","../src/agents/MSAgent.js","../src/agents/WebKitAgent.js","../src/index.js","../src/push/Push.js"],"sourcesContent":["// @flow\nconst errorPrefix = 'PushError:';\n\nexport default {\n errors: {\n incompatible: `${errorPrefix} Push.js is incompatible with browser.`,\n invalid_plugin: `${errorPrefix} plugin class missing from plugin manifest (invalid plugin). Please check the documentation.`,\n invalid_title: `${errorPrefix} title of notification must be a string`,\n permission_denied: `${errorPrefix} permission request declined`,\n sw_notification_error: `${errorPrefix} could not show a ServiceWorker notification due to the following reason: `,\n sw_registration_error: `${errorPrefix} could not register the ServiceWorker due to the following reason: `,\n unknown_interface: `${errorPrefix} unable to create notification: unknown interface`\n }\n};\n","// @flow\nimport type { Global } from 'types';\n\nexport default class Permission {\n // Private members\n _permissions: string[];\n _win: Global;\n\n // Public members\n GRANTED: string;\n DEFAULT: string;\n DENIED: string;\n\n constructor(win: Global) {\n this._win = win;\n this.GRANTED = 'granted';\n this.DEFAULT = 'default';\n this.DENIED = 'denied';\n this._permissions = [this.GRANTED, this.DEFAULT, this.DENIED];\n }\n\n /**\n * Requests permission for desktop notifications\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void, Promise}\n */\n request(onGranted: () => void, onDenied: () => void) {\n return arguments.length > 0\n ? this._requestWithCallback(...arguments)\n : this._requestAsPromise();\n }\n\n /**\n * Old permissions implementation deprecated in favor of a promise based one\n * @deprecated Since V1.0.4\n * @param {Function} onGranted - Function to execute once permission is granted\n * @param {Function} onDenied - Function to execute once permission is denied\n * @return {void}\n */\n _requestWithCallback(onGranted: () => void, onDenied: () => void) {\n const existing = this.get();\n\n var resolved = false;\n var resolve = (result = this._win.Notification.permission) => {\n if (resolved) return;\n resolved = true;\n if (typeof result === 'undefined' && this._win.webkitNotifications)\n result = this._win.webkitNotifications.checkPermission();\n if (result === this.GRANTED || result === 0) {\n if (onGranted) onGranted();\n } else if (onDenied) onDenied();\n };\n var request;\n\n /* Permissions already set */\n if (existing !== this.DEFAULT) {\n resolve(existing);\n } else if (\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission\n ) {\n /* Safari 6+, Legacy webkit browsers */\n this._win.webkitNotifications.requestPermission(resolve);\n } else if (\n this._win.Notification &&\n this._win.Notification.requestPermission\n ) {\n /* Safari 12+ */\n /* This resolve argument will only be used in Safari */\n /* CHrome, instead, returns a Promise */\n request = this._win.Notification.requestPermission(resolve);\n if (request && request.then) {\n /* Chrome 23+ */\n request.then(resolve).catch(function() {\n if (onDenied) onDenied();\n });\n }\n } else if (onGranted) {\n /* Let the user continue by default */\n onGranted();\n }\n }\n\n /**\n * Requests permission for desktop notifications in a promise based way\n * @return {Promise}\n */\n _requestAsPromise(): Promise<void> {\n const existing = this.get();\n\n let isGranted = result => result === this.GRANTED || result === 0;\n\n /* Permissions already set */\n var hasPermissions = existing !== this.DEFAULT;\n\n /* Safari 6+, Chrome 23+ */\n var isModernAPI =\n this._win.Notification && this._win.Notification.requestPermission;\n\n /* Legacy webkit browsers */\n var isWebkitAPI =\n this._win.webkitNotifications &&\n this._win.webkitNotifications.checkPermission;\n\n return new Promise((resolvePromise, rejectPromise) => {\n var resolved = false;\n var resolver = result => {\n iLine truncated
+22
View File
@@ -124,6 +124,9 @@ databap.pageInit = function()
//Init's end //Init's end
databap.setInitEnd(true); databap.setInitEnd(true);
//Notification Permission
if(!Push.Permission.has()) Push.Permission.request(()=>{}, ()=>{});
}; };
//On resize //On resize
@@ -825,15 +828,18 @@ function addMessage(message_info, bReset)
var sUnreadChanName, iUnreadCount; var sUnreadChanName, iUnreadCount;
var bSystemMsg = false; var bSystemMsg = false;
var bImage = false; var bImage = false;
var sNotif = '';
switch(message_info.msg_class) switch(message_info.msg_class)
{ {
case databap.consts.msg_types.user: case databap.consts.msg_types.user:
msg_body = sMsgPrefix+'<span class="text">'+message_info.message+'</span>'; msg_body = sMsgPrefix+'<span class="text">'+message_info.message+'</span>';
sNotif = message_info.nickname+' : '+message_info.message;
break; break;
case databap.consts.msg_types.news: case databap.consts.msg_types.news:
databap.tmp('get_news', true); databap.tmp('get_news', true);
msg_body = '<span class="text action">'+message_info.nickname+' a une news : <span class="news"><i class="fa fa-30 fa-c-news"></i> '+message_info.message+' <i class="fa fa-30 fa-c-news"></i></span></span>'; msg_body = '<span class="text action">'+message_info.nickname+' a une news : <span class="news"><i class="fa fa-30 fa-c-news"></i> '+message_info.message+' <i class="fa fa-30 fa-c-news"></i></span></span>';
sNotif = message_info.nickname+' a une news : '+message_info.message;
break; break;
case databap.consts.msg_types.add.code: case databap.consts.msg_types.add.code:
var url = databap.getInternalLink('code', message_info.message); var url = databap.getInternalLink('code', message_info.message);
@@ -859,6 +865,7 @@ function addMessage(message_info, bReset)
msgTargetUser = message_info.message.substr(1, slicePos - 1); msgTargetUser = message_info.message.substr(1, slicePos - 1);
var msg = message_info.message.slice(slicePos + 1); var msg = message_info.message.slice(slicePos + 1);
msg_body = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console"> <span class="highlight">&#64;'+msgTargetUser+'</span>&gt;</span><span class="text">'+msg+'</span>'; msg_body = '<a class="user clickable" title="Ecrire un PM &agrave; '+message_info.nickname+'">'+message_info.nickname+'</a><span class="console"> <span class="highlight">&#64;'+msgTargetUser+'</span>&gt;</span><span class="text">'+msg+'</span>';
sNotif = message_info.nickname+' @'+msgTargetUser+' : '+msg;
break; break;
case databap.consts.msg_types.nick: case databap.consts.msg_types.nick:
msg_body = '<span class="text">'+message_info.message+' (<a href="'+databap.getInternalLink('profil', message_info.id_user)+'" target="_blank"><i class="fa fa-c-profile fa-inline"></i>'+message_info.name+'</a>)</span>'; msg_body = '<span class="text">'+message_info.message+' (<a href="'+databap.getInternalLink('profil', message_info.id_user)+'" target="_blank"><i class="fa fa-c-profile fa-inline"></i>'+message_info.name+'</a>)</span>';
@@ -875,6 +882,7 @@ function addMessage(message_info, bReset)
var msg = '<a href="'+message_info.message.url+'" target="_blank" title="'+message_info.message.title+'"><img src="'+message_info.message.url_img+'" width="'+message_info.message.width+'" height="'+message_info.message.height+'" class="proxy" /></a>'; var msg = '<a href="'+message_info.message.url+'" target="_blank" title="'+message_info.message.title+'"><img src="'+message_info.message.url_img+'" width="'+message_info.message.width+'" height="'+message_info.message.height+'" class="proxy" /></a>';
msg_body = sMsgPrefix+'<span class="text">'+msg+'</span>'; msg_body = sMsgPrefix+'<span class="text">'+msg+'</span>';
bImage = true; bImage = true;
sNotif = message_info.nickname+' a posté une image';
break; break;
case databap.consts.msg_types.reboot: case databap.consts.msg_types.reboot:
if(!bReset) if(!bReset)
@@ -944,6 +952,19 @@ function addMessage(message_info, bReset)
sUnreadChanName = getChanName(message_info.id_chan); sUnreadChanName = getChanName(message_info.id_chan);
iUnreadCount = (databap.tmp(['unread_msg', sUnreadChanName]) || 0) + 1; iUnreadCount = (databap.tmp(['unread_msg', sUnreadChanName]) || 0) + 1;
databap.tmp(['unread_msg', sUnreadChanName], iUnreadCount); databap.tmp(['unread_msg', sUnreadChanName], iUnreadCount);
//Desktop Notification
if(!databap.vars.focus && sNotif != '' && Push.Permission.has()) {
Push.create('Databap - '+message_info.nickname, {
body: sNotif,
icon: databap.consts.app_image_folder+(databap.tmp(['logos', message_info.id_user]) || 'logo_25.png'),
timeout: 4000,
onClick: function () {
window.focus();
this.close();
}
});
}
} }
//Move to bottom if user is typing //Move to bottom if user is typing
@@ -1000,6 +1021,7 @@ function refresh_users()
databap.tmp(['users', sChankeyName, sSafeNickName], sNickName); databap.tmp(['users', sChankeyName, sSafeNickName], sNickName);
databap.tmp(['users', databap.consts.all_chan_id, sSafeNickName], sNickName); databap.tmp(['users', databap.consts.all_chan_id, sSafeNickName], sNickName);
databap.tmp(['id_users', sNickName], user_info.id_user); databap.tmp(['id_users', sNickName], user_info.id_user);
databap.tmp(['logos', user_info.id_user], user_info.logo);
//Append name to user list box //Append name to user list box
var sProfileLink = databap.getInternalLink('profil', user_info.id_user); var sProfileLink = databap.getInternalLink('profil', user_info.id_user);
+1
View File
@@ -11,6 +11,7 @@
<script type="text/javascript" src="jquery/jquery.min.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/jquery.min.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/jquery.mods.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/jquery.mods.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/fileuploader.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/fileuploader.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/push.min.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/common.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/common.js?v[#]version[#]"></script>
<script type="text/javascript" src="jquery/databap.js?v[#]version[#]"></script> <script type="text/javascript" src="jquery/databap.js?v[#]version[#]"></script>
<script type="text/javascript"> <script type="text/javascript">