]> git.mxchange.org Git - friendica.git/commitdiff
Improvements for the "post-reason"
authorMichael <heluecht@pirati.ca>
Fri, 29 Jul 2022 14:17:53 +0000 (14:17 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 29 Jul 2022 14:17:53 +0000 (14:17 +0000)
mod/item.php
src/Content/Conversation.php
src/Model/Item.php
src/Module/Api/Mastodon/Statuses/Bookmark.php
src/Module/Api/Mastodon/Statuses/Unbookmark.php
src/Module/Item/Star.php
src/Protocol/ActivityPub/Delivery.php
src/Protocol/ActivityPub/Transmitter.php
src/Worker/Notifier.php

index ce4cd45ca7e2e1124a3cc28669e787d13c1a3dd3..26dcef91cdf21db43ccb612974b0c6d0ff27b432 100644 (file)
@@ -138,7 +138,7 @@ function item_post(App $a) {
                // When commenting on a public post then store the post for the current user
                // This enables interaction like starring and saving into folders
                if ($toplevel_item['uid'] == 0) {
-                       $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user());
+                       $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user(), ['post-reason' => Item::PR_ACTIVITY]);
                        Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]);
                        if ($stored) {
                                $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]);
index 5bb47b23b14cfa4b808381a560bbfa3a974d3711..36fd38915d22098fde82b4ea223d6361436a94c2 100644 (file)
@@ -857,7 +857,7 @@ class Conversation
                                $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('You are following %s.', $row['author-name'])];
                                break;
                        case ItemModel::PR_TAG:
-                               $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('Tagged')];
+                               $row['direction'] = ['direction' => 4, 'title' => $this->l10n->t('You subscribed to one or more tags in this post.')];
                                break;
                        case ItemModel::PR_ANNOUNCEMENT:
                                if (!empty($row['causer-id']) && $this->pConfig->get(local_user(), 'system', 'display_resharer')) {
@@ -878,17 +878,30 @@ class Conversation
                                $row['direction'] = ['direction' => 5, 'title' => $this->l10n->t('%s is participating in this thread.', $row['author-name'])];
                                break;
                        case ItemModel::PR_STORED:
-                               $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored')];
+                               $row['direction'] = ['direction' => 8, 'title' => $this->l10n->t('Stored for general reasons')];
                                break;
                        case ItemModel::PR_GLOBAL:
-                               $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global')];
+                               $row['direction'] = ['direction' => 9, 'title' => $this->l10n->t('Global post')];
                                break;
                        case ItemModel::PR_RELAY:
-                               $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Relayed') : $this->l10n->t('Relayed by %s <%s>', $row['causer-name'], $row['causer-link']))];
+                               $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Send via an relay server') : $this->l10n->t('Send via the relay server %s <%s>', $row['causer-name'], $row['causer-link']))];
                                break;
                        case ItemModel::PR_FETCHED:
                                $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? $this->l10n->t('Fetched') : $this->l10n->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))];
                                break;
+                       case ItemModel::PR_COMPLETION:
+                               $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of a child post to complete this thread.')];
+                               break;
+                       case ItemModel::PR_DIRECT:
+                               $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Local delivery')];
+                               break;
+                       case ItemModel::PR_ACTIVITY:
+                               $row['direction'] = ['direction' => 2, 'title' => $this->l10n->t('Stored because of your activity (like, comment, star, ...)')];
+                               break;
+                       case ItemModel::PR_DISTRIBUTE:
+                               $row['direction'] = ['direction' => 6, 'title' => $this->l10n->t('Distributed')];
+                               break;
+
                }
 
                $row['thr-parent-row'] = $thr_parent;
index 55022519aa06fc1a9ce484c3945833d3268ba57a..a465e8c93c5f5fae8e6f5d13736e64d26aede265 100644 (file)
@@ -44,6 +44,7 @@ use Friendica\Util\Proxy;
 use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 use Friendica\Worker\Delivery;
+use GuzzleHttp\Psr7\Uri;
 use LanguageDetection\Language;
 
 class Item
@@ -74,6 +75,10 @@ class Item
        const PR_GLOBAL = 73;
        const PR_RELAY = 74;
        const PR_FETCHED = 75;
+       const PR_COMPLETION = 76;
+       const PR_DIRECT = 77;
+       const PR_ACTIVITY = 78;
+       const PR_DISTRIBUTE = 79;
 
        // system.accept_only_sharer setting values
        const COMPLETION_NONE    = 1;
@@ -688,9 +693,9 @@ class Item
                $parent = Post::selectFirst($fields, $condition, $params);
 
                if (!DBA::isResult($parent) && Post::exists(['uri-id' => [$item['thr-parent-id'], $item['parent-uri-id']], 'uid' => 0])) {
-                       $stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid']);
+                       $stored = Item::storeForUserByUriId($item['thr-parent-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]);
                        if (!$stored && ($item['thr-parent-id'] != $item['parent-uri-id'])) {
-                               $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid']);
+                               $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]);
                        }
                        if ($stored) {
                                Logger::info('Stored thread parent item for user', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid'], 'stored' => $stored]);
@@ -714,7 +719,7 @@ class Item
                $toplevel_parent = Post::selectFirst($fields, $condition, $params);
 
                if (!DBA::isResult($toplevel_parent) && $item['origin']) {
-                       $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid']);
+                       $stored = Item::storeForUserByUriId($item['parent-uri-id'], $item['uid'], ['post-reason' => Item::PR_COMPLETION]);
                        Logger::info('Stored parent item for user', ['uri-id' => $item['parent-uri-id'], 'uid' => $item['uid'], 'stored' => $stored]);
                        $toplevel_parent = Post::selectFirst($fields, $condition, $params);
                }
@@ -1355,14 +1360,8 @@ class Item
 
                $uids = Tag::getUIDListByURIId($item['uri-id']);
                foreach ($uids as $uid) {
-                       if (Contact::isSharing($item['author-id'], $uid)) {
-                               $fields = [];
-                       } else {
-                               $fields = ['post-reason' => self::PR_TAG];
-                       }
-
-                       $stored = self::storeForUserByUriId($item['uri-id'], $uid, $fields);
-                       Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'fields' => $fields, 'stored' => $stored]);
+                       $stored = self::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => self::PR_TAG]);
+                       Logger::info('Stored item for users', ['uri-id' => $item['uri-id'], 'uid' => $uid, 'stored' => $stored]);
                }
        }
 
@@ -1454,6 +1453,7 @@ class Item
                        if ($origin_uid == $uid) {
                                $item['diaspora_signed_text'] = $signed_text;
                        }
+                       $item['post-reason'] = self::PR_DISTRIBUTE;
                        self::storeForUser($item, $uid);
                }
        }
@@ -1605,7 +1605,6 @@ class Item
                unset($item['event-id']);
                unset($item['hidden']);
                unset($item['notification-type']);
-               unset($item['post-reason']);
 
                // Data from the "post-delivery-data" table
                unset($item['postopts']);
@@ -2488,7 +2487,7 @@ class Item
                }
 
                if (!Post::exists(['uri-id' => $item['parent-uri-id'], 'uid' => $uid])) {
-                       $stored = self::storeForUserByUriId($item['parent-uri-id'], $uid);
+                       $stored = self::storeForUserByUriId($item['parent-uri-id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
                        if (($item['parent-uri-id'] == $item['uri-id']) && !empty($stored)) {
                                $item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $stored]);
                                if (!DBA::isResult($item)) {
@@ -2948,7 +2947,7 @@ class Item
                $urlparts = parse_url($url);
                unset($urlparts['query']);
                unset($urlparts['fragment']);
-               $url = Network::unparseURL($urlparts);
+               $url = Uri::fromParts($urlparts);
 
                // Remove media links to only search in embedded content
                // @todo Check images for image link, audio for audio links, ...
index 95a072889c3c9969f0fc77dcaf134408cdcdccfc..cebb061927e6d550450b12faa7d86126636e324d 100644 (file)
@@ -52,7 +52,7 @@ class Bookmark extends BaseApi
                }
 
                if ($item['uid'] == 0) {
-                       $stored = Item::storeForUserByUriId($this->parameters['id'], $uid);
+                       $stored = Item::storeForUserByUriId($this->parameters['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
                        if (!empty($stored)) {
                                $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
                                if (!DBA::isResult($item)) {
index 103fac04afaa4891569b81cc71fb8a0a7acfc44e..f90916176d7b24bcc46bde000b17b0a967175a66 100644 (file)
@@ -52,7 +52,7 @@ class Unbookmark extends BaseApi
                }
 
                if ($item['uid'] == 0) {
-                       $stored = Item::storeForUserByUriId($this->parameters['id'], $uid);
+                       $stored = Item::storeForUserByUriId($this->parameters['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]);
                        if (!empty($stored)) {
                                $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]);
                                if (!DBA::isResult($item)) {
index 8f444d54edfdf79c95eb99964622cf6f539226c5..660095103d40103b677964e8cedc47c08b1bb660 100644 (file)
@@ -56,7 +56,7 @@ class Star extends BaseModule
                }
 
                if ($item['uid'] == 0) {
-                       $stored = Item::storeForUserByUriId($item['uri-id'], local_user());
+                       $stored = Item::storeForUserByUriId($item['uri-id'], local_user(), ['post-reason' => Item::PR_ACTIVITY]);
                        if (!empty($stored)) {
                                $item = Post::selectFirst(['starred'], ['id' => $stored]);
                                if (!DBA::isResult($item)) {
index fac8536d67f6906258dd7ce68ec26c900c04fd7b..6e97b0b92731bcb237636fc596dd8fb3cf837de5 100644 (file)
@@ -110,10 +110,7 @@ class Delivery
                } elseif ($cmd == WorkerDelivery::PROFILEUPDATE) {
                        $success = ActivityPub\Transmitter::sendProfileUpdate($uid, $inbox);
                } else {
-                       $data = Post\Activity::getByURIId($uri_id);
-                       if (empty($data)) {
-                               $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
-                       }
+                       $data = ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
                        if (!empty($data)) {
                                $timestamp  = microtime(true);
                                $response   = HTTPSignature::post($data, $inbox, $uid);
index ddf495794650162a7f33f3552c5adb1c86f61866..ecd18431855713b3bc940d3db9179a0d5c13ee56 100644 (file)
@@ -1233,26 +1233,20 @@ class Transmitter
                if (!$item['deleted']) {
                        $data = Post\Activity::getByURIId($item['uri-id']);
                        if (!$item['origin'] && !empty($data)) {
-                               if (!empty($data['type'])) {
-                                       if (in_array($data['type'], ['Create', 'Update'])) {
-                                               if ($object_mode) {
-                                                       unset($data['@context']);
-                                                       unset($data['signature']);
-                                               }
-                                               Logger::info('Return stored conversation', ['item' => $item_id]);
-                                               return $data;
-                                       } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) {
-                                               if (!empty($data['@context'])) {
-                                                       $context = $data['@context'];
-                                                       unset($data['@context']);
-                                               }
-                                               unset($data['actor']);
-                                               $object = $data;
-                                       }
+                               if ($object_mode) {
+                                       unset($data['@context']);
+                                       unset($data['signature']);
                                }
+                               Logger::info('Return stored conversation', ['item' => $item_id]);
+                               return $data;
                        }
                }
 
+               if (!$item['origin'] && empty($object)) {
+                       Logger::debug('Post is not ours and is not stored', ['id' => $item_id, 'uri-id' => $item['uri-id']]);
+                       return false;
+               }
+
                $type = self::getTypeOfItem($item);
 
                if (!$object_mode) {
index 8655d2662ed50ba2980a2c298f0480da31e2bb58..36d1a76b73de6ed8bc9adcbd4553cfa9ff65447d 100644 (file)
@@ -506,7 +506,7 @@ class Notifier
                        // Direct delivery of local contacts
                        if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::DELETION, Delivery::MAIL]) && $target_uid = User::getIdForURL($contact['url'])) {
                                Logger::info('Direct delivery', ['uri-id' => $target_item['uri-id'], 'target' => $target_uid]);
-                               $fields = ['protocol' => Conversation::PARCEL_LOCAL_DFRN, 'direction' => Conversation::PUSH];
+                               $fields = ['protocol' => Conversation::PARCEL_LOCAL_DFRN, 'direction' => Conversation::PUSH, 'post-reason' => Item::PR_DIRECT];
                                Item::storeForUserByUriId($target_item['uri-id'], $target_uid, $fields, $target_item['uid']);
                                continue;
                        }