Merge pull request #8964 from annando/contact-tabs

Ensure contact tabs will use the correct contact id / new function for fetching the followers
This commit is contained in:
Hypolite Petovan 2020-08-03 16:35:49 -04:00 committed by GitHub
commit adfb94d370
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 122 additions and 410 deletions

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2020.09-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1358
-- DB_UPDATE_VERSION 1359
-- ------------------------------------------
@ -465,67 +465,6 @@ CREATE TABLE IF NOT EXISTS `fsuggest` (
PRIMARY KEY(`id`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff';
--
-- TABLE gcontact
--
CREATE TABLE IF NOT EXISTS `gcontact` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this contact is known by',
`nick` varchar(255) NOT NULL DEFAULT '' COMMENT 'Nick- and user name of the contact',
`url` varchar(255) NOT NULL DEFAULT '' COMMENT 'Link to the contacts profile page',
`nurl` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`photo` varchar(255) NOT NULL DEFAULT '' COMMENT 'Link to the profile photo',
`connect` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
`updated` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
`last_contact` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
`last_failure` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
`last_discovery` datetime DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of the last contact discovery',
`failed` boolean COMMENT 'Connection failed',
`archive_date` datetime DEFAULT '0001-01-01 00:00:00' COMMENT '',
`archived` boolean NOT NULL DEFAULT '0' COMMENT '',
`location` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`about` text COMMENT '',
`keywords` text COMMENT 'puplic keywords (interests)',
`gender` varchar(32) NOT NULL DEFAULT '' COMMENT 'Deprecated',
`birthday` varchar(32) NOT NULL DEFAULT '0001-01-01' COMMENT '',
`community` boolean NOT NULL DEFAULT '0' COMMENT '1 if contact is forum account',
`contact-type` tinyint NOT NULL DEFAULT -1 COMMENT '',
`hide` boolean NOT NULL DEFAULT '0' COMMENT '1 = should be hidden from search',
`nsfw` boolean NOT NULL DEFAULT '0' COMMENT '1 = contact posts nsfw content',
`network` char(4) NOT NULL DEFAULT '' COMMENT 'social network protocol',
`addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`notify` varchar(255) COMMENT '',
`alias` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`generation` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`server_url` varchar(255) NOT NULL DEFAULT '' COMMENT 'baseurl of the contacts server',
`gsid` int unsigned COMMENT 'Global Server ID',
PRIMARY KEY(`id`),
UNIQUE INDEX `nurl` (`nurl`(190)),
INDEX `name` (`name`(64)),
INDEX `nick` (`nick`(32)),
INDEX `addr` (`addr`(64)),
INDEX `hide_network_updated` (`hide`,`network`,`updated`),
INDEX `updated` (`updated`),
INDEX `gsid` (`gsid`),
FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='global contacts';
--
-- TABLE glink
--
CREATE TABLE IF NOT EXISTS `glink` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`cid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
`gcid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`zcid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
PRIMARY KEY(`id`),
UNIQUE INDEX `cid_uid_gcid_zcid` (`cid`,`uid`,`gcid`,`zcid`),
INDEX `gcid` (`gcid`)
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='\'friends of friends\' linkages derived from poco';
--
-- TABLE group
--

View File

@ -18,9 +18,6 @@ Database Tables
| [event](help/database/db_event) | Events |
| [fcontact](help/database/db_fcontact) | friend suggestion stuff |
| [fsuggest](help/database/db_fsuggest) | friend suggestion stuff |
| [gcign](help/database/db_gcign) | contacts ignored by friend suggestions |
| [gcontact](help/database/db_gcontact) | global contacts |
| [glink](help/database/db_glink) | "friends of friends" linkages derived from poco |
| [group](help/database/db_group) | privacy groups, group info |
| [group_member](help/database/db_group_member) | privacy groups, member info |
| [gserver](help/database/db_gserver) | |

View File

@ -1,10 +0,0 @@
Table gcign
===========
| Field | Description | Type | Null | Key | Default | Extra |
| ----- | ------------------------------ | ------- | ---- | --- | ------- | --------------- |
| id | sequential ID | int(11) | NO | PRI | NULL | auto_increment |
| uid | local user.id | int(11) | NO | MUL | 0 | |
| gcid | gcontact.id of ignored contact | int(11) | NO | MUL | 0 | |
Return to [database documentation](help/database)

View File

@ -1,32 +0,0 @@
Table gcontact
==============
| Field |Description | Type | Null | Key | Default | Extra |
|--------------|------------------------------------|------------------|------|-----|---------------------|----------------|
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | Name that this contact is known by | varchar(255) | NO | | | |
| nick | Nick- and user name of the contact | varchar(255) | NO | | | |
| url | Link to the contacts profile page | varchar(255) | NO | | | |
| nurl | | varchar(255) | NO | MUL | | |
| photo | Link to the profile photo | varchar(255) | NO | | | |
| connect | | varchar(255) | NO | | | |
| created | | datetime | NO | | 0001-01-01 00:00:00 | |
| updated | | datetime | YES | MUL | 0001-01-01 00:00:00 | |
| last_contact | | datetime | YES | | 0001-01-01 00:00:00 | |
| last_failure | | datetime | YES | | 0001-01-01 00:00:00 | |
| location | | varchar(255) | NO | | | |
| about | | text | NO | | NULL | |
| keywords | puplic keywords (interests) | text | NO | | NULL | |
| gender | | varchar(32) | NO | | | |
| birthday | | varchar(32) | NO | | 0001-01-01 | |
| community | 1 if contact is forum account | tinyint(1) | NO | | 0 | |
| hide | 1 = should be hidden from search | tinyint(1) | NO | | 0 | |
| nsfw | 1 = contact posts nsfw content | tinyint(1) | NO | | 0 | |
| network | social network protocol | varchar(255) | NO | | | |
| addr | | varchar(255) | NO | | | |
| notify | | text | NO | | | |
| alias | | varchar(255) | NO | | | |
| generation | | tinyint(3) | NO | | 0 | |
| server_url | baseurl of the contacts server | varchar(255) | NO | | | |
Return to [database documentation](help/database)

View File

@ -1,13 +0,0 @@
Table glink
===========
| Field | Description | Type | Null | Key | Default | Extra |
|---------|------------------|------------------|------|-----|---------------------|----------------|
| id | sequential ID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| cid | | int(11) | NO | MUL | 0 | |
| uid | | int(11) | NO | | 0 | |
| gcid | | int(11) | NO | MUL | 0 | |
| zcid | | int(11) | NO | MUL | 0 | |
| updated | | datetime | NO | | 0001-01-01 00:00:00 | |
Return to [database documentation](help/database)

View File

@ -117,14 +117,6 @@ function common_content(App $a)
return $o;
}
$entries = [];
foreach ($common_friends as $common_friend) {
$contact = Model\Contact::getByURLForUser($common_friend['url'], local_user());
if (!empty($contact)) {
$entries[] = Module\Contact::getContactTemplateVars($contact);
}
}
$title = '';
$tab_str = '';
if ($cmd === 'loc' && $cid && local_user() == $uid) {
@ -133,6 +125,14 @@ function common_content(App $a)
$title = DI::l10n()->t('Common Friends');
}
$entries = [];
foreach ($common_friends as $common_friend) {
$contact = Model\Contact::getByURLForUser($common_friend['url'], local_user());
if (!empty($contact)) {
$entries[] = Module\Contact::getContactTemplateVars($contact);
}
}
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
$o .= Renderer::replaceMacros($tpl, [

View File

@ -128,7 +128,7 @@ function poco_init(App $a) {
$contacts = DBA::selectToArray('owner-view', [], ['net-publish' => true], ['limit' => [$startIndex, $itemsPerPage]]);
} else {
Logger::log("Start query for user " . $user['nickname'], Logger::DEBUG);
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `hiddden` AND NOT `archive`
$contacts = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `blocked` AND NOT `pending` AND NOT `hidden` AND NOT `archive`
AND NOT `failed` AND NOT `unsearchable`
AND `network` IN ('%s', '%s', '%s', '%s') $sql_extra LIMIT %d, %d",
intval($user['uid']),

View File

@ -26,6 +26,8 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\APContact;
use Friendica\Model\Contact;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
@ -218,12 +220,8 @@ class Relation
public static function countFollows(int $cid, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $cid]
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
$cid]
);
return DI::dba()->count('contact', $condition);
@ -233,6 +231,7 @@ class Relation
* Returns a paginated list of contacts that are followed the provided public contact.
*
* @param int $cid Public contact id
* @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
@ -240,27 +239,16 @@ class Relation
* @return array
* @throws Exception
*/
public static function listFollows(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
public static function listFollows(int $cid, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $cid]
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
$cid]
);
$follows = DI::dba()->selectToArray(
'contact',
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'RAND()' : 'name']
]
return DI::dba()->selectToArray('contact', $fields, $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
);
return $follows;
}
/**
@ -274,12 +262,8 @@ class Relation
public static function countFollowers(int $cid, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $cid]
['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)',
$cid]
);
return DI::dba()->count('contact', $condition);
@ -289,6 +273,7 @@ class Relation
* Returns a paginated list of contacts that follow the provided public contact.
*
* @param int $cid Public contact id
* @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
@ -296,27 +281,15 @@ class Relation
* @return array
* @throws Exception
*/
public static function listFollowers(int $cid, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
public static function listFollowers(int $cid, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $cid]
['`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)', $cid]
);
$followers = DI::dba()->selectToArray(
'contact',
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'RAND()' : 'name']
]
return DI::dba()->selectToArray('contact', $fields, $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'RAND()' : 'name']]
);
return $followers;
}
/**
@ -332,21 +305,12 @@ class Relation
public static function countCommon(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
)', $sourceId, $targetId]
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ?)',
$sourceId, $targetId]
);
$total = DI::dba()->count('contact', $condition);
return $total;
return DI::dba()->count('contact', $condition);
}
/**
@ -355,6 +319,7 @@ class Relation
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
* @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
@ -362,33 +327,17 @@ class Relation
* @return array
* @throws Exception
*/
public static function listCommon(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
public static function listCommon(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
["`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)", $sourceId, $targetId]
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
$sourceId, $targetId]
);
$contacts = DI::dba()->selectToArray(
'contact',
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
return DI::dba()->selectToArray('contact', $fields, $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
return $contacts;
}
@ -404,23 +353,12 @@ class Relation
public static function countCommonFollows(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)', $sourceId, $targetId]
['`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)',
$sourceId, $targetId]
);
$total = DI::dba()->count('contact', $condition);
return $total;
return DI::dba()->count('contact', $condition);
}
/**
@ -428,6 +366,7 @@ class Relation
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
* @param array $field Field list
* @param array $condition Additional condition array on the contact table
* @param int $count
* @param int $offset
@ -435,33 +374,17 @@ class Relation
* @return array
* @throws Exception
*/
public static function listCommonFollows(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
public static function listCommonFollows(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
["`id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `relation-cid`
FROM `contact-relation`
WHERE `cid` = ?
AND `follows`
)", $sourceId, $targetId]
["`id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)
AND `id` IN (SELECT `relation-cid` FROM `contact-relation` WHERE `cid` = ? AND `follows`)",
$sourceId, $targetId]
);
$contacts = DI::dba()->selectToArray(
'contact',
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
return DI::dba()->selectToArray('contact', $fields, $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
return $contacts;
}
/**
@ -476,23 +399,12 @@ class Relation
public static function countCommonFollowers(int $sourceId, int $targetId, array $condition = [])
{
$condition = DBA::mergeConditions($condition,
['`id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)', $sourceId, $targetId]
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
$sourceId, $targetId]
);
$total = DI::dba()->count('contact', $condition);
return $total;
return DI::dba()->count('contact', $condition);
}
/**
@ -500,6 +412,7 @@ class Relation
*
* @param int $sourceId Public contact id
* @param int $targetId Public contact id
* @param array $field Field list
* @param array $condition Additional condition on the contact table
* @param int $count
* @param int $offset
@ -507,32 +420,16 @@ class Relation
* @return array
* @throws Exception
*/
public static function listCommonFollowers(int $sourceId, int $targetId, array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
public static function listCommonFollowers(int $sourceId, int $targetId, array $fields = [], array $condition = [], int $count = 30, int $offset = 0, bool $shuffle = false)
{
$condition = DBA::mergeConditions($condition,
["`id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)
AND `id` IN (
SELECT `cid`
FROM `contact-relation`
WHERE `relation-cid` = ?
AND `follows`
)", $sourceId, $targetId]
["`id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)
AND `id` IN (SELECT `cid` FROM `contact-relation` WHERE `relation-cid` = ? AND `follows`)",
$sourceId, $targetId]
);
$contacts = DI::dba()->selectToArray(
'contact',
$condition,
[
'limit' => [$offset, $count],
'order' => [$shuffle ? 'name' : 'RAND()'],
]
return DI::dba()->selectToArray('contact', $fields, $condition,
['limit' => [$offset, $count], 'order' => [$shuffle ? 'name' : 'RAND()']]
);
return $contacts;
}
}

View File

@ -22,10 +22,7 @@
namespace Friendica\Model;
use Exception;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Util\DateTimeFormat;
/**
* This class handles GlobalContact related functions
@ -49,7 +46,7 @@ class GContact
$sourceId,
];
return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition);
return Contact\Relation::countCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition);
}
/**
@ -77,7 +74,7 @@ LIMIT 1",
$sourceId,
];
return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, $condition);
return Contact\Relation::countCommonFollowers($sourceId, $targetPublicContact['id'] ?? 0, [], $condition);
}
/**
@ -103,7 +100,7 @@ LIMIT 1",
$sourceId,
];
return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, $condition, $limit, $start, $shuffle);
return Contact\Relation::listCommonFollows($sourceId, $targetIds['public'] ?? 0, [], $condition, $limit, $start, $shuffle);
}
/**
@ -137,34 +134,6 @@ LIMIT 1",
$sourceId,
];
return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, $condition, $limit, $start, $shuffle);
}
/**
* @param integer $uid user
* @param integer $cid cid
* @return integer
* @throws Exception
*/
public static function countAllFriends($uid, $cid)
{
$cids = Contact::getPublicAndUserContacID($cid, $uid);
return Contact\Relation::countFollows($cids['public'] ?? 0);
}
/**
* @param integer $uid user
* @param integer $cid cid
* @param integer $start optional, default 0
* @param integer $limit optional, default 80
* @return array
* @throws Exception
*/
public static function allFriends($uid, $cid, $start = 0, $limit = 80)
{
$cids = Contact::getPublicAndUserContacID($cid, $uid);
return Contact\Relation::listFollows($cids['public'] ?? 0, [], $limit, $start);
return Contact\Relation::listCommonFollows($sourceId, $targetPublicContact['id'] ?? 0, [], $condition, $limit, $start, $shuffle);
}
}

View File

@ -54,34 +54,31 @@ class AllFriends extends BaseModule
$uid = $app->user['uid'];
$contact = Model\Contact::getContactForUser($cid, local_user(), ['name', 'url', 'photo', 'uid', 'id']);
$contact = Model\Contact::getById($cid, []);
if (empty($contact)) {
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid contact.'));
}
DI::page()['aside'] = "";
Model\Profile::load($app, "", Model\Contact::getByURL($contact["url"], false));
Model\Profile::load($app, "", $contact);
$total = Model\GContact::countAllFriends(local_user(), $cid);
$total = Model\Contact\Relation::countFollows($cid);
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
$friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
$friends = Model\Contact\Relation::listFollows($cid, [], [], $pager->getItemsPerPage(), $pager->getStart());
if (empty($friends)) {
return DI::l10n()->t('No friends to display.');
}
$tab_str = Contact::getTabsHTML($app, $contact, 4);
$entries = [];
foreach ($friends as $friend) {
$contact = Model\Contact::getByURLForUser($friend['url'], local_user());
if (!empty($contact)) {
$entries[] = Contact::getContactTemplateVars($contact);
}
$entries[] = Contact::getContactTemplateVars($friend);
}
$tab_str = Contact::getTabsHTML($app, $contact, 4);
$tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
return Renderer::replaceMacros($tpl, [
'$tab_str' => $tab_str,

View File

@ -179,7 +179,7 @@ class Contact extends BaseModule
private static function updateContactFromProbe($contact_id)
{
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
$contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id, 'uid' => [0, local_user()], 'deleted' => false]);
if (!DBA::isResult($contact)) {
return;
}
@ -257,19 +257,21 @@ class Contact extends BaseModule
DI::page()['aside'] = '';
}
$contact_id = null;
$contact = null;
// @TODO: Replace with parameter from router
if ($a->argc == 2 && intval($a->argv[1])
|| $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
) {
$contact_id = intval($a->argv[1]);
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => local_user(), 'deleted' => false]);
if (!DBA::isResult($contact)) {
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => 0, 'deleted' => false]);
// Ensure to use the user contact when the public contact was provided
$data = Model\Contact::getPublicAndUserContacID($contact_id, local_user());
if (!empty($data['user']) && ($contact_id == $data['public'])) {
$contact_id = $data['user'];
}
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'deleted' => false]);
// Don't display contacts that are about to be deleted
if ($contact['network'] == Protocol::PHANTOM) {
$contact = false;
@ -384,9 +386,9 @@ class Contact extends BaseModule
// NOTREACHED
}
if ($cmd === 'updateprofile' && ($orig_record['uid'] != 0)) {
if ($cmd === 'updateprofile') {
self::updateContactFromProbe($contact_id);
DI::baseUrl()->redirect('contact/' . $contact_id . '/advanced/');
DI::baseUrl()->redirect('contact/' . $contact_id);
// NOTREACHED
}
@ -862,11 +864,19 @@ class Contact extends BaseModule
*/
public static function getTabsHTML($a, $contact, $active_tab)
{
$cid = $pcid = $contact['id'];
$data = Model\Contact::getPublicAndUserContacID($contact['id'], local_user());
if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
$cid = $data['user'];
} elseif (!empty($data['public'])) {
$pcid = $data['public'];
}
// tabs
$tabs = [
[
'label' => DI::l10n()->t('Status'),
'url' => "contact/" . $contact['id'] . "/conversations",
'url' => "contact/" . $pcid . "/conversations",
'sel' => (($active_tab == 1) ? 'active' : ''),
'title' => DI::l10n()->t('Conversations started by this contact'),
'id' => 'status-tab',
@ -874,7 +884,7 @@ class Contact extends BaseModule
],
[
'label' => DI::l10n()->t('Posts and Comments'),
'url' => "contact/" . $contact['id'] . "/posts",
'url' => "contact/" . $pcid . "/posts",
'sel' => (($active_tab == 2) ? 'active' : ''),
'title' => DI::l10n()->t('Status Messages and Posts'),
'id' => 'posts-tab',
@ -882,7 +892,7 @@ class Contact extends BaseModule
],
[
'label' => DI::l10n()->t('Profile'),
'url' => "contact/" . $contact['id'],
'url' => "contact/" . $cid,
'sel' => (($active_tab == 3) ? 'active' : ''),
'title' => DI::l10n()->t('Profile Details'),
'id' => 'profile-tab',
@ -891,10 +901,10 @@ class Contact extends BaseModule
];
// Show this tab only if there is visible friend list
$x = Model\GContact::countAllFriends(local_user(), $contact['id']);
$x = Model\Contact\Relation::countFollows($pcid);
if ($x) {
$tabs[] = ['label' => DI::l10n()->t('Contacts'),
'url' => "allfriends/" . $contact['id'],
'url' => "allfriends/" . $pcid,
'sel' => (($active_tab == 4) ? 'active' : ''),
'title' => DI::l10n()->t('View all contacts'),
'id' => 'allfriends-tab',
@ -902,10 +912,10 @@ class Contact extends BaseModule
}
// Show this tab only if there is visible common friend list
$common = Model\GContact::countCommonFriends(local_user(), $contact['id']);
$common = Model\GContact::countCommonFriends(local_user(), $cid);
if ($common) {
$tabs[] = ['label' => DI::l10n()->t('Common Friends'),
'url' => "common/loc/" . local_user() . "/" . $contact['id'],
'url' => "common/loc/" . local_user() . "/" . $cid,
'sel' => (($active_tab == 5) ? 'active' : ''),
'title' => DI::l10n()->t('View all common friends'),
'id' => 'common-loc-tab',
@ -913,9 +923,9 @@ class Contact extends BaseModule
];
}
if (!empty($contact['uid'])) {
if ($cid != $pcid) {
$tabs[] = ['label' => DI::l10n()->t('Advanced'),
'url' => 'contact/' . $contact['id'] . '/advanced/',
'url' => 'contact/' . $cid . '/advanced/',
'sel' => (($active_tab == 6) ? 'active' : ''),
'title' => DI::l10n()->t('Advanced Contact Settings'),
'id' => 'advanced-tab',
@ -1011,6 +1021,15 @@ class Contact extends BaseModule
{
$alt_text = '';
if (!empty($contact['url']) && isset($contact['uid']) && ($contact['uid'] == 0) && local_user()) {
$personal = Model\Contact::getByURL($contact['url'], false, ['uid', 'rel', 'self'], local_user());
if (!empty($personal)) {
$contact['uid'] = $personal['uid'];
$contact['rel'] = $personal['rel'];
$contact['self'] = $personal['self'];
}
}
if (!empty($contact['uid']) && !empty($contact['rel'])) {
switch ($contact['rel']) {
case Model\Contact::FRIEND:
@ -1105,6 +1124,16 @@ class Contact extends BaseModule
];
}
if (in_array($contact['network'], Protocol::FEDERATED)) {
$contact_actions['updateprofile'] = [
'label' => DI::l10n()->t('Refetch contact data'),
'url' => 'contact/' . $contact['id'] . '/updateprofile',
'title' => '',
'sel' => '',
'id' => 'updateprofile',
];
}
$contact_actions['block'] = [
'label' => (intval($contact['blocked']) ? DI::l10n()->t('Unblock') : DI::l10n()->t('Block')),
'url' => 'contact/' . $contact['id'] . '/block',

View File

@ -538,68 +538,6 @@ return [
"PRIMARY" => ["id"],
]
],
"gcontact" => [
"comment" => "global contacts",
"fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this contact is known by"],
"nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Nick- and user name of the contact"],
"url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the contacts profile page"],
"nurl" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile photo"],
"connect" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
"updated" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
"last_contact" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
"last_failure" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
"last_discovery" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => "Date of the last contact discovery"],
"failed" => ["type" => "boolean", "comment" => "Connection failed"],
"archive_date" => ["type" => "datetime", "default" => DBA::NULL_DATETIME, "comment" => ""],
"archived" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"about" => ["type" => "text", "comment" => ""],
"keywords" => ["type" => "text", "comment" => "puplic keywords (interests)"],
"gender" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Deprecated"],
"birthday" => ["type" => "varchar(32)", "not null" => "1", "default" => DBA::NULL_DATE, "comment" => ""],
"community" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 if contact is forum account"],
"contact-type" => ["type" => "tinyint", "not null" => "1", "default" => "-1", "comment" => ""],
"hide" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = should be hidden from search"],
"nsfw" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 = contact posts nsfw content"],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "social network protocol"],
"addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"notify" => ["type" => "varchar(255)", "comment" => ""],
"alias" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"generation" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"server_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "baseurl of the contacts server"],
"gsid" => ["type" => "int unsigned", "foreign" => ["gserver" => "id", "on delete" => "restrict"], "comment" => "Global Server ID"],
],
"indexes" => [
"PRIMARY" => ["id"],
"nurl" => ["UNIQUE", "nurl(190)"],
"name" => ["name(64)"],
"nick" => ["nick(32)"],
"addr" => ["addr(64)"],
"hide_network_updated" => ["hide", "network", "updated"],
"updated" => ["updated"],
"gsid" => ["gsid"]
]
],
"glink" => [
"comment" => "'friends of friends' linkages derived from poco",
"fields" => [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
"gcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
"zcid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
"updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
],
"indexes" => [
"PRIMARY" => ["id"],
"cid_uid_gcid_zcid" => ["UNIQUE", "cid", "uid", "gcid", "zcid"],
"gcid" => ["gcid"],
]
],
"group" => [
"comment" => "privacy groups, group info",
"fields" => [

View File

@ -21,7 +21,8 @@
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="contact-edit-actions-button" aria-haspopup="true" id="contact-actions-menu" >
{{if $lblsuggest}}<li role="presentation"><a role="menuitem" href="{{$contact_actions.suggest.url}}" title="{{$contact_actions.suggest.title}}">{{$contact_actions.suggest.label}}</a></li>{{/if}}
{{if $poll_enabled}}<li role="presentation"><a role="menuitem" href="{{$contact_actions.update.url}}" title="{{$contact_actions.update.title}}">{{$contact_actions.update.label}}</a></li>{{/if}}
{{if $lblsuggest || $poll_enabled}}
{{if $contact_actions.updateprofile}}<li role="presentation"><a role="menuitem" href="{{$contact_actions.updateprofile.url}}" title="{{$contact_actions.updateprofile.title}}">{{$contact_actions.updateprofile.label}}</a></li>{{/if}}
{{if $lblsuggest || $poll_enabled || $contact_actions.updateprofile}}
<li role="presentation" class="divider"></li>
{{/if}}
<li role="presentation"><a role="menuitem" href="{{$contact_actions.block.url}}" title="{{$contact_actions.block.title}}">{{$contact_actions.block.label}}</a></li>

View File

@ -193,15 +193,15 @@ function frio_remote_nav($a, &$nav)
// since $userinfo isn't available for the hook we write it to the nav array
// this isn't optimal because the contact query will be done now twice
$fields = ['id', 'url', 'avatar', 'micro', 'name', 'nick', 'baseurl'];
if (local_user() && !empty($a->user['uid'])) {
$remoteUser = Contact::getById($a->user['uid'], ['id', 'url', 'avatar', 'micro', 'name', 'nick']);
$remoteUser = Contact::getById($a->user['uid'], $fields);
$remoteUser['name'] = $a->user['username'];
} elseif (!local_user() && remote_user()) {
$remoteUser = Contact::getById(remote_user(), ['id', 'url', 'avatar', 'micro', 'name', 'nick']);
$remoteUser = Contact::getById(remote_user(), $fields);
$nav['remote'] = DI::l10n()->t('Guest');
} elseif (Model\Profile::getMyURL()) {
$remoteUser = Contact::getByURL($homelink, ['id', 'url', 'avatar', 'micro', 'name', 'nick']);
$remoteUser = Contact::getByURL($homelink, $fields);
$nav['remote'] = DI::l10n()->t('Visitor');
} else {
$remoteUser = null;