diff options
-rw-r--r-- | Zotlabs/Module/Sse_bs.php | 23 | ||||
-rw-r--r-- | view/js/main.js | 29 | ||||
-rw-r--r-- | view/tpl/notifications_widget.tpl | 2 |
3 files changed, 43 insertions, 11 deletions
diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index 5e00593ef..4340876ea 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -77,10 +77,6 @@ class Sse_bs extends Controller { default: } - set_xconfig(self::$ob_hash, 'sse', 'timestamp', datetime_convert()); - set_xconfig(self::$ob_hash, 'sse', 'notifications', []); // reset the cache - set_xconfig(self::$ob_hash, 'sse', 'language', App::$language); - if(self::$offset && $f) { $result = self::$f(true); json_return_and_die($result); @@ -99,6 +95,10 @@ class Sse_bs extends Controller { self::bs_register() ); + set_xconfig(self::$ob_hash, 'sse', 'timestamp', datetime_convert()); + set_xconfig(self::$ob_hash, 'sse', 'notifications', []); // reset the cache + set_xconfig(self::$ob_hash, 'sse', 'language', App::$language); + json_return_and_die($result); } @@ -390,22 +390,29 @@ class Sse_bs extends Controller { $p_str = ids_to_querystr($p, 'parent'); $p_sql = (($p_str) ? "OR parent IN ( $p_str )" : ''); - $r = q("select count(id) as unseen from item + $r = q("select mid from item where uid = %d and ( owner_xchan = '%s' OR author_xchan = '%s' $p_sql ) and item_unseen = 1 $sql_extra $item_normal", intval(self::$uid), dbesc($forums[$x]['xchan_hash']), dbesc($forums[$x]['xchan_hash']) ); - if($r[0]['unseen']) { + if($r) { + $mids = flatten_array_recursive($r); + + + foreach($mids as $mid) + $b64mids[] = 'b64.' . base64url_encode($mid); + $forums[$x]['notify_link'] = (($forums[$x]['private_forum']) ? $forums[$x]['xchan_url'] : z_root() . '/network/?f=&pf=1&unseen=1&cid=' . $forums[$x]['abook_id']); $forums[$x]['name'] = $forums[$x]['xchan_name']; $forums[$x]['addr'] = $forums[$x]['xchan_addr']; $forums[$x]['url'] = $forums[$x]['xchan_url']; $forums[$x]['photo'] = $forums[$x]['xchan_photo_s']; - $forums[$x]['unseen'] = $r[0]['unseen']; + $forums[$x]['unseen'] = count($b64mids); $forums[$x]['private_forum'] = (($forums[$x]['private_forum']) ? 'lock' : ''); $forums[$x]['message'] = (($forums[$x]['private_forum']) ? t('Private forum') : t('Public forum')); + $forums[$x]['mids'] = json_encode($b64mids); unset($forums[$x]['abook_id']); unset($forums[$x]['xchan_hash']); @@ -413,7 +420,7 @@ class Sse_bs extends Controller { unset($forums[$x]['xchan_url']); unset($forums[$x]['xchan_photo_s']); - $i = $i + $r[0]['unseen']; + $i = $i + count($mids); } else { diff --git a/view/js/main.js b/view/js/main.js index 1baf1ca1f..f471bc909 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -696,11 +696,11 @@ function updateConvItems(mode,data) { // take care of the notifications count updates $('.thread-wrapper', data).each(function() { - //var nmid = $(this).data('b64mid'); var nmids = $(this).data('b64mids'); nmids.forEach(function(nmid, index) { sse_mids.push(nmid); + if($('.notification[data-b64mid=\'' + nmid + '\']').length) { $('.notification[data-b64mid=\'' + nmid + '\']').each(function() { var n = this.parentElement.id.split('-'); @@ -708,6 +708,27 @@ function updateConvItems(mode,data) { }); sse_mids = []; } + + // special handling for forum notification + $('.notification-forum').filter(function() { + var fmids = $(this).data('b64mids'); + var n = this.parentElement.id.split('-'); + if(fmids.indexOf(nmid) > -1) { + var fcount = Number($('.' + n[1] + '-update').html()); + fcount--; + $('.' + n[1] + '-update').html(fcount); + if(fcount < 1) + $('.' + n[1] + '-button').fadeOut(); + + var count = Number($(this).find('.badge-secondary').html()); + count--; + $(this).find('.badge-secondary').html(count); + if(count < 1) + $(this).remove(); + } + }); + + }); sse_setNotificationsStatus(); @@ -1757,7 +1778,11 @@ function sse_handleNotificationsItems(notifyType, data, replace, followup) { if(sse_mids.indexOf(this.b64mid) >= 0) { 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); + // TODO: this replace() is ugly - try to fix this in a better way. + // The problem is that allthough we use single quotes in the template + // the browser turns it into double quotes. JQuery picks up the double qoutes + // from the browser and breaks the JSON string due to that. + html = notifications_tpl.replace(/"/g, "'").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, this.mids); notify_menu.append(html); }); diff --git a/view/tpl/notifications_widget.tpl b/view/tpl/notifications_widget.tpl index 057d5b491..9191c2470 100644 --- a/view/tpl/notifications_widget.tpl +++ b/view/tpl/notifications_widget.tpl @@ -143,7 +143,7 @@ </a> </div> <div id="nav-notifications-forums-template" rel="template"> - <a class="list-group-item clearfix notification notification-forum" href="{0}" title="{4} - {3}" data-b64mid="{7}" data-notify_id="{8}" data-thread_top="{9}" data-contact_name="{2}" data-contact_addr="{3}"> + <a class="list-group-item clearfix notification notification-forum" href="{0}" title="{4} - {3}" data-b64mid="{7}" data-notify_id="{8}" data-thread_top="{9}" data-contact_name="{2}" data-contact_addr="{3}" data-b64mids='{12}'> <span class="float-right badge badge-secondary">{10}</span> <img class="menu-img-1" src="{1}"> <span class="">{2}</span> |