Merge pull request #10484 from annando/use-account-view

We now use the new account-user-view (and fixed the function name)
This commit is contained in:
Hypolite Petovan 2021-07-11 22:56:23 -04:00 committed by GitHub
commit 07ef1edfd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 99 additions and 38 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2021.09-dev (Siberian Iris) -- Friendica 2021.09-dev (Siberian Iris)
-- DB_UPDATE_VERSION 1428 -- DB_UPDATE_VERSION 1429
-- ------------------------------------------ -- ------------------------------------------

View file

@ -1287,11 +1287,11 @@ class BBCode
* @return string * @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function convertForUriId(int $uriid = 0, string $text = null, int $simple_html = self::INTERNAL) public static function convertForUriId(int $uriid = null, string $text = null, int $simple_html = self::INTERNAL)
{ {
$try_oembed = ($simple_html == self::INTERNAL); $try_oembed = ($simple_html == self::INTERNAL);
return self::convert($text, $try_oembed, $simple_html, false, $uriid); return self::convert($text ?? '', $try_oembed, $simple_html, false, $uriid ?? 0);
} }
/** /**

View file

@ -45,7 +45,8 @@ class PostUpdate
{ {
// Needed for the helper function to read from the legacy term table // Needed for the helper function to read from the legacy term table
const OBJECT_TYPE_POST = 1; const OBJECT_TYPE_POST = 1;
const VERSION = 1400;
const VERSION = 1427;
/** /**
* Calls the post update functions * Calls the post update functions

View file

@ -60,7 +60,7 @@ class Account extends BaseFactory
*/ */
public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account public function createFromContactId(int $contactId, $uid = 0): \Friendica\Object\Api\Mastodon\Account
{ {
$cdata = Contact::getPublicAndUserContacID($contactId, $uid); $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) { if (!empty($cdata)) {
$publicContact = Contact::getById($cdata['public']); $publicContact = Contact::getById($cdata['public']);
$userContact = Contact::getById($cdata['user']); $userContact = Contact::getById($cdata['user']);

View file

@ -49,7 +49,7 @@ class FollowRequest extends BaseFactory
*/ */
public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\FollowRequest public function createFromIntroduction(Introduction $introduction): \Friendica\Object\Api\Mastodon\FollowRequest
{ {
$cdata = Contact::getPublicAndUserContacID($introduction->{'contact-id'}, $introduction->uid); $cdata = Contact::getPublicAndUserContactID($introduction->{'contact-id'}, $introduction->uid);
if (empty($cdata)) { if (empty($cdata)) {
$this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]); $this->logger->warning('Wrong introduction data', ['Introduction' => $introduction]);

View file

@ -36,7 +36,7 @@ class Relationship extends BaseFactory
*/ */
public function createFromContactId(int $contactId, int $uid): RelationshipEntity public function createFromContactId(int $contactId, int $uid): RelationshipEntity
{ {
$cdata = Contact::getPublicAndUserContacID($contactId, $uid); $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) { if (!empty($cdata)) {
$cid = $cdata['user']; $cid = $cdata['user'];
} else { } else {

View file

@ -39,7 +39,7 @@ class User extends BaseFactory
*/ */
public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true) public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true)
{ {
$cdata = Contact::getPublicAndUserContacID($contactId, $uid); $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if (!empty($cdata)) { if (!empty($cdata)) {
$publicContact = Contact::getById($cdata['public']); $publicContact = Contact::getById($cdata['public']);
$userContact = Contact::getById($cdata['user']); $userContact = Contact::getById($cdata['user']);

View file

@ -332,7 +332,7 @@ class Contact
return false; return false;
} }
$cdata = self::getPublicAndUserContacID($cid, $uid); $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
return false; return false;
} }
@ -378,7 +378,7 @@ class Contact
return false; return false;
} }
$cdata = self::getPublicAndUserContacID($cid, $uid); $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
return false; return false;
} }
@ -507,7 +507,48 @@ class Contact
* @throws HTTPException\InternalServerErrorException * @throws HTTPException\InternalServerErrorException
* @throws \ImagickException * @throws \ImagickException
*/ */
public static function getPublicAndUserContacID($cid, $uid) public static function getPublicAndUserContactID($cid, $uid)
{
// We have to use the legacy function as long as the post update hasn't finished
if (DI::config()->get('system', 'post_update_version') < 1427) {
return self::legacyGetPublicAndUserContactID($cid, $uid);
}
if (empty($uid) || empty($cid)) {
return [];
}
$contact = DBA::selectFirst('account-user-view', ['id', 'uid', 'pid'], ['id' => $cid]);
if (!DBA::isResult($contact) || !in_array($contact['uid'], [0, $uid])) {
return [];
}
$pcid = $contact['pid'];
if ($contact['uid'] == $uid) {
$ucid = $contact['id'];
} else {
$contact = DBA::selectFirst('account-user-view', ['id', 'uid'], ['pid' => $cid, 'uid' => $uid]);
if (DBA::isResult($contact)) {
$ucid = $contact['id'];
} else {
$ucid = 0;
}
}
return ['public' => $pcid, 'user' => $ucid];
}
/**
* Helper function for "getPublicAndUserContactID"
*
* @param int $cid Either public contact id or user's contact id
* @param int $uid User ID
*
* @return array with public and user's contact id
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
private static function legacyGetPublicAndUserContactID($cid, $uid)
{ {
if (empty($uid) || empty($cid)) { if (empty($uid) || empty($cid)) {
return []; return [];
@ -2588,7 +2629,7 @@ class Contact
*/ */
public static function unfollow(int $cid, int $uid) public static function unfollow(int $cid, int $uid)
{ {
$cdata = self::getPublicAndUserContacID($cid, $uid); $cdata = self::getPublicAndUserContactID($cid, $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
return false; return false;
} }

View file

@ -39,7 +39,7 @@ class User
*/ */
public static function setBlocked($cid, $uid, $blocked) public static function setBlocked($cid, $uid, $blocked)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return; return;
} }
@ -62,7 +62,7 @@ class User
*/ */
public static function isBlocked($cid, $uid) public static function isBlocked($cid, $uid)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return false; return false;
} }
@ -102,7 +102,7 @@ class User
*/ */
public static function setIgnored($cid, $uid, $ignored) public static function setIgnored($cid, $uid, $ignored)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return; return;
} }
@ -125,7 +125,7 @@ class User
*/ */
public static function isIgnored($cid, $uid) public static function isIgnored($cid, $uid)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return false; return false;
} }
@ -165,7 +165,7 @@ class User
*/ */
public static function setCollapsed($cid, $uid, $collapsed) public static function setCollapsed($cid, $uid, $collapsed)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return; return;
} }
@ -185,7 +185,7 @@ class User
*/ */
public static function isCollapsed($cid, $uid) public static function isCollapsed($cid, $uid)
{ {
$cdata = Contact::getPublicAndUserContacID($cid, $uid); $cdata = Contact::getPublicAndUserContactID($cid, $uid);
if (empty($cdata)) { if (empty($cdata)) {
return; return;
} }

View file

@ -52,7 +52,7 @@ class Lists extends BaseApi
$lists = []; $lists = [];
$cdata = Contact::getPublicAndUserContacID($id, $uid); $cdata = Contact::getPublicAndUserContactID($id, $uid);
if (!empty($cdata['user'])) { if (!empty($cdata['user'])) {
$groups = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]); $groups = DBA::select('group_member', ['gid'], ['contact-id' => $cdata['user']]);
while ($group = DBA::fetch($groups)) { while ($group = DBA::fetch($groups)) {

View file

@ -45,7 +45,7 @@ class Note extends BaseApi
'comment' => '', 'comment' => '',
]); ]);
$cdata = Contact::getPublicAndUserContacID($parameters['id'], $uid); $cdata = Contact::getPublicAndUserContactID($parameters['id'], $uid);
if (empty($cdata['user'])) { if (empty($cdata['user'])) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }

View file

@ -46,7 +46,7 @@ class VerifyCredentials extends BaseApi
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }
$cdata = Contact::getPublicAndUserContacID($self['id'], $uid); $cdata = Contact::getPublicAndUserContactID($self['id'], $uid);
if (empty($cdata)) { if (empty($cdata)) {
DI::mstdnError()->InternalError(); DI::mstdnError()->InternalError();
} }

View file

@ -205,7 +205,7 @@ abstract class ContactEndpoint extends BaseApi
// Conversion to public contact ids // Conversion to public contact ids
array_walk($ids, function (&$contactId) use ($uid, $stringify_ids) { array_walk($ids, function (&$contactId) use ($uid, $stringify_ids) {
$cdata = Contact::getPublicAndUserContacID($contactId, $uid); $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
if ($stringify_ids) { if ($stringify_ids) {
$contactId = (string)$cdata['public']; $contactId = (string)$cdata['public'];
} else { } else {

View file

@ -283,7 +283,7 @@ class Contact extends BaseModule
$contact_id = intval($a->argv[1]); $contact_id = intval($a->argv[1]);
// Ensure to use the user contact when the public contact was provided // Ensure to use the user contact when the public contact was provided
$data = Model\Contact::getPublicAndUserContacID($contact_id, local_user()); $data = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
if (!empty($data['user']) && ($contact_id == $data['public'])) { if (!empty($data['user']) && ($contact_id == $data['public'])) {
$contact_id = $data['user']; $contact_id = $data['user'];
} }
@ -915,7 +915,7 @@ class Contact extends BaseModule
public static function getTabsHTML(array $contact, int $active_tab) public static function getTabsHTML(array $contact, int $active_tab)
{ {
$cid = $pcid = $contact['id']; $cid = $pcid = $contact['id'];
$data = Model\Contact::getPublicAndUserContacID($contact['id'], local_user()); $data = Model\Contact::getPublicAndUserContactID($contact['id'], local_user());
if (!empty($data['user']) && ($contact['id'] == $data['public'])) { if (!empty($data['user']) && ($contact['id'] == $data['public'])) {
$cid = $data['user']; $cid = $data['user'];
} elseif (!empty($data['public'])) { } elseif (!empty($data['public'])) {

View file

@ -345,7 +345,7 @@ class Transmitter
} }
if (!empty($owner['about'])) { if (!empty($owner['about'])) {
$data['summary'] = BBCode::convertForUriId($owner['uri-id'], $owner['about'], BBCode::EXTERNAL); $data['summary'] = BBCode::convertForUriId($owner['uri-id'] ?? 0, $owner['about'], BBCode::EXTERNAL);
} }
$data['url'] = $owner['url']; $data['url'] = $owner['url'];

View file

@ -161,7 +161,7 @@ class PermissionSet extends BaseRepository
*/ */
public function selectByContactId($contact_id, $uid) public function selectByContactId($contact_id, $uid)
{ {
$cdata = Model\Contact::getPublicAndUserContacID($contact_id, $uid); $cdata = Model\Contact::getPublicAndUserContactID($contact_id, $uid);
if (!empty($cdata)) { if (!empty($cdata)) {
$public_contact_str = '<' . $cdata['public'] . '>'; $public_contact_str = '<' . $cdata['public'] . '>';
$user_contact_str = '<' . $cdata['user'] . '>'; $user_contact_str = '<' . $cdata['user'] . '>';

View file

@ -55,7 +55,7 @@
use Friendica\Database\DBA; use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1428); define('DB_UPDATE_VERSION', 1429);
} }
return [ return [

View file

@ -945,3 +945,22 @@ function update_1419()
} }
return Update::SUCCESS; return Update::SUCCESS;
} }
function update_1429()
{
if (!DBA::e("UPDATE `contact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
return Update::FAILED;
}
if (!DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
return Update::FAILED;
}
if (!DBA::e("UPDATE `apcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
return Update::FAILED;
}
DI::config()->set("system", "post_update_version", 1423);
return Update::SUCCESS;
}