Merge pull request #7604 from annando/pending-contacts

Display pending contacts in the contact list
This commit is contained in:
Hypolite Petovan 2019-09-09 13:49:51 -04:00 committed by GitHub
commit 91b0f0465f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 11 deletions

View File

@ -98,9 +98,14 @@ function notifications_content(App $a)
if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { if ((($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
Nav::setSelected('introductions'); Nav::setSelected('introductions');
$id = 0;
if (!empty($a->argv[2]) && intval($a->argv[2]) != 0) {
$id = (int)$a->argv[2];
}
$all = (($a->argc > 2) && ($a->argv[2] == 'all')); $all = (($a->argc > 2) && ($a->argv[2] == 'all'));
$notifs = $nm->introNotifs($all, $startrec, $perpage); $notifs = $nm->introNotifs($all, $startrec, $perpage, $id);
// Get the network notifications // Get the network notifications
} elseif (($a->argc > 1) && ($a->argv[1] == 'network')) { } elseif (($a->argc > 1) && ($a->argv[1] == 'network')) {

View File

@ -108,6 +108,7 @@ class Router
$collector->addRoute(['GET'], '/{id:\d+}/updateprofile', Module\Contact::class); $collector->addRoute(['GET'], '/{id:\d+}/updateprofile', Module\Contact::class);
$collector->addRoute(['GET'], '/archived', Module\Contact::class); $collector->addRoute(['GET'], '/archived', Module\Contact::class);
$collector->addRoute(['GET', 'POST'], '/batch', 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'], '/blocked', Module\Contact::class);
$collector->addRoute(['GET'], '/hidden', Module\Contact::class); $collector->addRoute(['GET'], '/hidden', Module\Contact::class);
$collector->addRoute(['GET'], '/ignored', Module\Contact::class); $collector->addRoute(['GET'], '/ignored', Module\Contact::class);

View File

@ -549,6 +549,7 @@ class NotificationsManager extends BaseObject
* which aren't marked as ignored * which aren't marked as ignored
* @param int $start Start the query at this point * @param int $start Start the query at this point
* @param int $limit Maximum number of query results * @param int $limit Maximum number of query results
* @param int $id When set, only the introduction with this id is displayed
* *
* @return array with * @return array with
* string 'ident' => Notification identifier * string 'ident' => Notification identifier
@ -556,14 +557,20 @@ class NotificationsManager extends BaseObject
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public function introNotifs($all = false, $start = 0, $limit = 80) public function introNotifs($all = false, $start = 0, $limit = 80, $id = 0)
{ {
$ident = 'introductions'; $ident = 'introductions';
$notifs = []; $notifs = [];
$sql_extra = ""; $sql_extra = "";
if (!$all) { if (empty($id)) {
$sql_extra = " AND NOT `ignore` "; if (!$all) {
$sql_extra = " AND NOT `ignore` ";
}
$sql_extra .= " AND NOT `intro`.`blocked` ";
} else {
$sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
} }
/// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact /// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
@ -578,7 +585,7 @@ class NotificationsManager extends BaseObject
LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
WHERE `intro`.`uid` = ? $sql_extra AND `intro`.`blocked` = 0 WHERE `intro`.`uid` = ? $sql_extra
LIMIT ?, ?", LIMIT ?, ?",
$_SESSION['uid'], $_SESSION['uid'],
$start, $start,

View File

@ -1175,7 +1175,7 @@ class Contact extends BaseObject
} }
$sparkle = false; $sparkle = false;
if (($contact['network'] === Protocol::DFRN) && !$contact['self']) { if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && !$contact['pending']) {
$sparkle = true; $sparkle = true;
$profile_link = System::baseUrl() . '/redir/' . $contact['id'] . '?url=' . $contact['url']; $profile_link = System::baseUrl() . '/redir/' . $contact['id'] . '?url=' . $contact['url'];
} else { } else {
@ -1192,11 +1192,11 @@ class Contact extends BaseObject
$profile_link = $profile_link . '?tab=profile'; $profile_link = $profile_link . '?tab=profile';
} }
if (self::canReceivePrivateMessages($contact)) { if (self::canReceivePrivateMessages($contact) && !$contact['pending']) {
$pm_url = System::baseUrl() . '/message/new/' . $contact['id']; $pm_url = System::baseUrl() . '/message/new/' . $contact['id'];
} }
if (($contact['network'] == Protocol::DFRN) && !$contact['self']) { if (($contact['network'] == Protocol::DFRN) && !$contact['self'] && !$contact['pending']) {
$poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id']; $poke_link = System::baseUrl() . '/poke/?f=&c=' . $contact['id'];
} }
@ -1231,6 +1231,13 @@ class Contact extends BaseObject
'pm' => [L10n::t('Send PM'), $pm_url, false], 'pm' => [L10n::t('Send PM'), $pm_url, false],
'poke' => [L10n::t('Poke'), $poke_link, false], 'poke' => [L10n::t('Poke'), $poke_link, false],
]; ];
if ($contact['pending']) {
$intro = DBA::selectFirst('intro', ['id'], ['contact-id' => $contact['id']]);
if (DBA::isResult($intro)) {
$menu['follow'] = [L10n::t('Approve'), 'notifications/intros/' . $intro['id'], true];
}
}
} }
$args = ['contact' => $contact, 'menu' => &$menu]; $args = ['contact' => $contact, 'menu' => &$menu];

View File

@ -641,8 +641,12 @@ class Contact extends BaseModule
case 'archived': case 'archived':
$sql_extra = " AND `archive` AND NOT `blocked`"; $sql_extra = " AND `archive` AND NOT `blocked`";
break; break;
case 'pending':
$sql_extra = sprintf(" AND `pending` AND NOT `archive` AND ((`rel` = %d)
OR EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id` AND NOT `ignore`))", Model\Contact::SHARING);
break;
default: 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); $sql_extra .= sprintf(" AND `network` != '%s' ", Protocol::PHANTOM);
@ -660,6 +664,14 @@ class Contact extends BaseModule
'id' => 'showall-tab', 'id' => 'showall-tab',
'accesskey' => 'l', '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'), 'label' => L10n::t('Blocked'),
'url' => 'contact/blocked', 'url' => 'contact/blocked',
@ -730,7 +742,7 @@ class Contact extends BaseModule
$sql_extra2 = ((($sort_type > 0) && ($sort_type <= Model\Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); $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` $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']) intval($_SESSION['uid'])
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -742,7 +754,7 @@ class Contact extends BaseModule
$contacts = []; $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']), intval($_SESSION['uid']),
$pager->getStart(), $pager->getStart(),
$pager->getItemsPerPage() $pager->getItemsPerPage()
@ -763,6 +775,7 @@ class Contact extends BaseModule
} }
switch ($type) { switch ($type) {
case 'pending': $header .= ' - ' . L10n::t('Pending'); break;
case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break; case 'blocked': $header .= ' - ' . L10n::t('Blocked'); break;
case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break; case 'hidden': $header .= ' - ' . L10n::t('Hidden'); break;
case 'ignored': $header .= ' - ' . L10n::t('Ignored'); break; case 'ignored': $header .= ' - ' . L10n::t('Ignored'); break;
@ -976,6 +989,14 @@ class Contact extends BaseModule
$sparkle = ''; $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');
}
}
if ($rr['self']) { if ($rr['self']) {
$dir_icon = 'images/larrow.gif'; $dir_icon = 'images/larrow.gif';
$alt_text = L10n::t('This is you'); $alt_text = L10n::t('This is you');