From ab0bd55cbc12dfe835febbf5f980ad16a1837c16 Mon Sep 17 00:00:00 2001 From: nipos Date: Tue, 1 May 2018 18:51:00 +0200 Subject: [PATCH] Added notificatins,automatic reconnect with bad connection,added ... at end of shortened links --- README.md | 9 +++-- assets/css/style.css | 3 ++ assets/js/halcyon/halcyonFunctions.js | 28 +++++++++++++ assets/js/halcyon/halcyonUI.js | 51 +++++++++++++++++++----- assets/js/mastodon.js/mastodon.js | 57 ++++++++++++++++++++++----- login/auth.php | 1 + version.txt | 2 +- widgets/side_load_options.php | 7 ++++ 8 files changed, 134 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f3bf37a..2eba7a7 100644 --- a/README.md +++ b/README.md @@ -10,16 +10,17 @@ Follow or Mastodon account and never miss an important update: [@halcyon@social. ## Instances These instances are publicly accessible and usable by everyone, no matter which Mastodon instance you use. -- https://halcyon.toromino.de - 1.1.3 +- https://halcyon.toromino.de - 1.1.4 +- https://halcyon.bka.li - 1.1.4 +- https://halcyon.tilde.team - 1.1.3 +- https://itter.photog.social - 1.1.3 - https://social.dev-wiki.de - 1.1.1 -- https://halcyon.bka.li - 1.1.3 -- https://halcyon.tilde.team - 1.1.2 -- https://itter.photog.social - 1.1.1 - https://halcyon.cybre.space - Outdated You have your own Halcyon instance and want it to be listed here? Create an issue with the link and we will add it to the list. ## Blog +- Release of Version 1.1.4 - Automatically reconnect on bad connection,now supports desktop notifications,added ... at the end of shortened links - Release of Version 1.1.3 - New function link previews introduced and bug when replying an toot which already has replies below it fixed (reply to undefined) - Release of Version 1.1.2 - Privacy modes are now correctly displayed and used for replies,use username if display name doesn't exist,bugs on search page fixed - Release of Version 1.1.1 - Fixed error 404 when viewing profile of own instance,numbers below profile on the left do now change during session,added nginx config diff --git a/assets/css/style.css b/assets/css/style.css index 309e5f4..43e26de 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -35,6 +35,9 @@ color: red!important; .invisible { display: none!important; } +.ellipsis:after { +content:"..."; +} .no-events { pointer-events: none; } diff --git a/assets/js/halcyon/halcyonFunctions.js b/assets/js/halcyon/halcyonFunctions.js index c87c528..ccb0df7 100644 --- a/assets/js/halcyon/halcyonFunctions.js +++ b/assets/js/halcyon/halcyonFunctions.js @@ -248,6 +248,24 @@ $(".js_current_followers_count").text(current_followers_count); $(".current_toots_count_link").attr("href", current_statuses_count_link); $(".current_following_count_link").attr("href", current_following_count_link); $(".current_followers_count_link").attr("href", current_followers_count_link); +if(localStorage.setting_link_previews == "true") { +$("#setting_link_previews")[0].checked = true; +} +if(localStorage.setting_desktop_notifications == "true") { +$("#setting_desktop_notifications")[0].checked = true; +if (Notification.permission === 'default') { +Notification.requestPermission(function(p) { +if (p === 'denied') { +localStorage.setItem("setting_desktop_notifications","false"); +$("#setting_desktop_notifications")[0].checked = false; +} +}); +} +else if(Notification.permission == "denied") { +localStorage.setItem("setting_desktop_notifications","false"); +$("#setting_desktop_notifications")[0].checked = false; +} +} replace_emoji(); } function putMessage(Message) { @@ -257,3 +275,13 @@ setTimeout(function(){ $("#overlay_message").removeClass("view"); },3000); }; +function pushNotification(title,message) { +if (window.Notification && localStorage.setting_desktop_notifications == "true") { +if (Notification.permission === 'granted') { +notify = new Notification(title, { +body: message, +icon: '/assets/images/halcyon_logo.png' +}); +} +} +} diff --git a/assets/js/halcyon/halcyonUI.js b/assets/js/halcyon/halcyonUI.js index 3405d19..05d6bee 100644 --- a/assets/js/halcyon/halcyonUI.js +++ b/assets/js/halcyon/halcyonUI.js @@ -1724,18 +1724,25 @@ $('#header .header_nav_list .notification_badge').removeClass('invisible'); $('#header .header_nav_list .notification_badge').text( current_count ); } api.stream("user", function(userstream) { -if(userstream.event == "notification" && userstream.payload.type == "follow") { -$(".js_current_followers_count").html(++localStorage.current_followers_count); -} if (userstream.event === "update" & location.pathname !== "/" ) { $('#header .header_nav_list .home_badge').removeClass('invisible'); -} else if (userstream.event === "notification" & location.pathname !== "/notifications") { +} +else if (userstream.event === "notification" & location.pathname !== "/notifications") { current_count += 1; localStorage.setItem("notification_count", current_count ); $('#header .header_nav_list .notification_badge').text( current_count ); if ( $('#header .header_nav_list .notification_badge').hasClass('invisible') ) { $('#header .header_nav_list .notification_badge').removeClass('invisible') } +if(userstream.payload.account.display_name.length == 0) { +userstream.payload.account.display_name = userstream.payload.account.username; +} +switch(userstream.payload.type) { +case "favourite":pushNotification("New favourite",userstream.payload.account.display_name+" favourited your toot");break; +case "reblog":pushNotification("New boost",userstream.payload.account.display_name+" boosted your toot");break; +case "follow":pushNotification("New follower",userstream.payload.account.display_name+" followed you");$(".js_current_followers_count").html(++localStorage.current_followers_count);break; +case "mention":pushNotification("New mention",userstream.payload.account.display_name+" mentioned you");break; +} } }); } @@ -2455,9 +2462,6 @@ $('.post_steraming_wrap').html(html_post_steraming) $('.post_privacy_wrap').html(html_post_privacy); $('.local_instance_wrap').html(html_local_instance); $('.search_filter_wrap').html(html_search_filter); -if(localStorage.setting_link_previews == "true") { -$("#setting_link_previews")[0].checked = true; -} return false; }); $(document).on('change',".post_steraming_wrap select[name='post_steraming']", function(e) { @@ -2486,11 +2490,40 @@ putMessage("Changed setting to "+$(this).val() ); $("#setting_link_previews").change(function() { if(this.checked) { localStorage.setItem("setting_link_previews","true"); -putMessage("Link preview enabled"); +putMessage("Link previews enabled"); } else { localStorage.setItem("setting_link_previews","false"); -putMessage("Link preview disabled"); +putMessage("Link previews disabled"); +} +}); +$("#setting_desktop_notifications").change(function() { +if(this.checked) { +localStorage.setItem("setting_desktop_notifications","true"); +if (Notification.permission === 'default') { +Notification.requestPermission(function(p) { +if (p === 'denied') { +localStorage.setItem("setting_desktop_notifications","false"); +$("#setting_desktop_notifications")[0].checked = false; +putMessage("You didn't allow notifications"); +} +else { +putMessage("Desktop notifications enabled"); +} +}); +} +else if(Notification.permission == "denied") { +localStorage.setItem("setting_desktop_notifications","false"); +$("#setting_desktop_notifications")[0].checked = false; +putMessage("You didn't allow notifications"); +} +else { +putMessage("Desktop notifications enabled"); +} +} +else { +localStorage.setItem("setting_desktop_notifications","false"); +putMessage("Desktop notifications disabled"); } }); }) diff --git a/assets/js/mastodon.js/mastodon.js b/assets/js/mastodon.js/mastodon.js index 35087ee..5d7268a 100644 --- a/assets/js/mastodon.js/mastodon.js +++ b/assets/js/mastodon.js/mastodon.js @@ -13,8 +13,7 @@ getConfig: function(key) { return config[key]; }, get: function (endpoint) { -var queryData, callback, -queryStringAppend = "?"; +var queryData,callback,queryStringAppend = "?"; if (typeof arguments[1] === "function") { queryData = {}; callback = arguments[1]; @@ -22,6 +21,10 @@ callback = arguments[1]; queryData = arguments[1]; callback = arguments[2]; } +if(typeof queryData == "string") { +queryStringAppend = queryData; +} +else { for (var i in queryData) { if (queryData.hasOwnProperty(i)) { if (typeof queryData[i] === "string") { @@ -31,6 +34,8 @@ queryStringAppend += queryData[i].name + "="+ queryData[i].data + "&"; } } } +} +var xquerydata = queryData; $.ajax({ url: apiBase + endpoint + queryStringAppend, type: "GET", @@ -41,9 +46,14 @@ responce_headers = xhr.getAllResponseHeaders(); callback(data,textStatus); }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.get(endpoint,queryStringAppend,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); @@ -79,9 +89,14 @@ responce_headers = xhr.getAllResponseHeaders(); callback(data,textStatus); }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.getArray(endpoint,queryData,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); @@ -114,9 +129,14 @@ responce_headers = xhr.getAllResponseHeaders(); callback(data,textStatus); }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.getOther(endpoint,queryData,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); @@ -149,9 +169,14 @@ console.log("Successful POST API request to " +apiBase+endpoint); callback(data,textStatus) }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.post(endpoint,postData,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); @@ -177,9 +202,14 @@ console.log("Successful POST API request to " +apiBase+endpoint); callback(data,textStatus) }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.postMedia(endpoint,postData,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); @@ -197,16 +227,20 @@ console.log("Successful DELETE API request to " +apiBase+endpoint); callback(data,textStatus) }, error: function(xhr, textStatus, errorThrown) { +if(xhr.readyState == 0) { +api.delete(endpoint,callback); +} +else { putMessage(`[${xhr.status}] ${xhr.responseJSON['error']}`); if ( xhr.status === 401 ) { -location.href = "/logout" +location.href = "/logout"; +} } } }); }, stream: function (streamType, onData) { -var es = new WebSocket("wss://" + apiBase.substr(8) -+"streaming?access_token=" + config.api_user_token + "&stream=" + streamType); +var es = new WebSocket("wss://" + apiBase.substr(8) + "streaming?access_token=" + config.api_user_token + "&stream=" + streamType); var listener = function (event) { console.log("Got Data from Stream " + streamType); event = JSON.parse(event.data); @@ -214,6 +248,9 @@ event.payload = JSON.parse(event.payload); onData(event); }; es.onmessage = listener; +es.onclose = function() { +api.stream(streamType,onData); +}; } }; }; diff --git a/login/auth.php b/login/auth.php index 49305a0..f3eabd3 100644 --- a/login/auth.php +++ b/login/auth.php @@ -33,6 +33,7 @@ localStorage.setItem('setting_post_privacy', 'public'); localStorage.setItem('setting_local_instance', 'default'); localStorage.setItem('setting_search_filter', 'all'); localStorage.setItem('setting_link_previews', 'true'); +localStorage.setItem('setting_desktop_notifications', 'true'); localStorage.setItem('what_to_follow_0', JSON.stringify({id:'',username:'Halcyon',display_name:'Halcyon for Mastodon',url:'https://social.csswg.org/@halcyon',avatar:'https://social.csswg.org/system/accounts/avatars/000/005/666/original/e9a158381ce1249a.png'})); localStorage.setItem('what_to_follow_1', JSON.stringify({id:'',username:'Gargron',display_name:'Eugen',url:'https://mastodon.social/@Gargron',avatar:'https://files.mastodon.social/accounts/avatars/000/000/001/original/4df197532c6b768c.png'})); localStorage.setItem('what_to_follow_2', JSON.stringify({id:'',username:'Mastodon',display_name:'Mastodon',url:'https://mastodon.social/@Mastodon',avatar:'https://files.mastodon.social/accounts/avatars/000/013/179/original/27bc451c7713091b.jpg'})); diff --git a/version.txt b/version.txt index 781dcb0..65087b4 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.1.3 +1.1.4 diff --git a/widgets/side_load_options.php b/widgets/side_load_options.php index de241df..05464bb 100644 --- a/widgets/side_load_options.php +++ b/widgets/side_load_options.php @@ -23,5 +23,12 @@ +

Desktop notifications

+
+ +
+ +
+