consolidate notifications caching and loading
This commit is contained in:
parent
add9890754
commit
93259e4e92
2
boot.php
2
boot.php
@ -51,7 +51,7 @@ require_once('include/attach.php');
|
|||||||
require_once('include/bbcode.php');
|
require_once('include/bbcode.php');
|
||||||
|
|
||||||
define ( 'PLATFORM_NAME', 'hubzilla' );
|
define ( 'PLATFORM_NAME', 'hubzilla' );
|
||||||
define ( 'STD_VERSION', '3.1.3' );
|
define ( 'STD_VERSION', '3.1.4' );
|
||||||
define ( 'ZOT_REVISION', '1.3' );
|
define ( 'ZOT_REVISION', '1.3' );
|
||||||
|
|
||||||
define ( 'DB_UPDATE_VERSION', 1198 );
|
define ( 'DB_UPDATE_VERSION', 1198 );
|
||||||
|
@ -68,14 +68,11 @@ $(document).ready(function() {
|
|||||||
$('a.notification-link').click(function(e){
|
$('a.notification-link').click(function(e){
|
||||||
var notifyType = $(this).data('type');
|
var notifyType = $(this).data('type');
|
||||||
|
|
||||||
if (!$(this).data('clicked') && (sessionStorage.getItem(notifyType + '_notifications_cache') !== null)) {
|
if(! $('#nav-' + notifyType + '-sub').hasClass('show')) {
|
||||||
var cached_data = JSON.parse(sessionStorage.getItem(notifyType + '_notifications_cache'));
|
|
||||||
loadNotificationItems(notifyType, cached_data);
|
|
||||||
$(this).data('clicked', true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
loadNotificationItems(notifyType);
|
loadNotificationItems(notifyType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(this).data('clicked', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Allow folks to stop the ajax page updates with the pause/break key
|
// Allow folks to stop the ajax page updates with the pause/break key
|
||||||
@ -391,6 +388,15 @@ function notificationsUpdate(cached_data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var notifyType = null;
|
||||||
|
|
||||||
|
if($('.notification-content.show').length)
|
||||||
|
notifyType = $('.notification-content.show').data('type');
|
||||||
|
|
||||||
|
if(notifyType !== null) {
|
||||||
|
loadNotificationItems(notifyType);
|
||||||
|
}
|
||||||
|
|
||||||
if(timer) clearTimeout(timer);
|
if(timer) clearTimeout(timer);
|
||||||
timer = setTimeout(updateInit,updateInterval);
|
timer = setTimeout(updateInit,updateInterval);
|
||||||
}
|
}
|
||||||
@ -924,33 +930,35 @@ function justifyPhotosAjax(id) {
|
|||||||
$('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
|
$('#' + id).justifiedGallery('norewind').on('jg.complete', function(e){ justifiedGalleryActive = false; });
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadNotificationItems(notifyType, cached_data) {
|
function loadNotificationItems(notifyType) {
|
||||||
|
|
||||||
var pingExCmd = 'ping/' + notifyType + ((localUser != 0) ? '?f=&uid=' + localUser : '');
|
var pingExCmd = 'ping/' + notifyType + ((localUser != 0) ? '?f=&uid=' + localUser : '');
|
||||||
|
|
||||||
if(cached_data !== undefined) {
|
var clicked = $('[data-type=\'' + notifyType + '\']').data('clicked');
|
||||||
|
|
||||||
|
if((clicked === undefined) && (sessionStorage.getItem(notifyType + '_notifications_cache') !== null)) {
|
||||||
|
var cached_data = JSON.parse(sessionStorage.getItem(notifyType + '_notifications_cache'));
|
||||||
handleNotificationsItems(notifyType, cached_data);
|
handleNotificationsItems(notifyType, cached_data);
|
||||||
|
console.log('updating ' + notifyType + ' notifications from cache...');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
var cached_data = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('updating ' + notifyType + ' notifications...');
|
||||||
$.get(pingExCmd, function(data) {
|
$.get(pingExCmd, function(data) {
|
||||||
if(data.invalid == 1) {
|
if(data.invalid == 1) {
|
||||||
window.location.href=window.location.href;
|
window.location.href=window.location.href;
|
||||||
}
|
}
|
||||||
|
|
||||||
$("." + notifyType + "-update").html(data.notify.length);
|
if(JSON.stringify(cached_data[0]) === JSON.stringify(data.notify[0])) {
|
||||||
|
console.log(notifyType + ' notifications cache up to date - update deferred');
|
||||||
sessionStorage.setItem(notifyType + '_notifications_cache', JSON.stringify(data.notify));
|
}
|
||||||
|
else {
|
||||||
handleNotificationsItems(notifyType, data.notify);
|
handleNotificationsItems(notifyType, data.notify);
|
||||||
|
sessionStorage.setItem(notifyType + '_notifications_cache', JSON.stringify(data.notify));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
if($('#nav-' + notifyType + '-sub').hasClass('show')) {
|
|
||||||
console.log('updating ' + notifyType + ' notifications...');
|
|
||||||
setTimeout(loadNotificationItems, updateInterval, notifyType);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since our ajax calls are asynchronous, we will give a few
|
// Since our ajax calls are asynchronous, we will give a few
|
||||||
|
@ -129,7 +129,7 @@
|
|||||||
<i class="fa fa-fw fa-{{$notification.icon}}"></i> {{$notification.label}}
|
<i class="fa fa-fw fa-{{$notification.icon}}"></i> {{$notification.label}}
|
||||||
<span class="float-right badge badge-{{$notification.severity}} {{$notification.type}}-update"></span>
|
<span class="float-right badge badge-{{$notification.severity}} {{$notification.type}}-update"></span>
|
||||||
</a>
|
</a>
|
||||||
<div id="nav-{{$notification.type}}-sub" class="collapse notification-content">
|
<div id="nav-{{$notification.type}}-sub" class="collapse notification-content" data-type="{{$notification.type}}">
|
||||||
{{if $notification.viewall}}
|
{{if $notification.viewall}}
|
||||||
<a class="list-group-item text-dark" id="nav-{{$notification.type}}-see-all" href="{{$notification.viewall.url}}">
|
<a class="list-group-item text-dark" id="nav-{{$notification.type}}-see-all" href="{{$notification.viewall.url}}">
|
||||||
<i class="fa fa-fw fa-external-link"></i> {{$notification.viewall.label}}
|
<i class="fa fa-fw fa-external-link"></i> {{$notification.viewall.label}}
|
||||||
|
Reference in New Issue
Block a user