From 591ba9c68e82491468f7e97c966b2e5e3c0eefd6 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 8 Sep 2019 19:18:56 +0000 Subject: [PATCH] Display pending contacts in the contact list --- src/App/Router.php | 1 + src/Module/Contact.php | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/App/Router.php b/src/App/Router.php index 50b208792b..b3df8a14d2 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -108,6 +108,7 @@ class Router $collector->addRoute(['GET'], '/{id:\d+}/updateprofile', Module\Contact::class); $collector->addRoute(['GET'], '/archived', Module\Contact::class); $collector->addRoute(['GET', 'POST'], '/batch', Module\Contact::class); + $collector->addRoute(['GET'], '/pending', Module\Contact::class); $collector->addRoute(['GET'], '/blocked', Module\Contact::class); $collector->addRoute(['GET'], '/hidden', Module\Contact::class); $collector->addRoute(['GET'], '/ignored', Module\Contact::class); diff --git a/src/Module/Contact.php b/src/Module/Contact.php index 198496a0eb..7f31527a2b 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -641,8 +641,11 @@ class Contact extends BaseModule case 'archived': $sql_extra = " AND `archive` AND NOT `blocked`"; break; + case 'pending': + $sql_extra = " AND `pending` AND NOT `archive`"; + break; default: - $sql_extra = " AND NOT `archive` AND NOT `blocked`"; + $sql_extra = " AND NOT `archive` AND NOT `blocked` AND NOT `pending`"; } $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM); @@ -660,6 +663,14 @@ class Contact extends BaseModule 'id' => 'showall-tab', 'accesskey' => 'l', ], + [ + 'label' => L10n::t('Pending'), + 'url' => 'contact/pending', + 'sel' => $type == 'pending' ? 'active' : '', + 'title' => L10n::t('Only show pending contacts'), + 'id' => 'showpending-tab', + 'accesskey' => 'p', + ], [ 'label' => L10n::t('Blocked'), 'url' => 'contact/blocked', @@ -730,7 +741,7 @@ class Contact extends BaseModule $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); $r = q("SELECT COUNT(*) AS `total` FROM `contact` - WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ", + WHERE `uid` = %d AND `self` = 0 $sql_extra $sql_extra2 ", intval($_SESSION['uid']) ); if (DBA::isResult($r)) { @@ -742,7 +753,7 @@ class Contact extends BaseModule $contacts = []; - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT %d , %d ", intval($_SESSION['uid']), $pager->getStart(), $pager->getItemsPerPage() @@ -763,6 +774,7 @@ class Contact extends BaseModule } switch ($type) { + case 'pending': $header .= ' - ' . L10n::t('Pending'); break; case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break; case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break; case 'ignored': $header .= ' - ' . L10n::t('Ignored'); break; @@ -976,6 +988,22 @@ class Contact extends BaseModule $sparkle = ''; } + if ($rr['pending']) { + if (in_array($rr['rel'], [Model\Contact::FRIEND, Model\Contact::SHARING])) { + $alt_text = L10n::t('Pending outgoing contact request'); + } else { + $alt_text = L10n::t('Pending incoming contact request'); + $intro = DBA::selectFirst('intro', ['blocked', 'ignore'], ['contact-id' => $rr['id']]); + if (DBA::isResult($intro)) { + if ($intro['blocked']) { + $alt_text = L10n::t('Blocked incoming contact request'); + } elseif ($intro['ignore']) { + $alt_text = L10n::t('Ignored incoming contact request'); + } + } + } + } + if ($rr['self']) { $dir_icon = 'images/larrow.gif'; $alt_text = L10n::t('This is you'); -- 2.39.5