Handling of unlisted posts, better uid detection

This commit is contained in:
Michael 2018-09-16 09:06:09 +00:00
parent 1f98414bdd
commit 6f3b2b6586
4 changed files with 73 additions and 76 deletions

View file

@ -1322,33 +1322,27 @@ class Contact extends BaseObject
require_once 'include/conversation.php';
// There are no posts with "uid = 0" with connector networks
// This speeds up the query a lot
$r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact`
WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
DBA::escape(normalise_link($contact_url))
);
$cid = Self::getIdForURL($contact_url);
if (!DBA::isResult($r)) {
$contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
if (!DBA::isResult($contact)) {
return '';
}
if (in_array($r[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
if (in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
$sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))";
} else {
$sql = "`item`.`uid` = ?";
}
$author_id = intval($r[0]["author-id"]);
$contact = ($r[0]["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
$contact_field = ($contact["contact-type"] == self::ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
if ($thread_mode) {
$condition = ["`$contact` = ? AND `gravity` = ? AND " . $sql,
$author_id, GRAVITY_PARENT, local_user()];
$condition = ["`$contact_field` = ? AND `gravity` = ? AND " . $sql,
$cid, GRAVITY_PARENT, local_user()];
} else {
$condition = ["`$contact` = ? AND `gravity` IN (?, ?) AND " . $sql,
$author_id, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
$condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
$cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
}
$params = ['order' => ['created' => true],

View file

@ -2071,6 +2071,7 @@ class Item extends BaseObject
$users = [];
/// @todo add a field "pcid" in the contact table that referrs to the public contact id.
$owner = DBA::selectFirst('contact', ['url', 'nurl', 'alias'], ['id' => $parent['owner-id']]);
if (!DBA::isResult($owner)) {
return;
@ -2110,43 +2111,7 @@ class Item extends BaseObject
}
DBA::close($contacts);
}
/*
$condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)",
$parent['owner-id'], Contact::SHARING, Contact::FRIEND];
$contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) {
$users[$contact['uid']] = $contact['uid'];
}
DBA::close($contacts);
// And the same with the alias in the user contacts
$condition = ["`alias` IN (SELECT `url` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)",
$parent['owner-id'], Contact::SHARING, Contact::FRIEND];
$contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) {
$users[$contact['uid']] = $contact['uid'];
}
DBA::close($contacts);
// And vice versa
$condition = ["`url` IN (SELECT `alias` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)",
$parent['owner-id'], Contact::SHARING, Contact::FRIEND];
$contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) {
$users[$contact['uid']] = $contact['uid'];
}
DBA::close($contacts);
*/
$origin_uid = 0;
if ($item['uri'] != $item['parent-uri']) {