mirror of
https://github.com/friendica/friendica
synced 2025-05-09 14:24:15 +02:00
Add additional direction types
This commit is contained in:
parent
cb647b5b6c
commit
5a41cd437d
8 changed files with 102 additions and 47 deletions
|
@ -26,6 +26,7 @@ use Friendica\Content\Text\BBCode;
|
|||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\APContact;
|
||||
|
@ -353,7 +354,7 @@ class Processor
|
|||
DBA::close($items);
|
||||
|
||||
if (count($original) != count($receivers)) {
|
||||
Logger::info('Improved data', ['id' => $activity['id'], 'object' => $activity['object_id'], 'original' => $original, 'improved' => $receivers]);
|
||||
Logger::info('Improved data', ['id' => $activity['id'], 'object' => $activity['object_id'], 'original' => $original, 'improved' => $receivers, 'callstack' => System::callstack()]);
|
||||
}
|
||||
|
||||
return $receivers;
|
||||
|
@ -544,6 +545,9 @@ class Processor
|
|||
case Receiver::TARGET_FOLLOWER:
|
||||
$item['post-type'] = Item::PT_FOLLOWER;
|
||||
break;
|
||||
case Receiver::TARGET_ANSWER:
|
||||
$item['post-type'] = Item::PT_COMMENT;
|
||||
break;
|
||||
default:
|
||||
$item['post-type'] = Item::PT_ARTICLE;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ class Receiver
|
|||
const TARGET_BTO = 3;
|
||||
const TARGET_BCC = 4;
|
||||
const TARGET_FOLLOWER = 5;
|
||||
const TARGET_ANSWER = 6;
|
||||
|
||||
/**
|
||||
* Checks if the web request is done for the AP protocol
|
||||
|
@ -233,7 +234,7 @@ class Receiver
|
|||
if (!empty($uid)) {
|
||||
$additional = ['uid:' . $uid => $uid];
|
||||
$receivers = array_merge($receivers, $additional);
|
||||
if (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER])) {
|
||||
if (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER])) {
|
||||
$reception_types[$uid] = self::TARGET_BCC;
|
||||
}
|
||||
} else {
|
||||
|
@ -317,7 +318,7 @@ class Receiver
|
|||
$object_data['actor'] = $actor;
|
||||
$object_data['item_receiver'] = $receivers;
|
||||
$object_data['receiver'] = array_merge($object_data['receiver'] ?? [], $receivers);
|
||||
$object_data['reception_type'] = $reception_types;
|
||||
$object_data['reception_type'] = array_merge($object_data['reception_type'] ?? [], $reception_types);
|
||||
|
||||
$author = $object_data['author'] ?? $actor;
|
||||
if (!empty($author) && !empty($object_data['id'])) {
|
||||
|
@ -544,18 +545,30 @@ class Receiver
|
|||
*/
|
||||
private static function getReceivers($activity, $actor, $tags = [], $fetch_unlisted = false)
|
||||
{
|
||||
$receivers = [];
|
||||
$reply = $receivers = [];
|
||||
|
||||
// When it is an answer, we inherite the receivers from the parent
|
||||
$replyto = JsonLD::fetchElement($activity, 'as:inReplyTo', '@id');
|
||||
if (!empty($replyto)) {
|
||||
$reply = [$replyto];
|
||||
|
||||
// Fix possibly wrong item URI (could be an answer to a plink uri)
|
||||
$fixedReplyTo = Item::getURIByLink($replyto);
|
||||
$replyto = $fixedReplyTo ?: $replyto;
|
||||
if (!empty($fixedReplyTo)) {
|
||||
$reply[] = $fixedReplyTo;
|
||||
}
|
||||
}
|
||||
|
||||
$parents = Item::select(['uid'], ['uri' => $replyto]);
|
||||
// Fetch all posts that refer to the object id
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||
if (!empty($object_id)) {
|
||||
$reply[] = $object_id;
|
||||
}
|
||||
|
||||
if (!empty($reply)) {
|
||||
$parents = Item::select(['uid'], ['uri' => $reply]);
|
||||
while ($parent = Item::fetch($parents)) {
|
||||
$receivers['uid:' . $parent['uid']] = ['uid' => $parent['uid']];
|
||||
$receivers['uid:' . $parent['uid']] = ['uid' => $parent['uid'], 'type' => self::TARGET_ANSWER];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -616,7 +629,7 @@ class Receiver
|
|||
}
|
||||
|
||||
$type = $receivers['uid:' . $contact['uid']]['type'] ?? self::TARGET_UNKNOWN;
|
||||
if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER])) {
|
||||
if (in_array($type, [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER])) {
|
||||
switch ($element) {
|
||||
case 'as:to':
|
||||
$type = self::TARGET_TO;
|
||||
|
@ -1263,12 +1276,14 @@ class Receiver
|
|||
}
|
||||
|
||||
$receiverdata = self::getReceivers($object, $object_data['actor'], $object_data['tags'], true);
|
||||
$receivers = [];
|
||||
$receivers = $reception_types = [];
|
||||
foreach ($receiverdata as $key => $data) {
|
||||
$receivers[$key] = $data['uid'];
|
||||
$reception_types[$data['uid']] = $data['type'] ?? 0;
|
||||
}
|
||||
|
||||
$object_data['receiver'] = $receivers;
|
||||
$object_data['reception_type'] = $reception_types;
|
||||
|
||||
$object_data['unlisted'] = in_array(-1, $object_data['receiver']);
|
||||
unset($object_data['receiver']['uid:-1']);
|
||||
|
|
|
@ -1499,8 +1499,9 @@ class DFRN
|
|||
|
||||
$fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr',
|
||||
'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type'];
|
||||
$condition = ["`uid` = ? AND `nurl` = ? AND `network` != ?",
|
||||
$importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET];
|
||||
$condition = ["`uid` = ? AND `nurl` = ? AND `network` != ? AND NOT `pending` AND NOT `blocked` AND `rel` IN (?, ?)",
|
||||
$importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET,
|
||||
Contact::SHARING, Contact::FRIEND];
|
||||
$contact_old = DBA::selectFirst('contact', $fields, $condition);
|
||||
|
||||
if (DBA::isResult($contact_old)) {
|
||||
|
@ -1512,8 +1513,9 @@ class DFRN
|
|||
}
|
||||
|
||||
$author["contact-unknown"] = true;
|
||||
$author["contact-id"] = $importer["id"];
|
||||
$author["network"] = $importer["network"];
|
||||
$contact = Contact::getByURL($author["link"], null, ["contact-id", "network"]);
|
||||
$author["contact-id"] = $contact["id"] ?? $importer["id"];
|
||||
$author["network"] = $contact["network"] ?? $importer["network"];
|
||||
$onlyfetch = true;
|
||||
}
|
||||
|
||||
|
@ -2534,6 +2536,11 @@ class DFRN
|
|||
}
|
||||
|
||||
if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
|
||||
// Will be overwritten for sharing accounts in Item::insert
|
||||
if (empty($item['post-type']) && ($entrytype == DFRN::REPLY)) {
|
||||
$item['post-type'] = Item::PT_COMMENT;
|
||||
}
|
||||
|
||||
$posted_id = Item::insert($item);
|
||||
if ($posted_id) {
|
||||
Logger::log("Reply from contact ".$item["contact-id"]." was stored with id ".$posted_id, Logger::DEBUG);
|
||||
|
|
|
@ -1735,6 +1735,9 @@ class Diaspora
|
|||
$datarray["owner-link"] = $contact["url"];
|
||||
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
|
||||
|
||||
// Will be overwritten for sharing accounts in Item::insert
|
||||
$datarray['post-type'] = Item::PT_COMMENT;
|
||||
|
||||
$datarray["guid"] = $guid;
|
||||
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
||||
$datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue