diff options
author | Mario <mario@mariovavti.com> | 2022-11-30 10:36:55 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2022-11-30 10:36:55 +0000 |
commit | baf1b8b02de4ef3d62a2fd9126cbc05de1bf8711 (patch) | |
tree | b8077a9755f2e2c23cc05d315c6a9bbc36e35ccd | |
parent | 3ce1373ae0e5355b9d10eab5f5b8078245c4b8b6 (diff) | |
download | volse-hubzilla-baf1b8b02de4ef3d62a2fd9126cbc05de1bf8711.tar.gz volse-hubzilla-baf1b8b02de4ef3d62a2fd9126cbc05de1bf8711.tar.bz2 volse-hubzilla-baf1b8b02de4ef3d62a2fd9126cbc05de1bf8711.zip |
fetch the unseen count in a subquery instead of a separate query and rename array key
-rw-r--r-- | Zotlabs/Widget/Messages.php | 18 | ||||
-rw-r--r-- | view/tpl/messages_widget.tpl | 6 |
2 files changed, 9 insertions, 15 deletions
diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index c40d294e8..414353d8a 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -35,7 +35,7 @@ class Messages { 'notice_messages_title' => t('Notices'), 'loading' => t('Loading'), 'empty' => t('No messages'), - 'unseen' => t('Unseen') + 'unseen_count' => t('Unseen') ] ]); @@ -88,7 +88,9 @@ class Messages { $type_sql = ' AND item_private IN (0, 1) '; } - $items = q("SELECT * FROM item WHERE uid = %d + $items = q("SELECT item.*, parent AS this_parent, + (SELECT count(*) FROM item WHERE uid = %d AND parent = this_parent AND item_unseen = 1 AND item_thread_top = 0 $vnotify_sql) AS unseen_count + FROM item WHERE uid = %d AND created <= '%s' $type_sql AND item_thread_top = 1 @@ -96,6 +98,7 @@ class Messages { ORDER BY created DESC $dummy_order_sql LIMIT $limit OFFSET $offset", intval(local_channel()), + intval(local_channel()), dbescdate($loadtime) ); @@ -158,15 +161,6 @@ class Messages { $icon = ''; } - $unseen = q("SELECT count(id) AS total FROM item WHERE uid = %d - AND parent = %d - AND item_thread_top = 0 - AND item_unseen = 1 - $vnotify_sql", - intval(local_channel()), - intval($item['id']) - ); - $entries[$i]['author_name'] = $item['author']['xchan_name']; $entries[$i]['author_addr'] = (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']); $entries[$i]['info'] = $info; @@ -175,7 +169,7 @@ class Messages { $entries[$i]['b64mid'] = gen_link_id($item['mid']); $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); $entries[$i]['icon'] = $icon; - $entries[$i]['unseen'] = (($unseen[0]['total']) ? $unseen[0]['total'] : (($item['item_unseen']) ? ' ' : '')); + $entries[$i]['unseen_count'] = (($item['unseen_count']) ? $item['unseen_count'] : (($item['item_unseen']) ? ' ' : '')); $entries[$i]['unseen_class'] = (($item['item_unseen']) ? 'primary' : 'secondary'); $i++; diff --git a/view/tpl/messages_widget.tpl b/view/tpl/messages_widget.tpl index 495f93ef7..ee933b392 100644 --- a/view/tpl/messages_widget.tpl +++ b/view/tpl/messages_widget.tpl @@ -53,8 +53,8 @@ <div class="text-break">{{$e.summary}}</div> </div> <small>{{$e.info}}</small> - {{if $e.unseen}} - <span class="badge bg-transparent border border-{{$e.unseen_class}} text-{{$e.unseen_class}} rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen}}">{{$e.unseen}}</span> + {{if $e.unseen_count}} + <span class="badge bg-transparent border border-{{$e.unseen_class}} text-{{$e.unseen_class}} rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen_count}}">{{$e.unseen_count}}</span> {{/if}} </a> {{/foreach}} @@ -129,7 +129,7 @@ e.author_addr, e.href, e.icon, - e.unseen ? '<span class="badge bg-transparent border border-' + e.unseen_class + ' text-' + e.unseen_class + ' rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen}}">' + e.unseen + '</span>' : '' + e.unseen_count ? '<span class="badge bg-transparent border border-' + e.unseen_class + ' text-' + e.unseen_class + ' rounded-pill position-absolute bottom-0 end-0 m-2" title="{{$strings.unseen_count}}">' + e.unseen_count + '</span>' : '' ); $('#messages-loading').before(html); }); |