]> git.mxchange.org Git - friendica.git/commitdiff
Add additional direction types
authorMichael <heluecht@pirati.ca>
Sun, 13 Sep 2020 14:15:28 +0000 (14:15 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 13 Sep 2020 14:15:28 +0000 (14:15 +0000)
include/conversation.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
view/theme/frio/templates/sub/direction.tpl
view/theme/vier/templates/sub/direction.tpl

index 8fd9725aae8467434e58441b5d1098ef2af9a65f..a995ea4ad17ee322c022c470556f6300204674b9 100644 (file)
@@ -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) {
index 8c5a851eb97bd1ec53e436d4db63a603c1b3c0d5..4cc68c6492d07c645322abef74fd0e85df6d8928 100644 (file)
@@ -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);
index d8ec1a80d82d406f3905e2824846675eff3138af..24ac133358ac539c4874f7c35834087c963d5a6e 100644 (file)
@@ -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;
                        }
index 30126611744ed3213756cf8f47243ae1c096a8d6..090d7dcfa0ace8b9ae677faebbc7c406f6a06177 100644 (file)
@@ -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;
+                       }
+               }
+
+               // Fetch all posts that refer to the object id
+               $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
+               if (!empty($object_id)) {
+                       $reply[] = $object_id;
+               }
 
-                       $parents = Item::select(['uid'], ['uri' => $replyto]);
+               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']);
index 1329968126e43d6be6ba90502e16b5e9d28005ff..c5b34753eba00b8cbf1aa94bcb3869dc2500120d 100644 (file)
@@ -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);
index c77e1610d007c325de571edd1b7c771840e414a3..050a83937359ac20bcefb0f263fe2b50e7f8c702 100644 (file)
@@ -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']]);
index 2d625e18764a27a5807a8683ffd5694bc556d101..78731943329b21ebd4d26b54290f7973e5cc6525 100644 (file)
@@ -15,6 +15,8 @@
                <i class="fa fa-user" aria-hidden="true" title="{{$direction.title}}"></i>
        {{elseif $direction.direction == 7}}
                <i class="fa fa-at" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 8}}
+               <i class="fa fa-share" aria-hidden="true" title="{{$direction.title}}"></i>
        {{/if}}
 </span>
 {{/if}}
index 939623c1e213ba116d72b40f4893e6f172095631..4ebe21677278b36dbe8b27b936b627f57b1aa780 100644 (file)
@@ -15,6 +15,8 @@
                <i class="icon-ok-sign" aria-hidden="true" title="{{$direction.title}}"></i>
        {{elseif $direction.direction == 7}}
                <i class="icon-forward" aria-hidden="true" title="{{$direction.title}}"></i>
+       {{elseif $direction.direction == 8}}
+               <i class="icon-share" aria-hidden="true" title="{{$direction.title}}"></i>
        {{/if}}
 </span>
 {{/if}}