Merge pull request #7460 from annando/contact-id-new
Improved PR 7452: We now respect the "self" contact
This commit is contained in:
commit
f293d17ec3
|
@ -1234,35 +1234,19 @@ class Item extends BaseObject
|
||||||
|
|
||||||
private static function contactId($item)
|
private static function contactId($item)
|
||||||
{
|
{
|
||||||
$contact_id = (int)$item["contact-id"];
|
if (!empty($item['contact-id']) && DBA::exists('contact', ['self' => true, 'id' => $item['contact-id']])) {
|
||||||
|
return $item['contact-id'];
|
||||||
if (!empty($contact_id)) {
|
} elseif (!empty($item['uid']) && !Contact::isSharing($item['author-id'], $item['uid'])) {
|
||||||
return $contact_id;
|
return $item['author-id'];
|
||||||
}
|
} elseif (!empty($item['contact-id'])) {
|
||||||
Logger::log('Missing contact-id. Called by: '.System::callstack(), Logger::DEBUG);
|
return $item['contact-id'];
|
||||||
/*
|
} else {
|
||||||
* First we are looking for a suitable contact that matches with the author of the post
|
|
||||||
* This is done only for comments
|
|
||||||
*/
|
|
||||||
if ($item['parent-uri'] != $item['uri']) {
|
|
||||||
$contact_id = Contact::getIdForURL($item['author-link'], $item['uid']);
|
$contact_id = Contact::getIdForURL($item['author-link'], $item['uid']);
|
||||||
}
|
if (!empty($contact_id)) {
|
||||||
|
return $contact_id;
|
||||||
// If not present then maybe the owner was found
|
|
||||||
if ($contact_id == 0) {
|
|
||||||
$contact_id = Contact::getIdForURL($item['owner-link'], $item['uid']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Still missing? Then use the "self" contact of the current user
|
|
||||||
if ($contact_id == 0) {
|
|
||||||
$self = DBA::selectFirst('contact', ['id'], ['self' => true, 'uid' => $item['uid']]);
|
|
||||||
if (DBA::isResult($self)) {
|
|
||||||
$contact_id = $self["id"];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Logger::log("Contact-id was missing for post ".$item['guid']." from user id ".$item['uid']." - now set to ".$contact_id, Logger::DEBUG);
|
return $item['author-id'];
|
||||||
|
|
||||||
return $contact_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function will finally cover most of the preparation functionality in mod/item.php
|
// This function will finally cover most of the preparation functionality in mod/item.php
|
||||||
|
@ -1487,9 +1471,6 @@ class Item extends BaseObject
|
||||||
|
|
||||||
$item['plink'] = defaults($item, 'plink', System::baseUrl() . '/display/' . urlencode($item['guid']));
|
$item['plink'] = defaults($item, 'plink', System::baseUrl() . '/display/' . urlencode($item['guid']));
|
||||||
|
|
||||||
// The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
|
|
||||||
$item["contact-id"] = self::contactId($item);
|
|
||||||
|
|
||||||
$default = ['url' => $item['author-link'], 'name' => $item['author-name'],
|
$default = ['url' => $item['author-link'], 'name' => $item['author-name'],
|
||||||
'photo' => $item['author-avatar'], 'network' => $item['network']];
|
'photo' => $item['author-avatar'], 'network' => $item['network']];
|
||||||
|
|
||||||
|
@ -1545,6 +1526,9 @@ class Item extends BaseObject
|
||||||
unset($item['causer-id']);
|
unset($item['causer-id']);
|
||||||
unset($item['causer-link']);
|
unset($item['causer-link']);
|
||||||
|
|
||||||
|
// The contact-id should be set before "self::insert" was called - but there seems to be issues sometimes
|
||||||
|
$item["contact-id"] = self::contactId($item);
|
||||||
|
|
||||||
if ($item['network'] == Protocol::PHANTOM) {
|
if ($item['network'] == Protocol::PHANTOM) {
|
||||||
$item['network'] = Protocol::DFRN;
|
$item['network'] = Protocol::DFRN;
|
||||||
Logger::notice('Missing network, setting to {network}.', [
|
Logger::notice('Missing network, setting to {network}.', [
|
||||||
|
|
Loading…
Reference in a new issue