]> git.mxchange.org Git - friendica.git/commitdiff
"post-reason" ends double usage of "post-type"
authorMichael <heluecht@pirati.ca>
Wed, 7 Apr 2021 06:02:06 +0000 (06:02 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 7 Apr 2021 06:02:06 +0000 (06:02 +0000)
13 files changed:
database.sql
include/conversation.php
src/Model/Event.php
src/Model/Item.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php
src/Protocol/Feed.php
src/Worker/ExpirePosts.php
static/dbstructure.config.php
static/dbview.config.php
update.php

index 1c835587b1bfd5190301656b0d44b99d503ded02..1727911c93af61262e2ccf050691e406d72f4cb3 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2021.03-rc (Red Hot Poker)
--- DB_UPDATE_VERSION 1412
+-- DB_UPDATE_VERSION 1413
 -- ------------------------------------------
 
 
@@ -934,7 +934,7 @@ CREATE TABLE IF NOT EXISTS `post` (
        `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
        `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
        `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
-       `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
+       `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
        `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
        `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
        `global` boolean NOT NULL DEFAULT '0' COMMENT '',
@@ -1100,7 +1100,8 @@ CREATE TABLE IF NOT EXISTS `post-user` (
        `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
        `author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
        `causer-id` int unsigned COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
-       `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
+       `post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, image, article, ...)',
+       `post-reason` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Reason why the post arrived at the user',
        `vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
        `private` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '0=public, 1=private, 2=unlisted',
        `global` boolean NOT NULL DEFAULT '0' COMMENT '',
@@ -1488,6 +1489,7 @@ CREATE VIEW `post-user-view` AS SELECT
        `post-user`.`received` AS `received`,
        `post-thread-user`.`changed` AS `changed`,
        `post-user`.`post-type` AS `post-type`,
+       `post-user`.`post-reason` AS `post-reason`,
        `post-user`.`private` AS `private`,
        `post-thread-user`.`pubmail` AS `pubmail`,
        `post-user`.`visible` AS `visible`,
@@ -1647,6 +1649,7 @@ CREATE VIEW `post-thread-user-view` AS SELECT
        `post-thread-user`.`received` AS `received`,
        `post-thread-user`.`changed` AS `changed`,
        `post-user`.`post-type` AS `post-type`,
+       `post-user`.`post-reason` AS `post-reason`,
        `post-user`.`private` AS `private`,
        `post-thread-user`.`pubmail` AS `pubmail`,
        `post-thread-user`.`ignored` AS `ignored`,
index f3384f9177907b7095430806b2aa5d536809bdb2..ff8ecbad0054f59e18a6440a65ae2b0cafe9ee7d 100644 (file)
@@ -725,7 +725,7 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
        while ($row = Post::fetch($thread_items)) {
                if (!empty($activity)) {
                        if (($row['gravity'] == GRAVITY_PARENT)) {
-                               $row['post-type'] = Item::PT_ANNOUNCEMENT;
+                               $row['post-reason'] = Item::PR_ANNOUNCEMENT;
                                $row = array_merge($row, $activity);
                                $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
                                $row['causer-link'] = $contact['url'];
@@ -739,26 +739,26 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
 
                $name = $row['causer-contact-type'] == Contact::TYPE_RELAY ? $row['causer-link'] : $row['causer-name'];
 
-               switch ($row['post-type']) {
-                       case Item::PT_TO:
+               switch ($row['post-reason']) {
+                       case Item::PR_TO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
                                break;
-                       case Item::PT_CC:
+                       case Item::PR_CC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
                                break;
-                       case Item::PT_BTO:
+                       case Item::PR_BTO:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
                                break;
-                       case Item::PT_BCC:
+                       case Item::PR_BCC:
                                $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
                                break;
-                       case Item::PT_FOLLOWER:
+                       case Item::PR_FOLLOWER:
                                $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
                                break;
-                       case Item::PT_TAG:
+                       case Item::PR_TAG:
                                $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
                                break;
-                       case Item::PT_ANNOUNCEMENT:
+                       case Item::PR_ANNOUNCEMENT:
                                if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) {
                                        $row['owner-id'] = $row['causer-id'];
                                        $row['owner-link'] = $row['causer-link'];
@@ -773,19 +773,19 @@ function conversation_fetch_comments($thread_items, bool $pinned, array $activit
                                }
                                $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s', $name))];
                                break;
-                       case Item::PT_COMMENT:
+                       case Item::PR_COMMENT:
                                $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
                                break;
-                       case Item::PT_STORED:
+                       case Item::PR_STORED:
                                $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
                                break;
-                       case Item::PT_GLOBAL:
+                       case Item::PR_GLOBAL:
                                $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
                                break;
-                       case Item::PT_RELAY:
+                       case Item::PR_RELAY:
                                $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Relayed') : DI::l10n()->t('Relayed by %s.', $name))];
                                break;
-                       case Item::PT_FETCHED:
+                       case Item::PR_FETCHED:
                                $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Fetched') : DI::l10n()->t('Fetched because of %s', $name))];
                                break;
                        }
@@ -878,7 +878,7 @@ function conversation_fetch_items(array $parent, array $items, array $condition,
                $condition[0] .= " AND NOT `author-hidden`";
        }
 
-       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params);
+       $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-reason']), $condition, $params);
 
        $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity);
 
index 69fcd5e90ab04852e689470daffca38cd05bff1f..d2bc6ab86a7e6760ac14202c1be6a9111ebd1564 100644 (file)
@@ -381,6 +381,7 @@ class Event
                                $item_arr['visible']       = 1;
                                $item_arr['verb']          = Activity::POST;
                                $item_arr['object-type']   = Activity\ObjectType::EVENT;
+                               $item_arr['post-type']     = Item::PT_EVENT;
                                $item_arr['origin']        = $event['cid'] === 0 ? 1 : 0;
                                $item_arr['body']          = self::getBBCode($event);
                                $item_arr['event-id']      = $event['id'];
index 76402280c2073583950b32cf87cb36a75f3dff54..1d50dba2e7cc4a8bc4f152e102242e32ff70c8fc 100644 (file)
@@ -55,20 +55,23 @@ class Item
        const PT_VIDEO = 18;
        const PT_DOCUMENT = 19;
        const PT_EVENT = 32;
-       const PT_TAG = 64;
-       const PT_TO = 65;
-       const PT_CC = 66;
-       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_GLOBAL = 73;
-       const PT_RELAY = 74;
-       const PT_FETCHED = 75;
        const PT_PERSONAL_NOTE = 128;
 
+       // Posting reasons (Why had a post been stored for a user?)
+       const PR_NONE = 0;
+       const PR_TAG = 64;
+       const PR_TO = 65;
+       const PR_CC = 66;
+       const PR_BTO = 67;
+       const PR_BCC = 68;
+       const PR_FOLLOWER = 69;
+       const PR_ANNOUNCEMENT = 70;
+       const PR_COMMENT = 71;
+       const PR_STORED = 72;
+       const PR_GLOBAL = 73;
+       const PR_RELAY = 74;
+       const PR_FETCHED = 75;
+
        // Field list that is used to display the items
        const DISPLAY_FIELDLIST = [
                'uid', 'id', 'parent', 'guid', 'network', 'gravity',
@@ -92,7 +95,7 @@ class Item
        const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
                        'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
                        'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
-                       'inform', 'deleted', 'extid', 'post-type', 'gravity',
+                       'inform', 'deleted', 'extid', 'post-type', 'post-reason', 'gravity',
                        'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
                        'author-id', 'author-link', 'author-name', 'author-avatar', 'owner-id', 'owner-link', 'contact-uid',
                        'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
@@ -107,7 +110,7 @@ class Item
                        'contact-id', 'wall', 'gravity', 'extid', 'psid',
                        'created', 'edited', 'commented', 'received', 'changed', 'verb',
                        'postopts', 'plink', 'resource-id', 'event-id', 'inform',
-                       'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
+                       'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type', 'post-reason',
                        'private', 'pubmail', 'visible', 'starred',
                        'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
                        'title', 'content-warning', 'body', 'location', 'coord', 'app',
@@ -744,6 +747,10 @@ class Item
                        return 0;
                }
 
+               if (!isset($item['post-type'])) {
+                       $item['post-type'] = empty($item['title']) ? self::PT_NOTE : self::PT_ARTICLE;
+               }
+
                $item['wall']          = intval($item['wall'] ?? 0);
                $item['extid']         = trim($item['extid'] ?? '');
                $item['author-name']   = trim($item['author-name'] ?? '');
@@ -762,7 +769,6 @@ class Item
                $item['coord']         = trim($item['coord'] ?? '');
                $item['visible']       = (isset($item['visible']) ? intval($item['visible']) : 1);
                $item['deleted']       = 0;
-               $item['post-type']     = ($item['post-type'] ?? '') ?: self::PT_ARTICLE;
                $item['verb']          = trim($item['verb'] ?? '');
                $item['object-type']   = trim($item['object-type'] ?? '');
                $item['object']        = trim($item['object'] ?? '');
@@ -810,7 +816,7 @@ class Item
 
                $actor = ($item['gravity'] == GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
                if (!$item['origin'] && ($item['uid'] != 0) && Contact::isSharing($actor, $item['uid'])) {
-                       $item['post-type'] = self::PT_FOLLOWER;
+                       $item['post-reason'] = self::PR_FOLLOWER;
                }
 
                // Ensure that there is an avatar cache
@@ -1115,7 +1121,7 @@ class Item
         */
        private static function setOwnerforResharedItem(array $item)
        {
-               $parent = Post::selectFirst(['id', 'causer-id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-type'],
+               $parent = Post::selectFirst(['id', 'causer-id', 'owner-id', 'author-id', 'author-link', 'origin', 'post-reason'],
                        ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
                if (!DBA::isResult($parent)) {
                        Logger::error('Parent not found', ['uri-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
@@ -1135,7 +1141,7 @@ class Item
                }
 
                if ($author['contact-type'] != Contact::TYPE_COMMUNITY) {
-                       if ($parent['post-type'] == self::PT_ANNOUNCEMENT) {
+                       if ($parent['post-reason'] == self::PR_ANNOUNCEMENT) {
                                Logger::info('The parent is already marked as announced: quit', ['causer' => $parent['causer-id'], 'owner' => $parent['owner-id'], 'author' => $parent['author-id'], 'uid' => $item['uid']]);
                                return;
                        }
@@ -1144,8 +1150,8 @@ class Item
                                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, 'causer-id' => $item['author-id']], ['id' => $parent['id']]);
-                       Logger::info('Set announcement post-type', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
+                       self::update(['post-reason' => self::PR_ANNOUNCEMENT, 'causer-id' => $item['author-id']], ['id' => $parent['id']]);
+                       Logger::info('Set announcement post-reason', ['uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
                        return;
                }
 
@@ -1169,7 +1175,7 @@ class Item
                        if (Contact::isSharing($item['author-id'], $uid)) {
                                $fields = [];
                        } else {
-                               $fields = ['post-type' => self::PT_TAG];
+                               $fields = ['post-reason' => self::PR_TAG];
                        }
 
                        $stored = self::storeForUserByUriId($item['uri-id'], $uid, $fields);
@@ -1289,7 +1295,7 @@ class Item
                        return 0;
                }
 
-               $item['post-type'] = self::PT_STORED;
+               $item['post-reason'] = self::PR_STORED;
 
                $item = array_merge($item, $fields);
 
@@ -1416,7 +1422,7 @@ class Item
                        unset($item['starred']);
                        unset($item['postopts']);
                        unset($item['inform']);
-                       unset($item['post-type']);
+                       unset($item['post-reason']);
                        if ($item['uri-id'] == $item['parent-uri-id']) {
                                $item['contact-id'] = $item['owner-id'];
                        } else {
@@ -1479,7 +1485,7 @@ class Item
                unset($item['starred']);
                unset($item['postopts']);
                unset($item['inform']);
-               unset($item['post-type']);
+               unset($item['post-reason']);
                $item['contact-id'] = Contact::getIdForURL($item['author-link']);
 
                $public_shadow = self::insert($item, false, true);
@@ -2157,7 +2163,7 @@ class Item
 
                        // Only expire posts, not photos and photo comments
 
-                       if (!$expire_photos && (!empty($item['resource-id']) || ($item['post-type'] == self::PT_IMAGE))) {
+                       if (!$expire_photos && !empty($item['resource-id'])) {
                                continue;
                        } elseif (!$expire_starred && intval($item['starred'])) {
                                continue;
@@ -2696,21 +2702,31 @@ class Item
 
                        if (($filetype == 'video')) {
                                /// @todo Move the template to /content as well
-                               $leading .= Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
+                               $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('video_top.tpl'), [
                                        '$video' => [
                                                'id'     => $item['author-id'],
                                                'src'    => $the_url,
                                                'mime'   => $mime,
                                        ],
                                ]);
+                               if ($item['post-type'] == Item::PT_VIDEO) {
+                                       $leading .= $media;
+                               } else {
+                                       $trailing .= $media;
+                               }
                        } elseif ($filetype == 'audio') {
-                               $leading .= Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
+                               $media = Renderer::replaceMacros(Renderer::getMarkupTemplate('content/audio.tpl'), [
                                        '$audio' => [
                                                'id'     => $item['author-id'],
                                                'src'    => $the_url,
                                                'mime'   => $mime,
                                        ],
                                ]);
+                               if ($item['post-type'] == Item::PT_AUDIO) {
+                                       $leading .= $media;
+                               } else {
+                                       $trailing .= $media;
+                               }
                        } else {
                                $title = Strings::escapeHtml(trim(($attachment['description'] ?? '') ?: $attachment['url']));
 
index 171cf0ea4059981c2c74f242ffa59c547dd0adfe..c30a4ccc9963220af28b3b4f21f1af7d032f9327 100644 (file)
@@ -198,31 +198,47 @@ class Processor
 
                                                // image is the preview/thumbnail URL
                                                if (!empty($attach['image'])) {
-                                                       $trailing .= '[url=' . $attach['url'] . ']';
+                                                       $media = '[url=' . $attach['url'] . ']';
                                                        $attach['url'] = $attach['image'];
+                                               } else {
+                                                       $media = '';
                                                }
 
                                                if (empty($attach['name'])) {
-                                                       $trailing .= '[img]' . $attach['url'] . '[/img]';
+                                                       $media .= '[img]' . $attach['url'] . '[/img]';
                                                } else {
-                                                       $trailing .= '[img=' . $attach['url'] . ']' . $attach['name'] . '[/img]';
+                                                       $media .= '[img=' . $attach['url'] . ']' . $attach['name'] . '[/img]';
                                                }
 
                                                if (!empty($attach['image'])) {
-                                                       $trailing .= '[/url]';
+                                                       $media .= '[/url]';
                                                }
+
+                                               if ($item['post-type'] == Item::PT_IMAGE) {
+                                                       $leading .= $media;
+                                               } else {
+                                                       $trailing .= $media;
+                                               }               
                                        } elseif ($filetype == 'audio') {
                                                if (!empty($activity['source']) && strpos($activity['source'], $attach['url'])) {
                                                        continue 2;
                                                }
 
-                                               $leading .= '[audio]' . $attach['url'] . "[/audio]\n";
+                                               if ($item['post-type'] == Item::PT_AUDIO) {
+                                                       $leading .= '[audio]' . $attach['url'] . "[/audio]\n";
+                                               } else {
+                                                       $trailing .= '[audio]' . $attach['url'] . "[/audio]\n";
+                                               }
                                        } elseif ($filetype == 'video') {
                                                if (!empty($activity['source']) && strpos($activity['source'], $attach['url'])) {
                                                        continue 2;
                                                }
 
-                                               $leading .= '[video]' . $attach['url'] . "[/video]\n";
+                                               if ($item['post-type'] == Item::PT_VIDEO) {
+                                                       $leading .= '[video]' . $attach['url'] . "[/video]\n";
+                                               } else {
+                                                       $trailing .= '[video]' . $attach['url'] . "[/video]\n";
+                                               }
                                        }
                        }
                }
@@ -250,7 +266,7 @@ class Processor
         */
        public static function updateItem($activity)
        {
-               $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity'], ['uri' => $activity['id']]);
+               $item = Post::selectFirst(['uri', 'uri-id', 'thr-parent', 'gravity', 'post-type'], ['uri' => $activity['id']]);
                if (!DBA::isResult($item)) {
                        Logger::warning('No existing item, item will be created', ['uri' => $activity['id']]);
                        $item = self::createItem($activity);
@@ -336,6 +352,24 @@ class Processor
                        $item['direction'] = Conversation::RELAY;
                }
 
+               if ($activity['object_type'] == 'as:Article') {
+                       $item['post-type'] = Item::PT_ARTICLE;
+               } elseif ($activity['object_type'] == 'as:Audio') {
+                       $item['post-type'] = Item::PT_AUDIO;
+               } elseif ($activity['object_type'] == 'as:Document') {
+                       $item['post-type'] = Item::PT_DOCUMENT;
+               } elseif ($activity['object_type'] == 'as:Event') {
+                       $item['post-type'] = Item::PT_EVENT;
+               } elseif ($activity['object_type'] == 'as:Image') {
+                       $item['post-type'] = Item::PT_IMAGE;
+               } elseif ($activity['object_type'] == 'as:Page') {
+                       $item['post-type'] = Item::PT_PAGE;
+               } elseif ($activity['object_type'] == 'as:Video') {
+                       $item['post-type'] = Item::PT_VIDEO;
+               } else {
+                       $item['post-type'] = Item::PT_NOTE;
+               }
+
                $item['isForum'] = false;
 
                if (!empty($activity['thread-completion'])) {
@@ -456,6 +490,7 @@ class Processor
                $item['verb'] = $verb;
                $item['thr-parent'] = $activity['object_id'];
                $item['gravity'] = GRAVITY_ACTIVITY;
+               unset($item['post-type']);
                $item['object-type'] = Activity\ObjectType::NOTE;
 
                $item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
@@ -629,34 +664,34 @@ class Processor
                        $type = $activity['reception_type'][$receiver] ?? Receiver::TARGET_UNKNOWN;
                        switch($type) {
                                case Receiver::TARGET_TO:
-                                       $item['post-type'] = Item::PT_TO;
+                                       $item['post-reason'] = Item::PR_TO;
                                        break;
                                case Receiver::TARGET_CC:
-                                       $item['post-type'] = Item::PT_CC;
+                                       $item['post-reason'] = Item::PR_CC;
                                        break;
                                case Receiver::TARGET_BTO:
-                                       $item['post-type'] = Item::PT_BTO;
+                                       $item['post-reason'] = Item::PR_BTO;
                                        break;
                                case Receiver::TARGET_BCC:
-                                       $item['post-type'] = Item::PT_BCC;
+                                       $item['post-reason'] = Item::PR_BCC;
                                        break;
                                case Receiver::TARGET_FOLLOWER:
-                                       $item['post-type'] = Item::PT_FOLLOWER;
+                                       $item['post-reason'] = Item::PR_FOLLOWER;
                                        break;
                                case Receiver::TARGET_ANSWER:
-                                       $item['post-type'] = Item::PT_COMMENT;
+                                       $item['post-reason'] = Item::PR_COMMENT;
                                        break;
                                case Receiver::TARGET_GLOBAL:
-                                       $item['post-type'] = Item::PT_GLOBAL;
+                                       $item['post-reason'] = Item::PR_GLOBAL;
                                        break;
                                default:
-                                       $item['post-type'] = Item::PT_ARTICLE;
+                                       $item['post-reason'] = Item::PR_NONE;
                        }
 
                        if (!empty($activity['from-relay'])) {
-                               $item['post-type'] = Item::PT_RELAY;
+                               $item['post-reason'] = Item::PR_RELAY;
                        } elseif (!empty($activity['thread-completion'])) {
-                               $item['post-type'] = Item::PT_FETCHED;
+                               $item['post-reason'] = Item::PR_FETCHED;
                        }
 
                        if ($item['isForum'] ?? false) {
index 91d0915ca99cd22f0fcaa0d721c943ee0c42ec3a..a8c997c60c81ce74227b8062dfb94d5bc7212351 100644 (file)
@@ -522,7 +522,7 @@ class Receiver
                                                return;
                                        }
 
-                                       $item['post-type'] = Item::PT_ANNOUNCEMENT;
+                                       $item['post-reason'] = Item::PR_ANNOUNCEMENT;
                                        ActivityPub\Processor::postItem($object_data, $item);
 
                                        $announce_object_data = self::processObject($activity);
index 759ba674b1fd2e768f74d8392420216fa98752e6..5eee17e52db40debd1a6482fe7907803dd7d8f65 100644 (file)
@@ -2195,6 +2195,12 @@ class DFRN
 
                $item["title"] = XML::getFirstNodeValue($xpath, "atom:title/text()", $entry);
 
+               if (!empty($item["title"])) {
+                       $item["post-type"] = Item::PT_ARTICLE;
+               } else {
+                       $item["post-type"] = Item::PT_NOTE;
+               }
+
                $item["created"] = XML::getFirstNodeValue($xpath, "atom:published/text()", $entry);
 
                $item["body"] = XML::getFirstNodeValue($xpath, "dfrn:env/text()", $entry);
@@ -2426,8 +2432,8 @@ 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;
+                       if (empty($item['post-reason']) && ($entrytype == DFRN::REPLY)) {
+                               $item['post-reason'] = Item::PR_COMMENT;
                        }
 
                        $posted_id = Item::insert($item);
@@ -2588,7 +2594,7 @@ class DFRN
                $header["direction"] = $direction;
 
                if ($direction === Conversation::RELAY) {
-                       $header['post-type'] = Item::PT_RELAY;
+                       $header['post-reason'] = Item::PR_RELAY;
                }
 
                // Update the contact table if the data has changed
index 5c33e7e2b0067b2b0a61ea6938bdb6f033643fc8..4b00ead002c1d4309bbb2226e658e0e1f14d3103 100644 (file)
@@ -1536,11 +1536,11 @@ class Diaspora
 
                // Will be overwritten for sharing accounts in Item::insert
                if ($fetched) {
-                       $datarray["post-type"] = Item::PT_FETCHED;
+                       $datarray["post-reason"] = Item::PR_FETCHED;
                } elseif ($datarray["uid"] == 0) {
-                       $datarray["post-type"] = Item::PT_GLOBAL;
+                       $datarray["post-reason"] = Item::PR_GLOBAL;
                } else {
-                       $datarray["post-type"] = Item::PT_COMMENT;
+                       $datarray["post-reason"] = Item::PR_COMMENT;
                }
 
                $datarray["guid"] = $guid;
@@ -1553,6 +1553,7 @@ class Diaspora
                $datarray['thr-parent'] = $thr_parent ?: $toplevel_parent_item['uri'];
 
                $datarray["object-type"] = Activity\ObjectType::COMMENT;
+               $datarray["post-type"] = Item::PT_NOTE;
 
                $datarray["protocol"] = Conversation::PARCEL_DIASPORA;
                $datarray["source"] = $xml;
@@ -2737,8 +2738,10 @@ class Diaspora
                        }
 
                        $datarray["object-type"] = Activity\ObjectType::IMAGE;
+                       $datarray["post-type"] = Item::PT_IMAGE;
                } else {
                        $datarray["object-type"] = Activity\ObjectType::NOTE;
+                       $datarray["post-type"] = Item::PT_NOTE;
 
                        // Add OEmbed and other information to the body
                        if (!self::isHubzilla($contact["url"])) {
@@ -2773,9 +2776,9 @@ class Diaspora
                $datarray["direction"] = $fetched ? Conversation::PULL : Conversation::PUSH;
 
                if ($fetched) {
-                       $datarray["post-type"] = Item::PT_FETCHED;
+                       $datarray["post-reason"] = Item::PR_FETCHED;
                } elseif ($datarray["uid"] == 0) {
-                       $datarray["post-type"] = Item::PT_GLOBAL;
+                       $datarray["post-reason"] = Item::PR_GLOBAL;
                }
 
                $datarray["body"] = self::replacePeopleGuid($body, $contact["url"]);
index a86d9f98f59bf78fd0531b1f5c457cae9e28077c..65af597f169962526514a596cf5e5a60c2bb64fb 100644 (file)
@@ -235,6 +235,7 @@ class Feed
                $header["private"] = Item::PUBLIC;
                $header["verb"] = Activity::POST;
                $header["object-type"] = Activity\ObjectType::NOTE;
+               $header["post-type"] = Item::PT_ARTICLE;
 
                $header["contact-id"] = $contact["id"] ?? 0;
 
@@ -539,6 +540,10 @@ class Feed
                                }
                        }
 
+                       if (empty($item['title'])) {
+                               $item['post-type'] = Item::PT_NOTE;
+                       }
+
                        Logger::info('Stored feed', ['item' => $item]);
 
                        $notify = Item::isRemoteSelf($contact, $item);
index cff6e2b120c505bd32ae4fce4c73a9d3f67849d2..2c3f6f68a16d30e2a13dc203975f0f511cdb7fbe 100644 (file)
@@ -224,10 +224,10 @@ class ExpirePosts
                                        AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user` INNER JOIN `contact` ON `contact`.`id` = `contact-id` AND `notify_new_posts`
                                                WHERE `parent-uri-id` = `post-thread`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `parent-uri-id` FROM `post-user`
-                                               WHERE (`origin` OR `event-id` != 0 OR `post-type` IN (?, ?)) AND `parent-uri-id` = `post-thread`.`uri-id`)
+                                               WHERE (`origin` OR `event-id` != 0 OR `post-type` = ?) AND `parent-uri-id` = `post-thread`.`uri-id`)
                                        AND NOT `uri-id` IN (SELECT `uri-id` FROM `post-content`
                                                WHERE `resource-id` != 0 AND `uri-id` = `post-thread`.`uri-id`))",
-                               $expire_days, Item::PT_PERSONAL_NOTE, Item::PT_IMAGE]);
+                               $expire_days, Item::PT_PERSONAL_NOTE]);
 
                        Logger::notice('Start deleting expired threads');
                        $affected_count = 0;
index ce3dedf5a05528e62406dc0f47303cf34dcf6f3a..8ec833ca64100c75fb41c188534360e8fd435f77 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1412);
+       define('DB_UPDATE_VERSION', 1413);
 }
 
 return [
@@ -998,7 +998,7 @@ return [
                        "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
                        "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
                        "causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
-                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, image, article, ...)"],
                        "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
                        "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
                        "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
@@ -1150,7 +1150,8 @@ return [
                        "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the owner of this item"],
                        "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the author of this item"],
                        "causer-id" => ["type" => "int unsigned", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"],
-                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
+                       "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, image, article, ...)"],
+                       "post-reason" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Reason why the post arrived at the user"],
                        "vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
                        "private" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "0=public, 1=private, 2=unlisted"],
                        "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
index 7f7dec2185c3e678f643acad255d247791846b67..94b81411b4f8707e4746674bf76e229879cec40f 100644 (file)
@@ -60,6 +60,7 @@
                        "received" => ["post-user", "received"],
                        "changed" => ["post-thread-user", "changed"],
                        "post-type" => ["post-user", "post-type"],
+                       "post-reason" => ["post-user", "post-reason"],
                        "private" => ["post-user", "private"],
                        "pubmail" => ["post-thread-user", "pubmail"],
                        "visible" => ["post-user", "visible"],
                        "received" => ["post-thread-user", "received"],
                        "changed" => ["post-thread-user", "changed"],
                        "post-type" => ["post-user", "post-type"],
+                       "post-reason" => ["post-user", "post-reason"],
                        "private" => ["post-user", "private"],
                        "pubmail" => ["post-thread-user", "pubmail"],
                        "ignored" => ["post-thread-user", "ignored"],
index 2b5335869e15e81ea9da878aa1c0bca2684bb9e4..819085f7ff2f5c6f1342d4f36c3a9e851997b039 100644 (file)
@@ -883,6 +883,8 @@ function update_1404()
                                continue 2;
                }
                DBA::update('workerqueue', ['parameter' => json_encode($parameters)], ['id' => $task['id']]);
+
+               return Update::SUCCESS;
        }
 }
 
@@ -900,4 +902,13 @@ function update_1407()
        if (!DBA::e("UPDATE `post-thread-user` SET `causer-id` = NULL WHERE `causer-id` = 0")) {
                return Update::FAILED;
        }
+
+       return Update::SUCCESS;
+}
+
+function update_1413()
+{
+       if (!DBA::e("UPDATE `post-user` SET `post-reason` = `post-type` WHERE `post-type` >= 64 and `post-type` <= 75")) {
+               return Update::FAILED;
+       }
 }