aboutsummaryrefslogtreecommitdiffstats
path: root/view/js/main.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2019-11-20 18:38:25 +0000
committerMario <mario@mariovavti.com>2019-11-20 18:38:25 +0000
commite74361c4dbd21e1502fb0c989dbd31e29a285bca (patch)
treee9db9a2586032151ebefedc47e06802be0f0276a /view/js/main.js
parent21299c6fc147106072aef033e756f08e6fa957c5 (diff)
downloadvolse-hubzilla-e74361c4dbd21e1502fb0c989dbd31e29a285bca.tar.gz
volse-hubzilla-e74361c4dbd21e1502fb0c989dbd31e29a285bca.tar.bz2
volse-hubzilla-e74361c4dbd21e1502fb0c989dbd31e29a285bca.zip
sse: introduce sse_updateNotifications() to be able to update the notifications from different places
Diffstat (limited to 'view/js/main.js')
-rw-r--r--view/js/main.js74
1 files changed, 34 insertions, 40 deletions
diff --git a/view/js/main.js b/view/js/main.js
index 1fbd57b2a..f88153d9b 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -49,19 +49,6 @@ window.onstorage = function(e) {
}
}
-/*
-// Clear the session and local storage if we switch channel or log out
-var cache_uid = '';
-if(sessionStorage.getItem('uid') !== null) {
- cache_uid = sessionStorage.getItem('uid');
-}
-if(cache_uid !== localUser.toString()) {
- sessionStorage.clear();
- localStorage.clear();
- sessionStorage.setItem('uid', localUser.toString());
-}
-*/
-
$.ajaxSetup({cache: false});
$(document).ready(function() {
@@ -859,8 +846,6 @@ function updateConvItems(mode,data) {
}
});
- sse_mids = [];
-
// take care of the notifications count updates
$('.thread-wrapper', data).each(function() {
@@ -871,34 +856,13 @@ function updateConvItems(mode,data) {
if($('.notification[data-b64mid=\'' + nmid + '\']').length) {
$('.notification[data-b64mid=\'' + nmid + '\']').each(function() {
var n = this.parentElement.id.split('-');
-
- if(n[1] === 'pubs')
- return true;
-
- if(n[1] === 'notify' && (nmid !== bParam_mid || sse_type !== 'notify'))
- return true;
-
- var count = Number($('.' + n[1] + '-update').html());
-
- if(count > 0)
- count = count - 1;
-
- if(count < 1) {
- $('.' + n[1] + '-button').fadeOut();
- $('.' + n[1] + '-update').html(count);
- }
- else
- $('.' + n[1] + '-update').html(count);
-
- $('#nav-' + n[1] + '-menu .notification[data-b64mid=\'' + nmid + '\']').fadeOut();
-
+ return sse_updateNotifications(n[1], nmid, true);
});
+ sse_mids = [];
}
});
- //console.log(sse_mids);
-
// reset rotators and cursors we may have set before reaching this place
$('.like-rotator').hide();
@@ -2078,12 +2042,12 @@ function sse_handleNotificationsItems(notifyType, data, replace, followup) {
$(data).each(function() {
if(sse_mids.indexOf(this.b64mid) >= 0) {
- //console.log('dismiss: ' + this.b64mid);
- return true;
+ return sse_updateNotifications(notifyType, this.b64mid, false);
}
html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.addr,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top,this.unseen,this.private_forum);
notify_menu.append(html);
});
+ sse_mids = [];
if(!replace && !followup) {
console.log('sorting');
@@ -2117,3 +2081,33 @@ function sse_handleNotificationsItems(notifyType, data, replace, followup) {
}
}
+function sse_updateNotifications(type, mid, interactive) {
+
+ console.log('interactive: ' + interactive);
+
+ if(type === 'pubs')
+ return true;
+
+ if(type === 'notify' && (mid !== bParam_mid || sse_type !== 'notify'))
+ return true;
+
+ var count = Number($('.' + type + '-update').html());
+
+ if(count > 0)
+ count--;
+
+ if(count < 1) {
+ $('.' + type + '-button').fadeOut();
+ $('.' + type + '-update').html(count);
+ }
+ else
+ $('.' + type + '-update').html(count);
+
+ if(! interactive)
+ return true;
+
+ $('#nav-' + type + '-menu .notification[data-b64mid=\'' + mid + '\']').fadeOut();
+
+ return false;
+
+}