diff --git a/include/conversation.php b/include/conversation.php
index 8fd9725aa..a995ea4ad 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -741,32 +741,39 @@ function conversation_fetch_comments($thread_items, $pinned) {
$direction = ['direction' => 5, 'title' => DI::l10n()->t('%s commented on this.', $row['author-name'])];
}
- if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])) {
- if (Contact::isSharing($row['author-id'], $row['uid'])) {
+ switch ($row['post-type']) {
+ case Item::PT_TO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
+ break;
+ case Item::PT_CC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
+ break;
+ case Item::PT_BTO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
+ break;
+ case Item::PT_BCC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
+ break;
+ case Item::PT_FOLLOWER:
$row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
- } else {
- if ($row['post-type'] == Item::PT_TAG) {
- $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
- }
- $parentlines[] = $lineno;
- }
+ break;
+ case Item::PT_TAG:
+ $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
+ break;
+ case Item::PT_ANNOUNCEMENT:
+ $row['direction'] = ['direction' => 3, 'title' => DI::l10n()->t('Reshared')];
+ break;
+ case Item::PT_COMMENT:
+ $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
+ break;
+ case Item::PT_STORED:
+ $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
+ break;
+ }
- switch ($row['post-type']) {
- case Item::PT_TO:
- $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
- break;
- case Item::PT_CC:
- $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
- break;
- case Item::PT_BTO:
- $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
- break;
- case Item::PT_BCC:
- $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
- break;
- case Item::PT_FOLLOWER:
- $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
- }
+ if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) &&
+ !Contact::isSharing($row['author-id'], $row['uid'])) {
+ $parentlines[] = $lineno;
}
if ($row['gravity'] == GRAVITY_PARENT) {
diff --git a/src/Model/Item.php b/src/Model/Item.php
index 8c5a851eb..4cc68c649 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -62,6 +62,9 @@ class Item
const PT_BTO = 67;
const PT_BCC = 68;
const PT_FOLLOWER = 69;
+ const PT_ANNOUNCEMENT = 70;
+ const PT_COMMENT = 71;
+ const PT_STORED = 72;
const PT_PERSONAL_NOTE = 128;
// Field list that is used to display the items
@@ -1696,6 +1699,11 @@ class Item
'photo' => $item['owner-avatar'], 'network' => $item['network']];
$item['owner-id'] = ($item['owner-id'] ?? 0) ?: Contact::getIdForURL($item['owner-link'], 0, null, $default);
+ $actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
+ if (!$item['origin'] && in_array($item['post-type'], [self::PT_ARTICLE, self::PT_COMMENT]) && Contact::isSharing($actor, $item['uid'])) {
+ $item['post-type'] = self::PT_FOLLOWER;
+ }
+
// Ensure that there is an avatar cache
Contact::checkAvatarCache($item['author-id']);
Contact::checkAvatarCache($item['owner-id']);
@@ -1998,10 +2006,10 @@ class Item
*/
private static function setOwnerforResharedItem(array $item)
{
- $parent = self::selectFirst(['id', 'owner-id', 'author-id', 'author-link', 'origin'],
- ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
+ $parent = self::selectFirst(['id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-type'],
+ ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
if (!DBA::isResult($parent)) {
- Logger::error('Parent not found', ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid']]);
+ Logger::error('Parent not found', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
return;
}
@@ -2011,19 +2019,24 @@ class Item
return;
}
- if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
- logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
- return;
- }
-
$cid = Contact::getIdForURL($author['url'], $item['uid']);
if (empty($cid) || !Contact::isSharing($cid, $item['uid'])) {
logger::info('The resharer is not a following contact: quit', ['resharer' => $author['url'], 'uid' => $item['uid']]);
return;
}
- Item::update(['owner-id' => $item['author-id'], 'contact-id' => $cid], ['id' => $parent['id']]);
- Logger::info('Change owner of the parent', ['uri-id' => $item['uri-id'], 'parent-uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $cid]);
+ if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
+ if (!in_array($parent['post-type'], [self::PT_ARTICLE, self::PT_COMMENT]) || Contact::isSharing($parent['owner-id'], $item['uid'])) {
+ logger::info('The resharer is no forum: quit', ['resharer' => $item['author-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
+ return;
+ }
+ self::update(['post-type' => self::PT_ANNOUNCEMENT], ['id' => $parent['id']]);
+ Logger::info('Set announcement post-type', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
+ return;
+ }
+
+ self::update(['owner-id' => $item['author-id'], 'contact-id' => $cid], ['id' => $parent['id']]);
+ Logger::info('Change owner of the parent', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'owner-id' => $item['author-id'], 'contact-id' => $cid]);
}
/**
@@ -2229,6 +2242,8 @@ class Item
return 0;
}
+ $item['post-type'] = self::PT_STORED;
+
$item = array_merge($item, $fields);
$stored = self::storeForUser($item, $uid);
diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php
index d8ec1a80d..24ac13335 100644
--- a/src/Protocol/ActivityPub/Processor.php
+++ b/src/Protocol/ActivityPub/Processor.php
@@ -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;
}
diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 301266117..090d7dcfa 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -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']);
diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php
index 132996812..c5b34753e 100644
--- a/src/Protocol/DFRN.php
+++ b/src/Protocol/DFRN.php
@@ -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);
diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php
index c77e1610d..050a83937 100644
--- a/src/Protocol/Diaspora.php
+++ b/src/Protocol/Diaspora.php
@@ -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']]);
diff --git a/view/theme/frio/templates/sub/direction.tpl b/view/theme/frio/templates/sub/direction.tpl
index 2d625e187..787319433 100644
--- a/view/theme/frio/templates/sub/direction.tpl
+++ b/view/theme/frio/templates/sub/direction.tpl
@@ -15,6 +15,8 @@
{{elseif $direction.direction == 7}}
+ {{elseif $direction.direction == 8}}
+
{{/if}}
{{/if}}
diff --git a/view/theme/vier/templates/sub/direction.tpl b/view/theme/vier/templates/sub/direction.tpl
index 939623c1e..4ebe21677 100644
--- a/view/theme/vier/templates/sub/direction.tpl
+++ b/view/theme/vier/templates/sub/direction.tpl
@@ -15,6 +15,8 @@
{{elseif $direction.direction == 7}}
+ {{elseif $direction.direction == 8}}
+
{{/if}}
{{/if}}